托管c调用非托管c dll,未解析的令牌

时间:2013-08-22 19:19:58

标签: c++ visual-studio-2012 unmanaged managed

我有1个本机c ++ dll,CppApp,另一个项目是托管c ++,GatWayLibrary,带/ clr 在GatewayLibrary中,我从本机CppApp dll调用了函数。 但我得到了解析令牌错误。 这是我的代码剪辑:

CppApp.h
=========
#ifdef CPPAPP_EXPORTS
#define CPPAPP_API __declspec(dllexport)
#else
#define CPPAPP_API __declspec(dllimport)
#endif

class CPPAPP_API CppApp 
{
public:
    CppApp();
     ~CppApp();

     ContextManager & contextMgr() { return m_rplContextMng; }
     INativeListener* m_listener;

     void registerListener(INativeListener* listener)
     {
          m_listener = listener;
     }
...........
 }

在单独的项目GateWaylibrary中,将本机dll包装为

#include "../CppApp/CppApp.h"
#include <vcclr.h>

using namespace System;
using namespace System::Runtime::InteropServices;


#pragma comment(lib, "CppApp.lib")

namespace GatewayLibrary{

    //.net equvelant of the argument class
public ref class DotNetEventArg{
internal:

//contructor takes native version of argument to transform
DotNetEventArg(const NativeCPPArgs& args) {
....
...
}

托管c ++将链接错误作为来自本机c ++的所有函数调用的未解析标记。

我确实将CppApp.lib包含为附加依赖项 和目录。 有人可以帮忙吗?非常感谢。

编辑: 这里是我称之为原生c ++的地方     `GatewayLibrary :: EventGateway :: EventGateway()     {         nativeCode_ = new CppApp();

    //note; using 'this' in ctor is not a good practice
    nativeListener_ = new NativeListenerImp(this);

    //register native listener
    nativeCode_->registerListener(nativeListener_);
}`

0 个答案:

没有答案