471,078 Members | 843 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,078 software developers and data experts.

Linking problems with managed/unmanaged classes

I'm having problems calling an unmanaged class from a managed wrapper.
I suspect I'm missing something obvious, as I'm unfamiliar with C++ and
classes are very simple. My unmanaged class is as follows:

// Unmanaged.h
#pragma once
namespace Unmanaged {
class __declspec(dllexport) UnmanagedClass
{
// TODO: Add your methods for this class here.
public:
double DoUnmanagedStuff();
};
}

// Unmanaged.cpp
#include "stdafx.h"
#include "Unmanaged.h"
class UnmanagedClass
{
public:
double DoUnmanagedStuff() {
return 1.234;
}
};
This class is called from a managed wrapper as follows:

//Managed.cpp
#include "stdafx.h"
#include "Managed.h"
#include "..\Unmanaged\Unmanaged.h"

using namespace Unmanaged;

public ref class ManagedClass {
private:
UnmanagedClass* UClass;

public:
ManagedClass() {
UClass = new UnmanagedClass();
}
~ManagedClass() {
delete UClass;
}
double DoStuff() {
return UClass->DoUnmanagedStuff();
}
};

I get the following error when I try to compile the code:

error LNK2028: unresolved token (0A00000C) "public: double __thiscall
Unmanaged::UnmanagedClass::DoUnmanagedStuff(void)"
(?DoUnmanagedStuff@UnmanagedClass@Unmanaged@@$$FQA ENXZ) referenced in
function "public: double __clrcall ManagedClass::DoStuff(void)"
(?DoStuff@ManagedClass@@$$FQ$AAMNXZ)

Any ideas what is going on?
Thanks.

Nov 6 '06 #1
5 1758

"akash" <ak***********@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
I'm having problems calling an unmanaged class from a managed wrapper.
I suspect I'm missing something obvious, as I'm unfamiliar with C++ and
classes are very simple. My unmanaged class is as follows:

// Unmanaged.h
#pragma once
namespace Unmanaged {
class __declspec(dllexport) UnmanagedClass
{
// TODO: Add your methods for this class here.
public:
double DoUnmanagedStuff();
};
}
Defines "::Unmanaged::UnmanagedClass", including a forward declaration of
"double ::Unmanaged::UnmanagedClass::DoUnmanagedStuff(void )"
>
// Unmanaged.cpp
#include "stdafx.h"
#include "Unmanaged.h"
class UnmanagedClass
{
public:
double DoUnmanagedStuff() {
return 1.234;
}
};
Defines "::UnmanagedClass" with a definition of "double
::UnmanagedClass::DoUnmanagedStuff(void)". This class is different from
"::Unmanaged::UnmanagedClass".

Try:
// Unmanaged.cpp
#include "stdafx.h"
#include "Unmanaged.h"

double Unmanaged::UnmanagedClass::DoUnmanagedStuff(void)
{
return 1.234;
}

Nov 6 '06 #2
Thanks for the suggestion. Unfortunately I now get two errors:

error LNK2028: unresolved token (0A00000C) "public: double __thiscall
Unmanaged::UnmanagedClass::DoUnmanagedStuff(void)"
(?DoUnmanagedStuff@UnmanagedClass@Unmanaged@@$$FQA ENXZ) referenced in
function "public: double __clrcall ManagedClass::DoStuff(void)"
(?DoStuff@ManagedClass@@$$FQ$AAMNXZ)

error LNK2019: unresolved external symbol "public: double __thiscall
Unmanaged::UnmanagedClass::DoUnmanagedStuff(void)"
(?DoUnmanagedStuff@UnmanagedClass@Unmanaged@@$$FQA ENXZ) referenced in
function "public: double __clrcall ManagedClass::DoStuff(void)"
(?DoStuff@ManagedClass@@$$FQ$AAMNXZ)

I must still be doing something stupid, but I can't figure out what!

Ben Voigt wrote:
"akash" <ak***********@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
I'm having problems calling an unmanaged class from a managed wrapper.
I suspect I'm missing something obvious, as I'm unfamiliar with C++ and
classes are very simple. My unmanaged class is as follows:

// Unmanaged.h
#pragma once
namespace Unmanaged {
class __declspec(dllexport) UnmanagedClass
{
// TODO: Add your methods for this class here.
public:
double DoUnmanagedStuff();
};
}

