newbie Conversion type Problem urgent

G

Guest

I'm using Vs2002 .net framvwork sp3
I need to rerun my exe
I use that:
PROCESS_INFORMATION pi;
STARTUPINFO si;
memset( &pi, 0, sizeof(PROCESS_INFORMATION) );
memset(&si, 0, sizeof(STARTUPINFO));
si.cb= sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNA ;
si.lpDesktop = "";
CreateProcess( NULL,
Assembly::GetExecutingAssembly()->Location,
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&si,
&pi );
and i receive the following error
unable to convert parameter 2 from system::string__gc* to LPSTR
If i Put in the second parameter (char*))"progpath and name" all works!!
If i run
Console::writeline(S"location{0{ =
",Assembly::GetExecutingAssembly()->Location
I view the correct path
That's a conversion Problem i thing but i don't Know how to solve
thanks best
regards
Davide
 
T

Tamas Demjen

DavideR said:
and i receive the following error
unable to convert parameter 2 from system::string__gc* to LPSTR

If you need an ANSI C string, read this article:
http://www.codeproject.com/dotnet/managed_unmanaged.asp

You can use Marshal::StringToHGlobalAnsi to convert System::String to
char*. Don't forget about calling Marshal::FreeHGlobal afterwards.

If you need a Unicode Wide string, here's a tip:
http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx

Simply call PtrToStringChars to get a pointer to the internal
representation of the string. Don't forget about pinning it before
passing it to CreateProcess:

wchar_t __pin* pinned_s = PtrToStringChars(s);
// pass pinned_s to CreateProcess

Tom
 
G

Guest

Seems all Right Thanks
Best regards

Tamas Demjen said:
If you need an ANSI C string, read this article:
http://www.codeproject.com/dotnet/managed_unmanaged.asp

You can use Marshal::StringToHGlobalAnsi to convert System::String to
char*. Don't forget about calling Marshal::FreeHGlobal afterwards.

If you need a Unicode Wide string, here's a tip:
http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx

Simply call PtrToStringChars to get a pointer to the internal
representation of the string. Don't forget about pinning it before
passing it to CreateProcess:

wchar_t __pin* pinned_s = PtrToStringChars(s);
// pass pinned_s to CreateProcess

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top