473,785 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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) _CxxThrowExcept ion
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::s tring *,Foo *> m; };
}

Mar 27 '06 #1
4 2397
"Ray Tayek" <rt*******@spam .comcast.net> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
trying to put the code below into a .net class library gets unresolved
externs:
pure error LNK2020: unresolved token (0A000006) _CxxThrowExcept ion
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_initi alize();
}

/*************** *************** *************** *************** *********
*************** *************** *************** *************** *********/
void WINAPI Term(void)
{
__crt_dll_termi nate();
}

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***********@m vps.org says...
"Ray Tayek" <rt*******@spam .comcast.net> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
trying to put the code below into a .net class library gets unresolved
externs: ... pure error LNK2020: unresolved token (0A000006) _CxxThrowExcept ion ...
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.micros oft.com...
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***********@m vps.org says...
"Ray Tayek" <rt*******@spam .comcast.net> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
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
2034
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 is the standard procedure for debugging individual classes Thanks
10
9529
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 errors below. Everything compiles fine and all the types are defined, it appears that the template type itga::order_collection::iterator is causing the trouble. Gary.
5
1686
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 (and debug) from vs.net. but i found no possibility how to execute this testcase in my project... any help would be appreciated,
7
1746
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 help here...
13
5056
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 use that dll from pure unmanaged code (for example inherit from classes in that dll). Is something like that possible. I heared something called ManWarp tried that approach. If it is possible, how can I do that. Maybe there is a small litttle
6
6080
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 Client Name, phone number, email, etc. I want to the NUNIT to read this data from a file. This way I can change the data in a file easily and test various types of test data. I think this can be done using the CONFIG file that NUNIT reads. Is
16
2597
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. Are there any "how to" links available on how to do that with visual studio? Would it be best to have a "Windows" or "Console" application to develop and test each class and then put it into a library later on or is it possible to
1
2837
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 the product source code, but still want to execute them under nunit. I am trying this idea on nunit sample source code. Here is my class and the experiemental code: both money.cs and Imoney.cs is compiled to cs_money.dll. then I create another...
3
1675
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: DataAccess) _ SystemLibrary (Namespace name: SystemLibrary) which they both build in their own "bin\Release\" folders.
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.