Work only inside debuger?!

S

Stephan Schaem

get this string when I press CTRL-F5 to run:

ØB-

I get this string when I press F5 to run:

Mobile Intel(R) Celeron(R) CPU 1.50GHz


I started with a 100% C++ unmanaged program and
I wanted to display the processor name, and so I gave the .net framework a try.

So I injected this code in one of the .cpp file (nothing more, nothing less)

#using <system.dll>
#using <System.Management.dll>

using namespace System;
using namespace System::Management;

void Function() {

......

ManagementObjectSearcher* query1 = new ManagementObjectSearcher("SELECT * FROM Win32_processor") ;
ManagementObjectCollection* queryCollection1 = query1->Get();
ManagementObjectCollection::ManagementObjectEnumerator* queryEnum1 = queryCollection1->GetEnumerator();
queryEnum1->MoveNext();
ManagementBaseObject* object = queryEnum1->get_Current();
Object* cpuName = object->GetPropertyValue(L"Name");

.....

// Emit html with processor name
html.td(AtlHtmlAttrs("%s", cpuName->ToString()));

}

Stephan
 
T

Tian Min Huang

Hello Stephan,

Thanks for your post. I did some test on my side, and now I'd like to share
the following information with you:

I reviewed your code and built a sample console application, it works
properly on my side with and without VS .NET 2003 debugger.

To narrow down the problem, please tell me what version of VS .NET you are
using, 2002 or 2003. I recommend you create a new console program to check
whether other project will also reproduce the problem on your side.

It the problem only occurs to a specific project, could you please post the
project and I will be glad to check it.

I look forward to hearing from you.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Stephan Schaem

Thanks for looking into it.

I cannot post the project, but will try to inject that code in some already existing MS Win32 SDK sample
and see if it behave the same.

To recap the problem: I have a win32 (100% unmanaged C++ project, with inline assembly and all) and
want to use some of the new API in it. I'm at the stage where it compile (after allot of project setting massage)
and link (with warning... for example I lost my "edit and continue" :(( ) and run fine when the debugger is invoked.

Stephan
 
S

Stu Smith

AtlHtmlAttrs seems to be expecting unmanaged strings of some sort, and
you're giving it a managed string. They certainly aren't guaranteed to be
the same thing (although for some odd reason, as you've found out, in debug
mode they are interchangeable).

You'll need to use something like this (*NOTE* untested!):

inline CString ToStr( System::String *strParam )
{
using System::Runtime::InteropServices::Marshal;
System::IntPtr ptr = Marshal::StringToHGlobalAnsi( strParam );
CString str = static_cast<LPCTSTR>( const_cast<void*>(static_cast<const
void*>( ptr ) ) );
Marshal::FreeHGlobal( ptr );
return str;
}

.....

html.td(AtlHtmlAttrs("%s", ToStr(cpuName->ToString())));


Hope that helps,

Stu



get this string when I press CTRL-F5 to run:

ØB-

I get this string when I press F5 to run:

Mobile Intel(R) Celeron(R) CPU 1.50GHz


I started with a 100% C++ unmanaged program and
I wanted to display the processor name, and so I gave the .net framework a
try.

So I injected this code in one of the .cpp file (nothing more, nothing less)

#using <system.dll>
#using <System.Management.dll>

using namespace System;
using namespace System::Management;

void Function() {

......

ManagementObjectSearcher* query1 = new ManagementObjectSearcher("SELECT *
FROM Win32_processor") ;
ManagementObjectCollection* queryCollection1 = query1->Get();
ManagementObjectCollection::ManagementObjectEnumerator* queryEnum1 =
queryCollection1->GetEnumerator();
queryEnum1->MoveNext();
ManagementBaseObject* object = queryEnum1->get_Current();
Object* cpuName = object->GetPropertyValue(L"Name");

.....

// Emit html with processor name
html.td(AtlHtmlAttrs("%s", cpuName->ToString()));

}

Stephan
 
D

David Notario

Hi Stephan.

Can you send me a standalone repro? (.exe). Also, please indicate which version of the CLR this is.



--
David Notario
Software Design Engineer - CLR JIT Compiler
http://xplsv.com/blogs/devdiary/

get this string when I press CTRL-F5 to run:

ØB-

I get this string when I press F5 to run:

Mobile Intel(R) Celeron(R) CPU 1.50GHz


I started with a 100% C++ unmanaged program and
I wanted to display the processor name, and so I gave the .net framework a try.

So I injected this code in one of the .cpp file (nothing more, nothing less)

#using <system.dll>
#using <System.Management.dll>

using namespace System;
using namespace System::Management;

void Function() {

.....

ManagementObjectSearcher* query1 = new ManagementObjectSearcher("SELECT * FROM Win32_processor") ;
ManagementObjectCollection* queryCollection1 = query1->Get();
ManagementObjectCollection::ManagementObjectEnumerator* queryEnum1 = queryCollection1->GetEnumerator();
queryEnum1->MoveNext();
ManagementBaseObject* object = queryEnum1->get_Current();
Object* cpuName = object->GetPropertyValue(L"Name");

....

// Emit html with processor name
html.td(AtlHtmlAttrs("%s", cpuName->ToString()));

}

Stephan
 
G

Girish Bharadwaj

Just to make sure, you might want to verify the different compiler options
between the release build and the debug build..
Of course, you might want to check errors in every step .. :)
--
Girish Bharadwaj
Hi Stephan.

Can you send me a standalone repro? (.exe). Also, please indicate which
version of the CLR this is.



--
David Notario
Software Design Engineer - CLR JIT Compiler
http://xplsv.com/blogs/devdiary/

get this string when I press CTRL-F5 to run:

ØB-

I get this string when I press F5 to run:

Mobile Intel(R) Celeron(R) CPU 1.50GHz


I started with a 100% C++ unmanaged program and
I wanted to display the processor name, and so I gave the .net framework a
try.

So I injected this code in one of the .cpp file (nothing more, nothing less)

#using <system.dll>
#using <System.Management.dll>

using namespace System;
using namespace System::Management;

void Function() {

......

ManagementObjectSearcher* query1 = new ManagementObjectSearcher("SELECT *
FROM Win32_processor") ;
ManagementObjectCollection* queryCollection1 = query1->Get();
ManagementObjectCollection::ManagementObjectEnumerator* queryEnum1 =
queryCollection1->GetEnumerator();
queryEnum1->MoveNext();
ManagementBaseObject* object = queryEnum1->get_Current();
Object* cpuName = object->GetPropertyValue(L"Name");

.....

// Emit html with processor name
html.td(AtlHtmlAttrs("%s", cpuName->ToString()));

}

Stephan
 
S

Stephan Schaem

I never tested the release build... The binary code executed is the same,
the diference betwen both result is if the visual studio debugger is running
or not.

Stephan
 
S

Stephan Schaem

Thank you! this work.

I would like to rant that this is completly insane...

And I would like to see MS post their reasoning behind creating this
complete mess!

This type of complexity to access a string is simply unaceptable.

MS team : Stop making managed only API , you are killing the simplicity,
efficiency, cleaness of
the C++ language !

Stephan
 
Top