包装 C++带有托管类的 DLL

发布于 2024-09-28 15:24:15 字数 1184 浏览 7 评论 0原文

我试图用托管 C++ 包装非托管 C++ DLL,但不断收到链接错误。

即使我在项目中包含我的library.lib 并包含正确的头文件。

这是托管类:

#pragma once
#include "..\Terminal\Terminal.h"
public ref class ManagedTerminal
{
    private:
Terminal * m_unTerminal;
public:

ManagedTerminal(void)
{
    m_unTerminal = new Terminal();
}
};

这是非托管类:

#include "..\Core1.h"
#include "..\Core2.h"

 __declspec(dllexport) class Terminal
{
private:
CoreObj m_core;

public:
Terminal();
void Init(char* path, char* filename);    
void Start();
void Stop();
void Run();
Array<Report> GetSnapshot();
~Terminal(void);
};

我得到的错误是:

Error 5 error LNK2028: unresolved token (0A0000B3) "public: __thiscall Terminal::Terminal(void)" (??0Terminal@@$$ FQAE@XZ) 在函数“public: __clrcall ManagedTerminal::ManagedTerminal(void)”中引用 (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal.obj TerminalWrapper

错误 6 错误 LNK2019:无法解析的外部符号“public: __thiscall Terminal ::Terminal(void)" (??0Terminal@@$$FQAE@XZ) 在函数 "public: __clrcall ManagedTerminal::ManagedTerminal(void)" (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal 中引用。 obj TerminalWrapper

有人能告诉我出了什么问题吗? 谢谢 :)

I'm trying to wrap a unmanaged C++ DLL with managed C++ and I keep getting linking errors.

even though I include my library.lib in the project and include the correct header file.

This is the managed class:

#pragma once
#include "..\Terminal\Terminal.h"
public ref class ManagedTerminal
{
    private:
Terminal * m_unTerminal;
public:

ManagedTerminal(void)
{
    m_unTerminal = new Terminal();
}
};

and this is the unmanaged class:

#include "..\Core1.h"
#include "..\Core2.h"

 __declspec(dllexport) class Terminal
{
private:
CoreObj m_core;

public:
Terminal();
void Init(char* path, char* filename);    
void Start();
void Stop();
void Run();
Array<Report> GetSnapshot();
~Terminal(void);
};

and the errors I get are:

Error 5 error LNK2028: unresolved token (0A0000B3) "public: __thiscall Terminal::Terminal(void)" (??0Terminal@@$$FQAE@XZ) referenced in function "public: __clrcall ManagedTerminal::ManagedTerminal(void)" (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal.obj TerminalWrapper

Error 6 error LNK2019: unresolved external symbol "public: __thiscall Terminal::Terminal(void)" (??0Terminal@@$$FQAE@XZ) referenced in function "public: __clrcall ManagedTerminal::ManagedTerminal(void)" (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal.obj TerminalWrapper

can anybody tell me what's wrong?
thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情换悲伤 2024-10-05 15:24:15

您必须匹配所有构建设置——特别是调用约定(CDECL 与 STDCALL)——才能获得成功的链接。

从 .NET 2.0 开始,您还必须动态链接到 c 运行时,因此请确保 .dll 和托管 C++ 项目都执行此操作。

基本上,进入两个项目的属性对话框并确保影响调用的内容相同。

You have to match all of the build settings -- specifically the calling conventions (CDECL vs. STDCALL) -- in order to have a successful link.

Since .NET 2.0, you have also had to link to the c-runtime dynamically, so make sure that both the .dll and the managed C++ project do this.

Basically, go into the properties dialog for both projects and make sure that things that affect the call are the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文