MFC App + Managed C++ : Release compiles, Debug DOESN'T (operator new issue) 
Author Message
 MFC App + Managed C++ : Release compiles, Debug DOESN'T (operator new issue)

When trying to add CLR support (Managed C++) to an existing MFC app, I
am unable to instantiate .NET objects (via "new") in Debug mode, but
can in Release.  The following line produces the subsequent error:

CODE:
  SqlConnection* sqlconn = new SqlConnection(connectString);

COMPILER ERROR:
placement arguments are not allowed while creating instances of
managed classes

This code comes from a simple dialog-based MFC app, created in VS
.NET.  The proper using directives have been included at the top of
the file, along with the /CLR and /LD compiler options.  This compiles
and runs perfectly in Release but gives the above compiler error only
in Debug.  In researching this error message, I find references to
"placement arguments" in overloaded operator new documentation (which
is why I tried a Release Build).  

I've scanned the UseNet groups and have not found anyone else with
this problem.  Anyone with some insight???

Jeff Bush



Wed, 18 Aug 2004 12:19:12 GMT  
 MFC App + Managed C++ : Release compiles, Debug DOESN'T (operator new issue)
This is an FAQ, it surprises me you haven't found references to it. E.g. on
this newsgroup it has been discussed several times.

MFC in debug mode uses placement new to help associate the line number of an
allocation for each allocated block of memory.

Can you try

#undef new

after including the MFC headers and let us know whether that fixes it?

Ronald Laeremans
Visual C++ compiler team


Quote:
> When trying to add CLR support (Managed C++) to an existing MFC app, I
> am unable to instantiate .NET objects (via "new") in Debug mode, but
> can in Release.  The following line produces the subsequent error:

> CODE:
>   SqlConnection* sqlconn = new SqlConnection(connectString);

> COMPILER ERROR:
> placement arguments are not allowed while creating instances of
> managed classes

> This code comes from a simple dialog-based MFC app, created in VS
> .NET.  The proper using directives have been included at the top of
> the file, along with the /CLR and /LD compiler options.  This compiles
> and runs perfectly in Release but gives the above compiler error only
> in Debug.  In researching this error message, I find references to
> "placement arguments" in overloaded operator new documentation (which
> is why I tried a Release Build).

> I've scanned the UseNet groups and have not found anyone else with
> this problem.  Anyone with some insight???

> Jeff Bush



Wed, 18 Aug 2004 16:17:49 GMT  
 MFC App + Managed C++ : Release compiles, Debug DOESN'T (operator new issue)
Ron,
Thanks, that fixed it.
Sorry for the unnecessary post.  Where is the FAQ?
-Jeff

On Sat, 2 Mar 2002 00:17:49 -0800, "Ronald Laeremans [MSFT]"

Quote:

>This is an FAQ, it surprises me you haven't found references to it. E.g. on
>this newsgroup it has been discussed several times.

>MFC in debug mode uses placement new to help associate the line number of an
>allocation for each allocated block of memory.

>Can you try

>#undef new

>after including the MFC headers and let us know whether that fixes it?

>Ronald Laeremans
>Visual C++ compiler team



>> When trying to add CLR support (Managed C++) to an existing MFC app, I
>> am unable to instantiate .NET objects (via "new") in Debug mode, but
>> can in Release.  The following line produces the subsequent error:

>> CODE:
>>   SqlConnection* sqlconn = new SqlConnection(connectString);

>> COMPILER ERROR:
>> placement arguments are not allowed while creating instances of
>> managed classes

>> This code comes from a simple dialog-based MFC app, created in VS
>> .NET.  The proper using directives have been included at the top of
>> the file, along with the /CLR and /LD compiler options.  This compiles
>> and runs perfectly in Release but gives the above compiler error only
>> in Debug.  In researching this error message, I find references to
>> "placement arguments" in overloaded operator new documentation (which
>> is why I tried a Release Build).

>> I've scanned the UseNet groups and have not found anyone else with
>> this problem.  Anyone with some insight???

>> Jeff Bush



Sat, 21 Aug 2004 08:07:53 GMT  
 MFC App + Managed C++ : Release compiles, Debug DOESN'T (operator new issue)
We are working on one. I just meant it was frequently asked.

I just tried Dejanews today to search this newsgroup and I am seeing less
than 10% of all posts found. I will try to have someone work with them to
fix it.

-Ronald-


Quote:
> Ron,
> Thanks, that fixed it.
> Sorry for the unnecessary post.  Where is the FAQ?
> -Jeff

> On Sat, 2 Mar 2002 00:17:49 -0800, "Ronald Laeremans [MSFT]"

> >This is an FAQ, it surprises me you haven't found references to it. E.g.
on
> >this newsgroup it has been discussed several times.

> >MFC in debug mode uses placement new to help associate the line number of
an
> >allocation for each allocated block of memory.

> >Can you try

> >#undef new

> >after including the MFC headers and let us know whether that fixes it?

> >Ronald Laeremans
> >Visual C++ compiler team



> >> When trying to add CLR support (Managed C++) to an existing MFC app, I
> >> am unable to instantiate .NET objects (via "new") in Debug mode, but
> >> can in Release.  The following line produces the subsequent error:

> >> CODE:
> >>   SqlConnection* sqlconn = new SqlConnection(connectString);

> >> COMPILER ERROR:
> >> placement arguments are not allowed while creating instances of
> >> managed classes

> >> This code comes from a simple dialog-based MFC app, created in VS
> >> .NET.  The proper using directives have been included at the top of
> >> the file, along with the /CLR and /LD compiler options.  This compiles
> >> and runs perfectly in Release but gives the above compiler error only
> >> in Debug.  In researching this error message, I find references to
> >> "placement arguments" in overloaded operator new documentation (which
> >> is why I tried a Release Build).

> >> I've scanned the UseNet groups and have not found anyone else with
> >> this problem.  Anyone with some insight???

> >> Jeff Bush



Sat, 21 Aug 2004 09:00:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Use of operator new in a Managed MFC application

2. GetLastInputInfo doesn't compile in Release

3. Debug Version of program works, release doesn't

4. Debug version works, Release version doesn't

5. Debug Build works Release build doesn't?

6. Debug works, Release doesn't

7. Debug version works, release doesn't

8. Release hangs but debug doesn't

9. Debug version works, Release version doesn't

10. Strange problem: release build crashes, debug doesn't

11. Debug works, Release doesn't

12. Calling function in managed dll from Unmanaged MFC Application doesn't work on XP

 

 
Powered by phpBB® Forum Software