Calling a function from a Win32 .lib project with /clr from a project that is a pure Win32 project, no clr

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 05:24:45

问题


I want to know how do I exactly call a function from ProjectA::ClassA::FuncA() that is a Win32 .lib with /clr from a ProjectB::ClassB::FuncB() that does not have clr support and is a pure Win32 project. Both these projects are under same solution.

First, this is what I have tried: 1. Created the ProjectA with the .lib 2. Added the .lib path to ProjectB properties (in Linker:Input:Add.Dependencies) 3. I added the .h for the .lib created by ProjectA in ProjectB 4. Created the object for ProjectA::ClassA in ProjectB::ClassB and tried to call the FuncA().

I get the following error:

Error 1 error LNK2019: unresolved external symbol "public: static void __cdecl ClassA::FuncA(void)" (?FuncA@ClassA@@SAXXZ) referenced in function "public: static void __cdecl ClassB::FuncB(void)" (?FuncB@ClassB@@SAXXZ) Helper.obj

I am using third-party .lib s in ProjectB successfully. I follow the same process but it fails; the only difference being ProjectA() is with CLR support.

Am I missing something? Please enlighten me ;-)

Thanks!


回答1:


Native code can call managed code but that needs to be done in a source code file that's compiled with /clr. You need a little adapter class that's native (no "ref") in ProjectB. If these are instance methods then you'll need gcroot<> in the adapter to store a reference to the managed class.



来源:https://stackoverflow.com/questions/3994073/calling-a-function-from-a-win32-lib-project-with-clr-from-a-project-that-is-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!