構造体へのポインタをDLLに渡す必要があります。どのようにすればよいでしょうか?私のC#のコードでC#プログラムからC DLLを呼び出す
typedef struct
{
int length;
unsigned char *value;
} Sample;
__declspec(dllexport) void __stdcall helloWorld(Sample *sample);
:私のCのDLLで
は
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CSharpConsole
{
class Program
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private struct Sample
{
public Int32 length;
// What Should I Declare Here?
}
[DllImport("C:\\CTestDLL.dll")]
private static extern void helloWorld(Sample sample); // How would I make this a pointer?
void HelloWorld()
{
Sample sample = new Sample();
sample .length = 20;
// How can I fill up the values of value?
helloWorld(sample); // How should I pass it inside here
return;
}
static void Main(string[] args)
{
Program program = new Program();
program.HelloWorld();
}
}
}
IntPtr(プラットフォームセーフポインタ)を使用し、場合によってはデータのマーシャリングを使用します。安全でないコードブロックが必要な場合があります。 – user978122