C++ DLL Export to C#, example with messagebox

10
24



You have to use “extern “C” __declspec(dllexport)” before void to make it for export.
C++ code:

int WINAPI MessageBox(
_In_opt_ HWND hWnd,
_In_opt_ LPCTSTR lpText,
_In_opt_ LPCTSTR lpCaption,
_In_ UINT uType
);

extern “C” __declspec(dllexport) void MsgBox()
{
MessageBox(NULL,TEXT(“LOL”), TEXT(“LEL”),0x00000000L);
}

С# Code:

[DllImport(“MessageBoxShow.dll”, CharSet = CharSet.Unicode)]
public static extern void MessageBoxShow();
private void button1_Click(object sender, EventArgs e)
{
MessageBoxShow();
}

Nguồn:https://wijstaanvooronzegrondrechten.org/

10 COMMENTS

  1. В моем случаи пришлось делать так:
    [DllImport("DllName", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]

LEAVE A REPLY

Please enter your comment!
Please enter your name here