Linking non-CLR code to a .NET application

I am new to Visual C ++, .NET and the Windows programming world (from Objective-C / Cocoa) and I am trying to use the CFLite (Open CoreFoundation Lite) library which I compiled into a .lib file. It is written in pure unmanaged C and I would like to use it in my CLR.NET managed application. When I try to link it and use the CFSTR function that is a shortcut to __CFStringMakeConstantString, it fails. Any advice? Attached bug.

Proj.obj : error LNK2031: unable to generate p/invoke for "extern "C" struct __CFString const * __clrcall __CFStringMakeConstantString(char const *)" (?__CFStringMakeConstantString@@$$J0YMPBU__CFString@@PBD@Z); calling convention missing in metadata
Proj.obj : warning LNK4248: unresolved typeref token (01000016) for '__CFString'; image may not run
Proj.obj : error LNK2028: unresolved token (0A00000B) "extern "C" struct __CFString const * __clrcall __CFStringMakeConstantString(char const *)" (?__CFStringMakeConstantString@@$$J0YMPBU__CFString@@PBD@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
Proj.obj : error LNK2019: unresolved external symbol "extern "C" struct __CFString const * __clrcall __CFStringMakeConstantString(char const *)" (?__CFStringMakeConstantString@@$$J0YMPBU__CFString@@PBD@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)

      

UPDATE: I ended up with a native app with Win32 calls since my UI will be minimal (it's a background app). I played around with p / invoke a bit and found it difficult for a beginner like me: p Thanks!

0


a source to share


3 answers


It looks like you have a mismatch in the signature of the function you are using in your managed C ++ application versus what is in your C library.



.Net technology uses PInvoke for communication between the managed world, and the unmanaged world. The best resource for examples of using PInvoke is pinvoke.net . Your C function signatures look very simple, so it should be straight forward to create an appropriate C ++ parameter set correctly.

+1


a source


http://www.codeproject.com/KB/mcpp/timeserver.aspx



+1


a source


I know that working with managed code from unmanaged is DLL assembly or COM working.

0


a source







All Articles