Using C++ app in .NET

后端 未结 2 954
走了就别回头了
走了就别回头了 2021-01-24 08:40

I am new to using PInvoke with Classic C++ and I asked this question yesterday: Using Windows API functions in .NET

I have now created a very simple C++ program as follo

2条回答
  •  醉梦人生
    2021-01-24 09:14

    Declare is VB6 legacy. You should use p/invoke and the DllImport attribute.

     _
    Public Shared Function hello() As Integer
    End Function
    

    There are lots of ways that this could fail. Perhaps the DLL is not loading because there's a 32/64 bit mismatch. Also, your calling conventions do not match. Your DLL will be using cdecl but your VB code uses stdcall. The pinvoke above fixes that.

    Most seriously your function does not appear to have been exported from the DLL. That's going to make it fail for sure. Use Dependency Walker to determined whether or not your function has been exported. I'm not so familiar with g++ so you'll have to work out how to export your function using the GNU toolchain. But watch out for name decoration and name mangling. You may need to take care with how you export your function so that it is exported with the desired name.

提交回复
热议问题