471,052 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Wrapping native-C++ DLL in Managed C++: LNK2020 problem

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 library.

I took this import library and had my Managed-C++ class library link
against it. The managed code does the style of wrapping of classes
found in the MSDN section on migrating to managed C++. That is, each
class replicates the interface of the wrapped class and forwards the
calls through to the native-class pointer. This is where I do all my
marshaling and converting of types from their .NET representations to
the native representations.

The code all compiles fine, but when I go to link, I get a series of
LNK2020 errors, which are unresolved tokens in the metadata. I am not
sure how this differs from the usual LNK2001 unresolved external
symbol, but when I remove the DLL import library from the managed-c++
project, I then get LNK2001 errors instead. It seems like it is
linking against the native-C++ DLL's import library, but not finding
everything it needs.

What else do I need to provide to my Managed-C++ library to satisfy
these unresolved tokens in the metadata? The native-C++ DLL does not
have any assembly information or metadata, and I am not really sure
what exactly it is looking for. The errors are things like:

LINK : error LNK2020: unresolved token (0A0000AA)
LINK : error LNK2020: unresolved token (0A0000AB)

These methods are defined in the DLL (and exported in the .def). When
I remove the import library, these errors convert to being LNK2001.

Anyone have any ideas what I might be missing?

Thanks in advance.

Nov 16 '05 #1
2 7388

No help here.

I've been getting the same problem at my end. Here is a
snipet of code what will get a link error:


#pragma once

using namespace System;

#pragma unmanaged
__nogc class B
B() {};
~B() {};
#pragma managed
public __gc class A
B * pB;
A() { pB = new B;}
~A() { pB->~B();}

#include "stdafx.h"

#include "B.h"
This compiles fine, but throws an link error:
B error LNK2020: unresolved token (0A000008) delete

Interestingly, I took a piece of downloaded sample of
some wrapper code from Wrox.com and was able to build
that using the same skeleton. There maybe something set
differently between this downloaded solution and one I
start from scratch.


Nov 16 '05 #2
Here is what we were doing wrong....

All the examples ASSUME that you are making a standalone
program, but we are trying to make a stand alone DLL in
which we are mixing IDL and c code. This is a mixed mode
DLL, and you have to make some changes to the way the
code is linked.

Try looking here:
onConvertingManagedExtensionsForCProjectsFromPureI ntermedi

This seemed to solve my problem!
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Roy Smith | last post: by
2 posts views Thread by dam_fool_2003 | last post: by
1 post views Thread by mg | last post: by
4 posts views Thread by rodchar | last post: by
8 posts views Thread by Gary Nastrasio | last post: by
6 posts views Thread by Markus Ernst | last post: by
3 posts views Thread by gabriel.becedillas | last post: by
7 posts views Thread by christian2.schmidt | 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.