473,396 Members | 1,599 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.

Mixed question: Should I wrap unmanaged headers with #pragmas?

I have an older MFC C++ app with some new Managed C++ being thrown in. Recently I turned on the /clr flag for one of my old .cpp files. I then placed '#pragma unmanaged' just below my #include statements near the top of the file. These headers contain older unmanaged class declarations.

When running I discovered a new bug, a crash, at a point in execution that was nowhere near any code that's been touched in quite a while. After hunting down logical code paths with no luck finding the problem, I tried turning off the /clr flag and that made the problem go away. I will need /clr later, so I want to get to the bottom of this bug.

I tried moving the #pragma unmanaged to the very top of the file, but it then refused to compile stating:
vcclr.h(23) : error C3821: 'const unsigned char': managed type cannot be used in an unmanaged function.

So next I tried moving the #pragma unmanaged just below the call to #include stdafx.h, which was the first file included. This compiled. (As an aside, can anyone explain why it matters if stdafx.h is called after #pragma managed or unmanaged?) Anyway, it compiled so I tried running and TADAAA! The program ran smoothly.

Now the big question. Do I actually need to consciously consider my current managed/unmanaged context when including my headers? What in particular could be in a header file that would cause my runtime execution to break under these circumstances? Or did I only hide a bug that was previously hidden but lately uncovered with /clr compilation?

Any pointers?

thanks
knormand
Nov 17 '05 #1
1 1849
Sin
> As an aside, can anyone explain why it matters if stdafx.h is called
after #pragma managed or unmanaged?


Can't comment on your other questions but I can tell you that #include
<stdafx.h> needs to be the first line in your file when precompiled headers
are used. Think of it as a compiler limitation. No idea what the real reason
is, but the compiler could at least tell us stdafx.h is not included on the
first line rather than babling unrelated errors. Anyways... I don't use
precompiled headers anymore and things have been running smootly ever
since... lol

Alex.
Nov 17 '05 #2

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

Similar topics

13
by: Jason Swett | last post by:
I want to do graphics with C++. Surprisingly, so far nobody has been able to tell me anything helpful. How do I do it? Any input would be greatly appreciated. Jason
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
8
by: Ted Miller | last post by:
Hi folks, I'm looking at moving a large base of C++ code to .Net under tight time constraints. The code runs in mission-critical environments, and I am extremely concerned about the loader lock...
8
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid...
2
by: Steve McLellan | last post by:
Hi, We've found some pretty serious performance hits that we didn't expect in a mixed mode C++ application. The number crunching bits of our algorithms are compiled with #pragma unmanaged. They...
1
by: Bern McCarty | last post by:
Our project consists of some mixed .dlls and recently we noticed that it had slowed down. When I investigated I figured out that some inlineable methods of a native C++ type were compiled into (not...
6
by: Robert Ginsburg | last post by:
I have a DLL that is "mixed mode" in that it is both an ATL com server and a reference managed C++ class. For the most part it works, however the problem I have (which may simply not be solvable)...
4
by: quortex | last post by:
Hey all, I have been working on a project which consists of Native C++ code and managed C# code. In order for the managed C# code to be able to access the native layer I wrap some objects using...
7
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I'm new to working with mixed assemblies. All of my previous experience has been with VC++/MFC in native, unmanaged applications. When I create a mixed assembly in which one or more of the files...
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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.