473,786 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

\CLR Mixed mode compilation woes!

Iv compiled my current C++ project as \clr as i want to start putting
in some specific C++\CLI code to serialize my MFC objects to .NET
equivalents.
The program crashes on startup, something to do with the stack frame
being corrupted.

My first concern is the program has ballooned in terms of the size of
the executable image.
When it attempts to run it fails and some report about stack frame
corruption.

Iv noticed any C files have to be converted to C++.

The program links to a DLL and Libs that have been compiled as C.

Is this a problem when compiling a program as /CLR that then links with
C libs etc and on startup loads C Dlls?

How can i specifically instruct the compiler to only compiler specific
functions/methods as managed(mixed mode) and to leave everything else
as native?
Is this possible?

Thanks in advance.

Dec 7 '05 #1
12 4611
Have you first tried just compiling and running it successfully in VC++ 2005
(without /clr turned on) ? Does it work okay then?

--
Regards,
Nish [VC++ MVP]
"Herby" <pr********@gma il.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Iv compiled my current C++ project as \clr as i want to start putting
in some specific C++\CLI code to serialize my MFC objects to .NET
equivalents.
The program crashes on startup, something to do with the stack frame
being corrupted.

My first concern is the program has ballooned in terms of the size of
the executable image.
When it attempts to run it fails and some report about stack frame
corruption.

Iv noticed any C files have to be converted to C++.

The program links to a DLL and Libs that have been compiled as C.

Is this a problem when compiling a program as /CLR that then links with
C libs etc and on startup loads C Dlls?

How can i specifically instruct the compiler to only compiler specific
functions/methods as managed(mixed mode) and to leave everything else
as native?
Is this possible?

Thanks in advance.

Dec 7 '05 #2
Yes compiled un-managed first and is OK.

Dec 7 '05 #3
"Herby" <pr********@gma il.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Iv compiled my current C++ project as \clr as i want to start putting
in some specific C++\CLI code to serialize my MFC objects to .NET
equivalents.
The program crashes on startup, something to do with the stack frame
being corrupted.

My first concern is the program has ballooned in terms of the size of
the executable image.
When it attempts to run it fails and some report about stack frame
corruption.
You should be specific: exactly how is it failing, exactly what is reported?

Iv noticed any C files have to be converted to C++.
Yes. You cannot compile C as managed code.

The program links to a DLL and Libs that have been compiled as C.
That's fine.

Is this a problem when compiling a program as /CLR that then links with
C libs etc and on startup loads C Dlls?
No, there's no problem with that. Consider that the operating system itself
is C and is exposed through DLLs...

How can i specifically instruct the compiler to only compiler specific
functions/methods as managed(mixed mode) and to leave everything else
as native?


See #pragma managed and #pragma unmanaged. You also can throw the /clr
compiler option only on files that contain managed code and continue to
compile everything else as native code. That might save you from having to
insert #pragma unmanaged a bunch of places.

Note that header files that define declarations that will be shared between
native and managed code should generally be written as:

// MySharedHeader. h
#pragma once
#pragma managed(push, off)

// your declarations here

#pragma managed(pop)

This will ensure that the declarations in the shared header are always seen
as unmanaged regardless of how the compilation unit the references the
header file is compiled.

Note also that preprocessor macros (#define) are neither managed nor
unmanaged - they're simply text substitutions, so they'll work identically
in either environment.

-cd
Dec 7 '05 #4
Yes i did do that first. And it runs OK.

Dec 7 '05 #5
Ok, Iv not actually added anything managed yet.
Im just trying to compile it with the \CLR option.
I have now switched off clr for each source file but left it on for the
project.

One day this will all be 2nd nature i hope - must just persevere :-)

Im much more a software developer than a compiler tweaking geek! :-)

And it now works!

So ill call it a day there! and dream about how i can begin to add some
new managed code.

Once again, thanks alot for all your help!

Dec 7 '05 #6
Ok, have moved on, but having problems with shared headers.
Have added #pragmas as described above, but still throwing out
errors...

e.g.

// constants.h
#pragma once
#pragma managed(push,of f)

extern BOOL bIsOLE;

#pragma managed(pop)

-----------------------------------------------------------------------------

//Convert2DotNet. cpp // compiled with /clr
// Have taken out pre-compiled header here stdafx.h
#include "constants. h"

bool Convert2DotNet( void)
{
return true;
}

-----------------------------------------------
When compiling get many errors including
c:\dev.2005.net \designtime\com mon\constants.h (24) : error C2146: syntax
error : missing ';' before identifier 'bIsOLE'

Can anyone help?

Thanks.