Defines "::Unmanaged::UnmanagedClass", including a forward declaration of
"double ::Unmanaged::UnmanagedClass::DoUnmanagedStuff(void )"

// Unmanaged.cpp
#include "stdafx.h"
#include "Unmanaged.h"
class UnmanagedClass
{
public:
double DoUnmanagedStuff() {
return 1.234;
}
};

Defines "::UnmanagedClass" with a definition of "double
::UnmanagedClass::DoUnmanagedStuff(void)". This class is different from
"::Unmanaged::UnmanagedClass".

Try:
// Unmanaged.cpp
#include "stdafx.h"
#include "Unmanaged.h"

double Unmanaged::UnmanagedClass::DoUnmanagedStuff(void)
{
return 1.234;
}
Nov 6 '06 #3
I note you have declspec(dllexport). Are you actually importing a DLL here,
or are Unmanaged.cpp and Managed.cpp in the same project?
"akash" <ak***********@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Thanks for the suggestion. Unfortunately I now get two errors:

error LNK2028: unresolved token (0A00000C) "public: double __thiscall
Unmanaged::UnmanagedClass::DoUnmanagedStuff(void)"
(?DoUnmanagedStuff@UnmanagedClass@Unmanaged@@$$FQA ENXZ) referenced in
function "public: double __clrcall ManagedClass::DoStuff(void)"
(?DoStuff@ManagedClass@@$$FQ$AAMNXZ)

error LNK2019: unresolved external symbol "public: double __thiscall
Unmanaged::UnmanagedClass::DoUnmanagedStuff(void)"
(?DoUnmanagedStuff@UnmanagedClass@Unmanaged@@$$FQA ENXZ) referenced in
function "public: double __clrcall ManagedClass::DoStuff(void)"
(?DoStuff@ManagedClass@@$$FQ$AAMNXZ)

I must still be doing something stupid, but I can't figure out what!

Ben Voigt wrote:
>"akash" <ak***********@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegr oups.com...
I'm having problems calling an unmanaged class from a managed wrapper.
I suspect I'm missing something obvious, as I'm unfamiliar with C++ and
classes are very simple. My unmanaged class is as follows:

// Unmanaged.h
#pragma once
namespace Unmanaged {
class __declspec(dllexport) UnmanagedClass
{
// TODO: Add your methods for this class here.
public:
double DoUnmanagedStuff();
};
}

Defines "::Unmanaged::UnmanagedClass", including a forward declaration of
"double ::Unmanaged::UnmanagedClass::DoUnmanagedStuff(void )"
>
// Unmanaged.cpp
#include "stdafx.h"
#include "Unmanaged.h"
class UnmanagedClass
{
public:
double DoUnmanagedStuff() {
return 1.234;
}
};

Defines "::UnmanagedClass" with a definition of "double
::UnmanagedClass::DoUnmanagedStuff(void)". This class is different from
"::Unmanaged::UnmanagedClass".

Try:
// Unmanaged.cpp
#include "stdafx.h"
#include "Unmanaged.h"

double Unmanaged::UnmanagedClass::DoUnmanagedStuff(void)
{
return 1.234;
}

Nov 6 '06 #4
I am using a DLL. When I put the two classes in the same project, it
all works. Clearly I'm still doing something stupid regarding DLL use,
but I'm not sure what.

For the moment I'll live with having everything in the same
project...unless you have any suggestions?

Ben Voigt wrote:
I note you have declspec(dllexport). Are you actually importing a DLL here,
or are Unmanaged.cpp and Managed.cpp in the same project?
Nov 7 '06 #5

"akash" <ak***********@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
>I am using a DLL. When I put the two classes in the same project, it
all works. Clearly I'm still doing something stupid regarding DLL use,
but I'm not sure what.
Oh!

You need to use dllexport inside the DLL and dllimport outside. A #define
is good for this...
>
For the moment I'll live with having everything in the same
project...unless you have any suggestions?

Ben Voigt wrote:
>I note you have declspec(dllexport). Are you actually importing a DLL
here,
or are Unmanaged.cpp and Managed.cpp in the same project?

Nov 7 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by DotNetJunkies User | last post: by
2 posts views Thread by Joerg M. Colberg | last post: by
2 posts views Thread by Sandy | last post: by
7 posts views Thread by Lee Crabtree | last post: by
9 posts views Thread by Amit Dedhia | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.