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

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\ScannerTest\Debug\TestLib.dll : fatal error LNK1120:
2 unresolved externals
Nov 17 '05 #1
2 1744
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;libcmt.lib;libc.lib nochkclr.obj
Force symbol reference: __DllMainCRTStartup@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
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...
1
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. ...
4
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...
3
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
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...
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...
2
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
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...
9
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...
25
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...
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: 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
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
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
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.