Visual studio community 2019で作成しました。(超初心者です)
以下のソースがエラー発生した箇所です。(← ここの”)”に~が出て”CS1001 識別子がありません”)
エラー回避方法お願いします。
-----C#側のDLLソースコード(Program.cs)------
using System.Runtime.InteropServices;
namespace CallDll1
{
class Program
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
private struct STPart
{
[MarshalAs(UnmanagedType.I1)]
public bool boA;
public int iB;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] c1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] c2;
public double d1;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)] private struct STMain { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] public STPart[] stPart; } [DllImport("DLL.dll", EntryPoint = "foo", SetLastError = false)] private static extern int foo(ref STMain); ← ← ここの”)”に~が出て”CS1001 識別子がありません” static void Main(string[] args) { STMain stM = new STMain(); int i; for (i = 0; i < 10; i++) { stM.stPart[i] = new STPart(); stM.stPart[i].boA = false; stM.stPart[i].iB = 10; stM.stPart[i].d1 = 9.9; foo(ref stM); } } }
}
---C++側のソース(Dll1.cpp)---
#include "Dll1.h";
void foo(STMain* sCPP)
{
sCPP->sPart[0].c1[0] = 5;
}
---C++側のヘッダ(Dll1.h)---
typedef struct {
bool boA;
int iB;
char c1[256];
char c2[256];
double d1;
} STPart;
typedef struct {
STPart sPart[10];
} STMain;