472,805 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 7502

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

Similar topics

by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
by: nimdez | last post by:
Hi, I am working on an existing code base in which a lot of data displayed to the user is formatted in tables. Most tables are printed row-by-row using printf() with "%s" print conversion...
by: dam_fool_2003 | last post by:
My understanding about wrapping is that we add utilities to a lib function for our specific use. So days ago in the c.l.c I saw a function def as: void * xmalloc (size_t size) { register void...
by: mg | last post by:
I set the width of a WebForm Label but do not get line wrapping (see below). What can I do to get line wrapping WebForm1.asp <asp:Labe id="Label1" style="Z-INDEX: 101; LEFT: 40px; POSITION:...
by: rodchar | last post by:
Hey all, I have a datagrid that auto-generate the columns. When I run the app some of the column values are wrapping. How do I prevent the values from wrapping? Do I have to use template...
by: Gary Nastrasio | last post by:
If I compile with /clr:safe, which is exactly meant by saying I can't use "Native Types" in my code? Is a native type something such as float, short, or int? Thanks, Gary
by: Siv | last post by:
Hi, I am trying to find a wrapping routine for text and not having much luck. The reason I need one is that I am producing a report where the text that was stored in the database was written into...
by: Markus Ernst | last post by:
Hi Searching for a possibility to display some text with preserved white space and line breaks, but with long lines being wrapped, I found this CSS declaration, which I found helpful: pre {...
by: gabriel.becedillas | last post by:
Hi, I'm having problems wrapping a hierarchy of classes, actually having problems wrapping the base class. I don't need to use the WrapClass mechanism since I don't want to override classes in...
by: christian2.schmidt | last post by:
Hi, I'm trying to wrap an IList-instance in a native template class with a "vector"-like interface. cliext::vector seems not suited, as it copies the list - correct me if I'm wrong. template...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.