GetProcAddress cannot find my functions

前端 未结 2 1071
慢半拍i
慢半拍i 2020-12-19 14:02

I made a DLL with a function named \"render()\" and I want to load it dynamically to my application, but GetProcAddress cannot find it. Here\'s the DLL .h:

#         


        
2条回答
  •  情深已故
    2020-12-19 14:31

    The function you export is treated as a C++ function (because of *.cpp file extension) and so C++ name mangling is used to decorate the exported function name. If you use the Dependency Walker tool from Microsoft to inspect your created DLL you will see the functions full name.

    You can either use that decorated name in your import code or force the compiler to export your function in C style, that is, in its undecorated form that your current import code expects.

    You can tell the compiler to do so by adding extern "C" to your functions signature. Something like this:

    extern "C" D3D_API_API void render();
    

    Now your import code should work as expexted.

提交回复
热议问题