473,566 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LNK2020 using managed/unmanaged classes combination and workaround question

Greetings!

I found myself with a LNK2020 linking problem using VS.NET 2003 under a
situation that I was able to replicate in a small project.

I found one workaround for the problem too, but it's ugly and sure things
shouldn't be like that. I'd like to know if that's a conceptual mistake by
me, a compiler error, both, or none of them! ;-)

To replicate the problem:

- Create a new solution with 2 projects:
- The first project will be a DLL (New Project, Win32 Application,
Application Settings, mark 'DLL' and 'Export Symbols'). Name it anything,
say, TestDLL
- For the other project, create a "Windows Forms application"

In the DLL:
- Add to project, besides the default .cpp generated by VS, another one, say
ManagedClassX.c pp
- Define your class like this:

//ManagedClassX.h :
//--------------------------------
public __gc class ManagedClassX
{
public:
void SomeMethod();
};
//--------------------------End of h

//ManagedClassX.c pp:
//--------------------------------
#using <mscorlib.dll >

#include "ManagedClassX. h"

void ManagedClassX:: SomeMethod()
{
};
//----------------------------End of cpp

As we can see, this is a managed class added to the DLL.

To the Windows Forms project,

- Add a button to the main form. Add to this button the code:

ManagedClassX* test = new ManagedClassX() ;
test->SomeMethod() ;

and make sure that the Form1.h contains

#include "ManagedClassX. h"

All set up, make sure you compile everything with /clr. Yes, I understand
this will create managed code for everything.

At my test machine here, the DLL compiles just fine. But the WinForms
application
that is going to use it no - it gives me an LNK2020 error:

------ Build started: Project: WinForms, Configuration: Release Win32 ------

Compiling...
Form1.cpp
Linking...
LINK : error LNK2020: unresolved token (06000002) ManagedClassX:: SomeMethod
LINK : fatal error LNK1120: 1 unresolved externals

How can that be? The class was compiled, the .lib file from the DLL is
already added in my "Additional Dependencies" property for the project...

Everything shoud work fine! Methods exported from the Win32 dll work fine on
my Windows Forms Application. Sure, they are being exported by the
"__declspec(dll export)" directive, but the managed class is declared
"Public", so the class and its methods should be visible... Shouldn't them?

The Workaround is to add the "ManagedClass.c pp" file inside my "Windows
Forms"
project, and having the project compile again. Then I don't get the
unresolved external and things work. But this has some drawbacks, like
having to compile files twice... Surely it's not the desired solution!

Any clues?

Thank you for any help,

Gustavo Fabro

gu************* **********@hotm ail.com
Nov 17 '05 #1
0 1372

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4297
by: mccoyn | last post by:
I'm porting an old project to use .NET. When I try to link in a static library (.lib) that has a single managed class in it. I get the following errors: LINK : error LNK2020: unresolved token (0600000E) PatInfo::.ctor LINK : error LNK2020: unresolved token (0600000F) PatInfo::Finalize LINK : fatal error LNK1120: 2 unresolved externals I've...
47
3495
by: Bonj | last post by:
I downloaded the gzlib library from zlib in order to do compression. (http://www.gzip.org/zlib) The prototype of the compression function seems to be int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); It is meant to be called by C, but I would rather use it from C#. So I wrote the following C# program to...
2
7566
by: Jacob Cohen | last post by:
Under VC7.1, I am trying to wrap a native-C++ DLL that contains C++ objects in a Managed-C++ class library for use in a C# project. I created and compiled the native DLL under VC7.1 as a Win32 DLL C++ (unmanaged) project. I found the decorated names of the symbols I wanted to export and created a .def file, so that it generated an import...
1
2107
by: Eric Twietmeyer | last post by:
Hello, I'm starting to investigate cs, managed c++ and interoperating with a very large unmanaged code base. We are going to use Windows Forms (written in cs) to replace our old fashioned GUI. The guts will remain in unmanaged c++. So I need to write public managed c++ wrapper classes for the couple of interfaces the unmanaged stuff...
2
5987
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 managed one. I have taken a look at following sample code on how to do this. http://longhorn.msdn.microsoft.com/lhsdk/ndp/vcmg_appendixs...
0
1115
by: Stefan | last post by:
Hi, Could anyone share some light on this and how I can work around it. If I have 2 managed c++ dlls (A and B) and B tries to use a native class in A this fails to link. It is easily reproducable by taking the example from: 'http://msdn2.microsoft.com/library/c3d162w5.aspx' And then move the definition(?) of N::N to the cpp file. It will...
9
2408
by: WithPit | last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library which contains C++ code. Some of the unmanaged methods returns an returntype which is of the abstract base type (for example unmanagedObject). How can i convert this to the managed abstract basetype? Hope somebody can help me Thanx
3
1793
by: WithPit | last post by:
I am trying to create an managed wrapper but have some problems with it by using abstract classes. In my unmanaged library code i had the following three classes with the following hierarchy Referenced (class) Object (abstract class, inheriting from referenced) Node (class, inheriting from object)
0
2921
by: Roland | last post by:
Hi, ultimately I want to call some unmanaged C++ class that contains some DirectShow code of mine from my C# classes, but for the time being I'd be happy if I could get this to build! I have read the other topics on the same problem here on the groups but haven't found the solution to my problem yet. I have written a managed C++ wrapper...
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7953
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.