Stephan Schaem
11/3/2003 10:44:00 AM
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
>
>