473,396 Members | 2,033 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,396 software developers and data experts.

how to link unmanaged c++ into .net class library to test with nunit?

hi, i am teaching a class using visual studio 2003 in the labs at
school and trying to get some pure c++ into a dll so i can sic nunit on
it.
trying to put the code below into a .net class library gets unresolved
externs:
pure error LNK2020: unresolved token (0A000006) _CxxThrowException
pure error LNK2020: unresolved token (0A000015) delete
pure fatal error LNK1120: 2 unresolved externals
i have been away from the m$ world for many years and have no clue
how to resolve this. this has to do with linking in some static
flavour of the crt lib (i think). there are some clues at
http://support.microsoft.com/?kbid=814472, but it looks like a
research project.
what i would like to do is to package the pure c++ code into a pure
c++ dll ideally, but *any* kind of assembly would be fine. and then
put the managed tests that nunit will find into another assembly. not
sure how to expose the public api from c to the managed code.
is anyone at all familiar with this?
any pointers will be appreciated.
thanks

#pragma once
#include <iostream>
#include <string>
#include <map>
namespace pure {
class Foo { std::map<std::string *,Foo *> m; };
}

Mar 27 '06 #1
4 2371
"Ray Tayek" <rt*******@spam.comcast.net> wrote in message
news:MP************************@msnews.microsoft.c om...
trying to put the code below into a .net class library gets unresolved
externs:
pure error LNK2020: unresolved token (0A000006) _CxxThrowException
pure error LNK2020: unresolved token (0A000015) delete
pure fatal error LNK1120: 2 unresolved externals
Often, these errors come from trying to mix native and managed code in the
same assembly and breaking the (albeit obscure) rules for doing so.

The rules are spelled out here:

http://support.microsoft.com/?id=814472
there are some clues at
http://support.microsoft.com/?kbid=814472, but it looks like a
research project.
Ah, you found the link. It's not a research project. It is pretty detailed,
no?

In a mixed-mode DLL of mine, I have this module:

#include <windows.h>
#include <_vcclrit.h>

/************************************************** *******************
************************************************** *******************/
void WINAPI Init(void)
{
__crt_dll_initialize();
}

/************************************************** *******************
************************************************** *******************/
void WINAPI Term(void)
{
__crt_dll_terminate();
}

I link the project with the /NOENTRY switch to avoid the "loader-lock"
issue, link against msvcrt.lib and ignore references from MSVCRTD or LIBCMT
(in debug and release builds respectively) and make sure that Init() is
called before the first use of any other export in the DLL and that Term()
is called before the DLL is unloaded (or the executable is terminated)
what i would like to do is to package the pure c++ code into a pure
c++ dll ideally, but *any* kind of assembly would be fine. and then
put the managed tests that nunit will find into another assembly. not
sure how to expose the public api from c to the managed code.


I think there is a disconnect here because the word DLL is in a way
overloaded. DLLs that contain assemblies are different enough from those
that export a flat API that special handling is required. (Just BTW and
IIRC, VS2005 does a better job of hiding the differences)

Regards,
Will
Mar 28 '06 #2
In article <uy**************@TK2MSFTNGP12.phx.gbl>,
wi***********@mvps.org says...
"Ray Tayek" <rt*******@spam.comcast.net> wrote in message
news:MP************************@msnews.microsoft.c om...
trying to put the code below into a .net class library gets unresolved
externs: ... pure error LNK2020: unresolved token (0A000006) _CxxThrowException ...
Often, these errors come from trying to mix native and managed code in the
same assembly and breaking the (albeit obscure) rules for doing so.


the code is all pure.

The rules are spelled out here: ...
there are some clues at ...
http://support.microsoft.com/?kbid=814472, but it looks like a
research project.
Ah, you found the link. It's not a research project.


it is if you have been outside of the m$ world for a few years.
It is pretty detailed, no?
yes, it is detailed.

In a mixed-mode DLL of mine, I have this module:

