Jump to content
  • Advertisement
Sign in to follow this  
Idov

Wrapping unmanaged C++

This topic is 2831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!
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 which is in a different DLL.


#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 :)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Sneftel
The class needs to be marked dllimport when used from other modules.


I tried it... it didn't help :/

Share this post


Link to post
Share on other sites
When building the DLL you want the DLL's classes, functions and data to be declared dllexport, but when you use the DLL, you want them to be declared dllimport. Traditionally this is handled by using preprocessor code like:

#ifdef DLL_EXPORTS
#define DECLSPEC __declspec(dllexport)
#else
#define DECLSPEC __declspec(dllimport)
#endif

DECLSPEC class MyClass {
// stuff
};

Then in project settings for the DLL #define DLL_EXPORTS and don't define it in whatever project uses it. Though usually you'd want to use a symbol name more specific than DLL_EXPORTS.

Share this post


Link to post
Share on other sites
Quote:
Original post by Idov
yes.

There's your problem, then. The two aren't magical incantations; they have very specific meaning for the linker, and understanding what they do is extremely helpful in getting them to do the right thing. The code SiCrane showed is pretty standard, and it's probably all you need, but reading this will help you understand what it's doing. Remember, if you don't know why something should work, you can't figure out why it isn't working.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!