473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1886

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
2
by: Paul Kenny | last post by:
Hi, I am trying to expose the functionality of an unmanaged C++ class to the other languages available in the .NET Framework. I have decided to do this by wrapping the unmanaged C++ class in a...
0
by: DotNetJunkies User | last post by:
Hi! I got some huge problems trying to use a C/C++ package (originally from a gcc environment) into a library in VS.NET 2003 and finally linked and used by a C# windows service. Basicly nothing...
13
by: bonk | last post by:
Hello, I am trying to create a dll that internally uses managed types but exposes a plain unmanaged interface. All the managed stuff shall be "wrapped out of sight". So that I would be able to...
2
by: Joerg M. Colberg | last post by:
I have a VS.Net solution that contains various projects. Some of the projects contain programme blocks (legacy code) that are used by some of the other projects. One project contains some C code...
2
by: Sandy | last post by:
I am confused about Unmanaged Code, How .Net Framework treate that code, What is the use of that. Thanks in advance Sandeep Chitode
7
by: Lee Crabtree | last post by:
I'm starting work on what will eventually be a very, very LARGE project. A lot of the project involves taking C/C++ class libraries and wrapping them with managed C++. I'd like to minimize the...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
3
by: Pixel.to.life | last post by:
Hi, Gurus, I recently attempted to build a .Net forms application, that links with old style unmanaged C++ static libs. Of course I had to recompile the static lib projects to link properly...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.