代码之家  ›  专栏  ›  技术社区  ›  AriX

将非CLR代码链接到.NET应用程序

  •  0
  • AriX  · 技术社区  · 16 年前

    我是VisualC++、.NET和Windows编程世界的新手(来自Objut-C/COCOA),我尝试使用CFLite(OpenCopeoundation Lite)库,我将其编译为.LIB文件。它是用纯的、非托管的C编写的,我想在我的托管clr.net应用程序中使用它。当我试图链接它并使用函数cfstr时,它会失败得很惨,cfstr是cfStringMakeConstantstring的快捷方式。有什么建议吗?附加的是错误。

    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)
    

    更新:由于我的用户界面将是最小的(它是一个后台应用程序),我最后只使用了一个本地应用程序和win32调用。我玩了一下P/Invoke,对像我这样的新手来说,这似乎很复杂:P 谢谢!

    3 回复  |  直到 16 年前
        1
  •  1
  •   sipsorcery    16 年前

    看起来你在托管C++应用程序中使用的函数签名与C库中的函数签名不匹配。

    NET用来在托管世界和非托管世界之间进行通信的技术是PInvoke。如何使用pinvoke示例的最佳资源是 pinvoke.net . 你的C函数签名看起来非常简单,所以它应该是直的,在C++中创建匹配的参数,并正确地排列参数。

        3
  •  0
  •   Drahakar    16 年前

    我知道从非托管代码处理托管代码的方法是构建一个DLL或使用COM。