c++
typedef struct
{
HANDLE aaa;
HWND bbb;
BYTE ccc[2500];
} SStruct, LPSCStruct;
BOOL __stdcall func1(LPSCStruct zzz);
c#
public struct LPSCStruct
{
public int aaa;
public IntPtr bbb;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2500)]
public byte[] ccc;
}
public partial class Form1 : Form /*, IMessageFilter*/
{
[DllImport("test.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.I1)]
unsafe extern public static bool func1(IntPtr zzz);
public LPSCStruct sss;
public LPSCStruct rrr;
public IntPtr m_lpstruct;
private void Form1_Load(object sender, EventArgs e)
{
sss = new LPSCStruct();
}
private IntPtr MarshalToPointer(object data)
{
IntPtr buf = Marshal.AllocHGlobal(Marshal.SizeOf(pse));
Marshal.StructureToPtr(data, buf, false);
return buf;
}
private object MarshalToStruct(IntPtr buf, Type t)
{
return Marshal.PtrToStructure(buf, t);
}
private void button1_Click(object sender, EventArgs e)
{
sss.bbb = FindWindow(null, "Form1");
m_lpstruct = MarshalToPointer(sss);
bool bRtn = func1(m_lpstruct);
if (bRtn)
{
rrr = (LPSCStruct)MarshalToStruct(m_lpstruct, typeof(LPSCStruct));
textBox1.AppendText(Encoding.Default.GetString(rrr.ccc));
}
}
댓글 없음:
댓글 쓰기