C++ API가 :바이트 배열이 인식되지
typedef struct
{
BYTE bCommandCode;
BYTE bParameterCode;
struct
{
DWORD dwSize;
LPBYTE lpbBody;
}
Data;
}
COMMAND;
그리고 함수 :
DLL_API DWORD WINAPI ExecuteCommand(LPCSTR, CONST COMMAND, CONST DWORD, LPREPLY);
그리고 내 C# 동등한 코드 :
public struct Data
{
public int dwSize;
public byte[] lpbBody;
}
public struct Command
{
public byte bCommandCode;
public byte bParameterCode;
public Data Data;
}
[DllImport(@"api.dll", CallingConvention = CallingConvention.Winapi)]
public static extern int ExecuteCommand(string port, Command command, int timeout, ref Reply reply);
답글 구조체는 여기에 필요하지 않습니다.
내가 전화 ExecuteCommand를 : 나는 바이트 [] BDATA가 올바르게 전혀 인식하지 못하는 것을 볼Command command = new Command();
command.bCommandCode = 0x10;
command.bParameterCode = 0x10;
byte[] bData = { 0xff, 0xff };
command.Data.dwSize = bData.Length;
command.Data.lpbBody = bData;
Reply reply = new Reply();
var result = ExecuteCommand("COM1", command, 5000, ref reply);
나는 C에서 로그를 볼 ++ DLL. 내가 뭘 잘못하고 있니? 어쩌면이 정의가 올바르지 않을 수 있습니다 : public byte [] lpbBody? 구조체의 LPBYTE 배열을 C++ 메서드에 전달할 수 있습니까?
아니요, MarshalAsAttribute를 사용하지 않습니다. 어디에서 사용해야합니까? – Anton23
클래스/구조체 및 필드 꼭대기. 인터넷 메이트에있는 많은 자습서. 마샬링에 대해 읽고 .NET에서 작동하는 방법을 제안합니다. –
GCHandle.Alloc 작품! 고마워요! @ 페리 – Anton23