How to call C++ DLL in C#

前端 未结 3 504
暗喜
暗喜 2020-11-30 04:53

I have written a DLL in dev C++. The DLL\'s name is \"DllMain.dll\" and it contains two functions: HelloWorld and ShowMe. The header file looks lik

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 05:24

    The following code in VS 2012 worked fine:

    #include 
    extern "C"
    {
        __declspec(dllexport) void HelloWorld ()
        {
            MessageBox (0, L"Hello World from DLL!\n", L"Hi",MB_ICONINFORMATION);
        }
        __declspec(dllexport) void ShowMe()
        {
            MessageBox (0, L"How are u?", L"Hi", MB_ICONINFORMATION);
        }
    }
    

    NOTE: If I remove the extern "C" I get exception.

提交回复
热议问题