Dec 8 '05 #7
I think that one is simply because i had excluded stdafx.h and this
file includes all the system dependencies etc, which go on to define
BOOL.
I cannot change the system headers - so how am i to proceed on this
one?

Dec 8 '05 #8
"Herby" <pr********@gma il.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
I think that one is simply because i had excluded stdafx.h and this
file includes all the system dependencies etc, which go on to define
BOOL.
I cannot change the system headers - so how am i to proceed on this
one?


The error indicates that BOOL wasn't defined before you used it in
constants.h. Based on what you posted, the error is correct.

The following compiles without error for me:

<code>
#pragma managed(push,of f)

#include <windows.h>

extern BOOL IsOle;

#pragma managed(pop)

bool f()
{
return IsOle;
}
</code>

compile with cl -c -clr

-cd
Dec 8 '05 #9
Thanks Carl, Iv been through so much to get this far and this would
appear to be my last hurdle, and im worried...

My problem now is im going to be referencing my unmanaged classes that
derive from the MFC CObject.
So I need something like:

<code>
#pragma managed(push, off)

#include <afx.h> // MFC core and standard components
#include "constants. h"

#pragma managed(pop)

bool Convert2DotNet( void)
{
return true;
}
</code>

When I now compile this i get the following errors...

C:\Program Files\Microsoft Visual Studio 8\VC\include\vc clr.h(42) :
error C3821: 'cli::interior_ ptr<Type>': managed type or function cannot
be used in an unmanaged function
with
[
Type=unsigned char
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\vc clr.h(42) :
error C3821: 's': managed type or function cannot be used in an
unmanaged function
Headers can still be a real headache it seems...

Can i resolve this?

Thanks.

Dec 8 '05 #10

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

Similar topics

9
2592
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and explain it. I have some questions about the instructions for creating a mixed mode DLL in the MSDN topic "Converting Managed Extensions for C++ Projects from Pure Intermediate Language to Mixed Mode" in the "Managed Extensions for C++ Reference"....
13
4150
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
0
1004
by: bonk | last post by:
I have a plain unmanaged exe (no /CLR) that is supposed to to use classes from a mixed mode dll (dll that uses .NET internally). That dll only needs to expose unmanaged interfaces (classes and/or functions). This is of course no problem and it works fine. However I have the special scenario where the exe needs to be able to run even when there is no .NET Framework installed. The exe is supposed to check at runtime if the .NET Framework is...
5
3278
by: bonk | last post by:
I have a plain unmanaged exe (no /CLR) that is supposed to to use classes from a mixed mode dll (dll that uses .NET internally). That dll only needs to expose unmanaged interfaces (classes and/or functions). This is of course no problem and it works fine. However I have the special scenario where the exe needs to be able to run even when there is no .NET Framework installed. The exe is supposed to check at runtime if the .NET Framework is...
4
2243
by: Lonewolf | last post by:
hi, I'm still in the process of transiting from MFC/VC6 to vs2005, and a lot of things are very alien to me. So hope you could bear with me if my question sounds stupid. Basically I have native codes written in VC6 which I want to encapsulate in a managed assembly using C++/CLI so that I can use it in C# easily without all the interop codes. So, my question is, what is the replacement for MFC's TRACE macro in VS2005's C++/CLI in...
0
1413
by: Russ Barrett | last post by:
Hello, I'm new to ASP.Net and I'm trying to interface an ASP.Net (C#) application to functionality resident in a C++ static lib. From posts I've seen around I understand this requires creation of a 'mixed-mode' assembly. Since a dll of this type provides no normal entry point for C Runtime (CRT) library initialization, I understand that the dll must provide its own exported functions to do this. Thus, from samples I've seen on the web,...
5
1463
by: Bart | last post by:
Hi, What is the benefit of using the Pure option over the Mixed one. Is there a better performance? We have a lot of stuff in c++ with mfc support en we want to use in our .net apps. With mixed setting we can compile including the mfc part of our code. We can get rid of the mfc code but it will cost us some effort so we can use the pure setting in that case.
5
1786
by: Jesper Schmidt | last post by:
Hi, I have a relatively large C++ code base, which requires that static initializers are called when a dll is loaded. This seems to work well for native code, but it does not work for files compiled with the /CLR option enabled. I will try to give a simple example that illustrates my problem. Library code: -----------
6
6201
by: R.Kaiser | last post by:
I know that I can call Win32 API functions in a Windows forms application by specifying each function header individually like in using namespace System; using namespace System::Runtime::InteropServices; typedef void* HWND; extern "C" int* MessageBox(HWND hWnd, char* pText,
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
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,...
1
10110
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
9961
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
8989
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
7512
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
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4066
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
2894
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.