473,834 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mixing Managed C and Unmanaged C - Big Problem

Hi

All the information I had read suggested that if you had an existing C
project that you wished to change to managed code all you had to do was use
the /clr switch and then over time you could convert/add managed code bit by
bit.

I have done this on my large C project and all compiles and links OK. So far
so good.

I have now added a managed C++ file to the project which needs to call some
of the existing code in the unmanaged C files. When I link this I get error
LNK1235.

This is referred to in
http://support.microsoft.com/default...b;en-us;822329
which says you cannot do this unless you compile the previous C code without
/clr.

As this is a large project I have turned off /clr on the project as a whole
and then set it on the new C++ managed file. Now I get a linker error
telling me there is an cannot find the external symbols of the functions I
am calling in the unmanaged C code and also if I try to add a Windows form
to the project (part of the purpose of doing all this), I get errors because
the project isn't set to use /clr.

Can ant one advise on the correct way if there is one of taking a large C
project and compiling/linking it so that I can add individual managed C+_
files and windows forms to it.

Thanks

Steve
Nov 17 '05 #1
1 1268
Hi

I have solved the problem. I needed to leave the properties for the project
to Use Managed Extensions under General for the Project but set all the
individual C files (which you can do by highlighting them as a block) to not
use Managed Extensions under General under C/C++.

I also needed to declare all my external functiosn and symbols as external
"C" so that I could see them from the C++ file

Steve

"Steve Marsden" <st***@conquest .ltd.uk> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi

All the information I had read suggested that if you had an existing C
project that you wished to change to managed code all you had to do was
use the /clr switch and then over time you could convert/add managed code
bit by bit.

I have done this on my large C project and all compiles and links OK. So
far so good.

I have now added a managed C++ file to the project which needs to call
some of the existing code in the unmanaged C files. When I link this I get
error LNK1235.

This is referred to in
http://support.microsoft.com/default...b;en-us;822329
which says you cannot do this unless you compile the previous C code
without /clr.

As this is a large project I have turned off /clr on the project as a
whole and then set it on the new C++ managed file. Now I get a linker
error telling me there is an cannot find the external symbols of the
functions I am calling in the unmanaged C code and also if I try to add a
Windows form to the project (part of the purpose of doing all this), I get
errors because the project isn't set to use /clr.

Can ant one advise on the correct way if there is one of taking a large C
project and compiling/linking it so that I can add individual managed C+_
files and windows forms to it.

Thanks

Steve

Nov 17 '05 #2

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

Similar topics

0
2877
by: kaalus | last post by:
Hello I have problem mixing managed and unmanaged C++ code in VS.NET 2003. I want to create a windows forms application which uses some C++ code that is incompatible with managed extensions (__fastcall etc.). I have tried disabling "compile as managed" option for these specific files, but it does not help: by trial and error I figured out that if there are any "references" in the project, IDE adds /FU switch with each of these references to...
4
1692
by: Daniel Lidström | last post by:
Hello, is it possible to ``use CS to code a class, and (M)C++ for the logic''? Sorry if this sounds vague, I'm not really sure myself what it means. Does anyone have any ideas? -- Daniel
14
6503
by: Jon | last post by:
Whether I can compile a class or not, depends on the order of functions in my class. My question is (see example below): 1) Is it a bug that the class 'WillCompile' will compile and execute, or 2) or is it a bug that the class 'WillNotCompile' will not compile?. #include "stdafx.h" #include <iostream> #include <memory> using namespace std;
2
4447
by: quat | last post by:
I am getting the error: error C4368: cannot define 'd3dPP' as a member of managed 'FormEx::Form1': mixed types are not supported I am trying to mixed managed and unmanaged code (d3dPP is unmanaged, where the form is managed). Can I not have an unmanaged instance in a managed class?
3
2190
by: frank | last post by:
Hi I've got aplication, which one is written in unmanaged c++ with stl, i've made for it gui in managed c++. Problem becomes when I'm starting to filling up for example datagrids, when I'm adding row to datagrid , some varibles (vectors etc) in unmanaged class are cleared or filled with null. I want mention also when i compile only unmanaged class for console project (without .net gui) problem never happends, everything works fine.
3
4705
by: frank | last post by:
Hi I've got aplication, which one is written in unmanaged c++ with stl, i've made for it gui in managed c++. Problem becomes when I'm starting to filling up for example datagrids, when I'm adding row to datagrid , some varibles (vectors etc) in unmanaged class are cleared or filled with null. I want mention also when i compile only unmanaged class for console project (without .net gui) problem never happends, everything works fine.
0
2950
by: HeroOfSpielburg | last post by:
Hello, I'm new to the realm of .NET application creation, so please forgive my ignorance. I have been tasked with debugging a problem that arises with using a DLL that contains managed and unmanaged code in concert with a managed application that makes calls to the DLL. This problem has been cropping up for a while, but the debugger provides very little information (from what I can tell) as to what exactly is the problem.
2
16862
by: jraul | last post by:
Hi, This is probably a noobie question but: I just created a new C++/CLI project in VS 2005. It created an empty class: public ref class Class1 { // TODO: Add your methods for this class here.
2
12367
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the classes in managed C++ as a wrapper to the unmanaged C++ classes or is there an easier way? Essentially what I have done is written a C++ kernel mode driver and I want to use it from my C# program. Because it requires some setup outside the...
0
10793
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...
0
10509
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10547
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
10219
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9331
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...
0
5793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4427
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
2
3977
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3081
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.