473,396 Members | 1,671 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,396 software developers and data experts.

\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 4577
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********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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,off)

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\common\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********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.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,off)

#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\vcclr.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\vcclr.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
Can anyone help me on this?
it has become a real show stopper!

How can i reference umanaged types derived from the MFC CObject within
a managed module?

I thought this was a big selling point of the mixed mode approach?

Dec 9 '05 #11
Yes I can help myself. I 'managed' to do it.

<code>
#include <afx.h> // MFC core and standard components
#include<afxtempl.h>

#pragma managed(push, off)
#include"map_dwo.h"
#include"RuntimeMap.h"
#include"Convert2DotNet.h"
#pragma managed(pop)

#using<Runtime2.DLL>

using namespace Runtime2;

bool Convert2DotNet(CRuntimeMap* pMap)
{
RuntimeMap^ pGcMap = gcnew RuntimeMap;
return true;
}
</code>

Had to exclude the system headers outside of the un-managed set.

All systems go!

Dec 9 '05 #12
Ok..
Given an unmanaged class is it possible for one of its methods to be
compiled as managed?

The reason being im copying member data from the source unmanaged
object to the new managed target object. I would like direct acces to
this source member data via one of its methods.
Ideally all my current un-managed classes that must take part in the
..NET converison will implement the Convert2DotNet method( preferably
via an iterface class, but lets keep it simple as possible for now)

E.g.

#pragma managed
CRuntimeMap::Convert2DotNet(void)
{
}

When i attempt to do this i get the following error

error C3295: '#pragma managed' can only be used at global or namespace
scope

Is there anyway to acheive this?

Dec 9 '05 #13

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

Similar topics

9
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...
13
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...
0
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...
5
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...
4
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...
0
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...
5
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...
5
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.