473,544 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to mix managed and unmanaged code

The project that I am on is going to require me to mix managed and unmanaged
code. I created a vc++ class library (.net) project bane TestLib.

I inserted the following test code in testLib.h. The code came from the MS
example on mixing managed and unmanaged code. When I build the project, I get
two unresolved external symbols on from the MClass Constructor and
Destructor. I'll guess I am missing a build switch. The doc says I need /clr
and /LD but they have no affect. The actual link errors follow the code.

Thanks in advance...Chuck

// TestLib.h
#pragma once
using namespace System;

namespace TestLib
{
class CppClass
{
public:
// constructor
CppClass() {}
// destructor
~CppClass() {}
// methods
void native_f() {}
};

public __gc class MClass
{
public:
// constructor
MClass() { m_pC = new CppClass(); }
// destructor
~MClass() { delete m_pC; }
// method
void managed_f() { m_pC->native_f(); }
private:
CppClass * m_pC;
};

}

Compiling...
TestLib.cpp
Linking...
TestLib.obj : error LNK2001: unresolved external symbol "void * __cdecl
operator new(unsigned int)" (??2@$$FYAPAXI@ Z)
TestLib.obj : error LNK2001: unresolved external symbol "void __cdecl
operator delete(void *)" (??3@$$FYAXPAX@ Z)
D:\Source Files\statrad\S cannerTest\Debu g\TestLib.dll : fatal error LNK1120:
2 unresolved externals
Nov 17 '05 #1
2 1756
Hi.

add msvcrt.lib (or msvcrtd.lib) to the project dependencies (Project
properties/Linker/Input/Additional Dependencies)

see also: http://support.microsoft.com/?id=814472

hope this helps.

Csaba

Nov 17 '05 #2
Hi,

I've done similar projects and found that I had to play with other
settings also to get rid of every problem. Here are the VS 2003
solution settings that ultimately worked for me.

General:
Use of MFC: Use MFC in a Shared DLL

Compiler:
Runtime Lib: Multi-threaded DLL (/MD)
Compile As Managed: Yes for managed files, No for unmanaged

Linker:
Additional Dependencies: mscoree.lib msvcrt.lib
Ignore all default libs: No
Ignore specific libs: nafxcw.lib;libc mt.lib;libc.lib nochkclr.obj
Force symbol reference: __DllMainCRTSta rtup@12
Additional options: /noentry

Then add the ManagedWrapper. cpp file as per the MSDN article 814472
(and call the minitialize() and mterminate() functions from within your
VB.NET,c#, etc. code before and after using the new managed/unmanaged
assembly.
ctrucza wrote:
Hi.

add msvcrt.lib (or msvcrtd.lib) to the project dependencies (Project
properties/Linker/Input/Additional Dependencies)

see also: http://support.microsoft.com/?id=814472

hope this helps.

Csaba


Nov 17 '05 #3

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

Similar topics

1
741
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a managed point-of-view I've noticed that: 1) for each managed and unmanaged C function (not C++ classes) I get a public managed static method...
1
2105
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...
4
7166
by: repstat | last post by:
Hi I have a project which is going to be doing some string manipulation which needs to be pretty fast. The user interface is going to be written in C#. I am going to write the string handling functions in a C++ DLL. My first question is, if I insert a C++ project into my C# solution, how will VS.NET know that I want it to be unmanaged code?...
3
3490
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust ------------------------------------------------------------------------
3
2760
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple question.
13
5020
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...
2
2712
by: Sandy | last post by:
I am confused about Unmanaged Code, How .Net Framework treate that code, What is the use of that. Thanks in advance Sandeep Chitode
6
1442
by: nicolas.hilaire | last post by:
Hi all, i'm not totally clear with some concepts about managed and unmanaged code. I'm asking myself some questions : - i've a MFC app, i want to use the framework dotnet by switching to /clr compilation mode. Is my app in CLR, or only the call to the
9
3102
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a...
25
2981
by: Koliber (js) | last post by:
sorry for my not perfect english i am really f&*ckin angry in this common pattern about dispose: ////////////////////////////////////////////////////////// Public class MyClass:IDisposable
0
7360
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...
0
7761
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...
1
7363
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...
0
5899
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...
1
5289
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
3400
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1833
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
1
983
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
653
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.