views:

37

answers:

1

Hi All, 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  A: 

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.

Hans Passant
@Hans: Thanks for the info. I am able to call Managed functions implemented in ProjectA from ProjectB - both are Win32 projects as explained above. However, I have now hit another unusual(rather usual) situation (for me) though. I have both static and non-static functions in ProjectA::ClassA. I have a ProjectB::ClassB object using which I want to call these ClassA functions. I am ABLE to call the non-static/instance methods in ProjectA::ClassA using ClassB object.
Daniel
However I am UNABLE to call the static functions either using the class names of either the ClassA:: or ClassB:: (class ClassB : public ClassA is how I am sub-classing). I am new to this interop betwen "Win32+CLR" and "Win32". Any pointers??? Am I blatantly missing something?
Daniel
Probably, static functions are easier. I cannot possibly guess what you are missing, you didn't even include an error message. Update your question.
Hans Passant
Sorry, the error waserror LNK2001: unresolved external symbol "public: static void __cdecl ClassA::StaticFuncA(void)" (?StaticFuncA@ClassA@@SAXXZ) Helper.obj
Daniel