私は 1 つのネイティブ c++ dll、CppApp を持っています。別のプロジェクトは /clr で管理されている c++、GatWayLibrary です。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_);
}`