G
Guest
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
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