#include <_vcclrit.h> ...
void WINAPI Init(void) ...
void WINAPI Term(void) ...
I link the project with the /NOENTRY ...
i will try this sometime.
what i would like to do is to package the pure c++ code into a pure ...
I think there is a disconnect here because the word DLL is in a way
overloaded. DLLs that contain assemblies are different enough from those
that export a flat API that special handling is required. (Just BTW and
IIRC, VS2005 does a better job of hiding the differences)


i am sure that it does. but i am stuck with 2003 in the labs.

is your init and term stuff above for 2005 or 2003?

thanks

Mar 29 '06 #3
"Ray Tayek" <rt*******@spam.comcast.net> wrote in message
news:MP************************@msnews.microsoft.c om...
the code is all pure.
Hmm. Are you compiling with the /clr switch on?
it is if you have been outside of the m$ world for a few years.
Mixing and matching code from runtime environments is not often easy.
i will try this sometime.
Hmm. I thought you wanted to know how to get unmanaged C++ code and .Net
code to interoperate. My post tried to address that issue.

If don't have any experience with Nunit so I can't offer anything there.
Maybe someone else will chime in.
is your init and term stuff above for 2005 or 2003?


VS 2003. AFAIK, without resorting to tricks VS2005 only targets v2.0 of the
..Net framework. I need to support 1.1 so 2003 is it for me.

Regards,
Will
Mar 29 '06 #4
In article <uv**************@tk2msftngp13.phx.gbl>,
wi***********@mvps.org says...
"Ray Tayek" <rt*******@spam.comcast.net> wrote in message
news:MP************************@msnews.microsoft.c om...
the code is all pure.
Hmm. Are you compiling with the /clr switch on?


yes
... i will try this sometime.


Hmm. I thought you wanted to know how to get unmanaged C++ code and .Net
code to interoperate.


they interop fine ifi build a console app (.exe).
My post tried to address that issue.
it probably does, i will try that when i get some time
If don't have any experience with Nunit so I can't offer anything there.
Maybe someone else will chime in.


the nunit works fine. my problem (right now) is linking
is your init and term stuff above for 2005 or 2003?


VS 2003. AFAIK, without resorting to tricks VS2005 only targets v2.0 of the
.Net framework. I need to support 1.1 so 2003 is it for me.


we do have 2005 in two of the labs now, so i mat try that experiment
also.

thanks
Mar 29 '06 #5

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

Similar topics

5
by: Tom | last post by:
I am new to C# and VS.Net. How do I test inidividual classes? I'm used to Java where a Main method for every class to test it. However, VS sees each Main method as an entry point into the .exe. What...
10
by: Gary Hughes | last post by:
I'm getting the following error when attempting to link a managed C++ dll. I can't find any reference to these errors with google. Can anyone help? I've included the class definition causing the...
5
by: Marco Zapletal | last post by:
hi group, i am facing the following problem: i have a vs.net (c#) project, which compiles into a class library. now i wrote a kind of testcase (with a main method()) which i want to execute...
7
by: Kristof Thys via .NET 247 | last post by:
Post a new message to microsoft.public.dotnet.languages.vc http://www.dotnet247.com/247reference/default.aspx Hello, I've been struggling for weeks with this problem, I hope I find some...
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...
6
by: tchaiket | last post by:
Hey all, I'm using NUNIT to test our classes. However, I don't want to hard code test data into the NUNIT classes. For example, to test adding a new Client, I don't want to hard code the...
16
by: Rainer Queck | last post by:
Hi, What would be the best way to develop a class library? I am planing to develop a couple of classes, needed in our company enviroment. These classe will be later used in several projects. ...
1
by: learning | last post by:
Hi how can I instaltiate a class and call its method. the class has non default constructor. all examples i see only with class of defatul constructor. I am trying to pull the unit test out from...
3
by: Med | last post by:
Hi, I use Visual C# Express 2005 and Visual Web Developer Express 2005. In my Visual C# Express 2005 Solution, I have following two class library projects: _ DataAccess (Namespace name:...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.