[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Work only inside debuger?!

Stephan Schaem

10/3/2003 5:53:00 PM

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
8 Answers

timhuang

10/6/2003 3:35:00 AM

0

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.

quansun

10/6/2003 9:52:00 AM

0

Based on my test, I can't reproduce the issue on my side. You can try:
1. Otput the string to a console window, or a file, instead of the Html
control.
2. Try your sample on other machine to check whether it occurs.


Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

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

Stu Smith

10/7/2003 11:23:00 AM

0

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



"Stephan Schaem" <sschaem@seriousmagic.com> wrote in message
news:e72V%23cdiDHA.2536@TK2MSFTNGP10.phx.gbl...
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


David Notario [MS]

10/10/2003 4:00:00 AM

0

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...

"Stephan Schaem" <sschaem@seriousmagic.com> wrote in message news:e72V%23cdiDHA.2536@TK2MSFTNGP10.phx.gbl...
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

Girish Bharadwaj

10/13/2003 3:13:00 PM

0

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
"David Notario" <dnotario@online.microsoft.com> wrote in message
news:en2bLMujDHA.1656@tk2msftngp13.phx.gbl...
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...

"Stephan Schaem" <sschaem@seriousmagic.com> wrote in message
news:e72V%23cdiDHA.2536@TK2MSFTNGP10.phx.gbl...
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


Stephan Schaem

11/3/2003 9:44:00 AM

0

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

"Girish Bharadwaj" <girishb.at.mvps.dot.org> wrote in message
news:uo%23tyxZkDHA.2000@TK2MSFTNGP12.phx.gbl...
> 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
> "David Notario" <dnotario@online.microsoft.com> wrote in message
> news:en2bLMujDHA.1656@tk2msftngp13.phx.gbl...
> 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...
>
> "Stephan Schaem" <sschaem@seriousmagic.com> wrote in message
> news:e72V%23cdiDHA.2536@TK2MSFTNGP10.phx.gbl...
> 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
>
>


Stephan Schaem

11/3/2003 10:44:00 AM

0

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

"Stu Smith" <stuarts@remove.digita.com> wrote in message
news:ONqZTVMjDHA.2416@TK2MSFTNGP10.phx.gbl...
> 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
>
>
>
> "Stephan Schaem" <sschaem@seriousmagic.com> wrote in message
> news:e72V%23cdiDHA.2536@TK2MSFTNGP10.phx.gbl...
> 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
>
>


Stephan Schaem

11/3/2003 10:55:00 AM

0

It was reproduced on various system/config, debug/release...

Stu Smith posted a solution by using this code to access a string:


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;
}

But I'm not happy one bit.... Or in Ms land the saying is transformed to
"I'm not happy one kbyte"

Stephan



"Duke Sun" <quansun@online.microsoft.com> wrote in message
news:fWRMP%23%23iDHA.1928@cpmsftngxa06.phx.gbl...
> Based on my test, I can't reproduce the issue on my side. You can try:
> 1. Otput the string to a console window, or a file, instead of the Html
> control.
> 2. Try your sample on other machine to check whether it occurs.
>
>
> Best regards,
>
> Duke Sun
> Microsoft Online Partner Support
> <MCSE/MCDBA/MCSD>
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>