I usually code in C# so C++ isn't my strongest side.. :-)
I'm creating a small C++ application that show a splash screen while the C#
application is loading.
My plan is to pass the splash window handle (hWnd) as a command line
argument when executing the C# application and then close the window with
the C# application when its finished loading. Everything works well except
casting (converting) the hWnd to a string. I've tried what I know of
casting, and using the sprintf function but I can't make functional code.
If anybody could help me I would be very thankful!

Regards
Oyvind Eriksen

Re: hWnd to string by James

James
Tue Sep 26 16:00:53 CDT 2006

char buf[10];

HWND hwnd = <your_window_handle>;

sprintf(buf, "%x", (DWORD)hwnd);

--
James Brown
Microsoft MVP - Windows SDK
www.catch22.net
Free Win32 Tutorials and Sourcecode



"Oyvind Eriksen" <oyvind -(at)- eriksen.cn> wrote in message
news:OgOOQwa4GHA.1496@TK2MSFTNGP05.phx.gbl...
>I usually code in C# so C++ isn't my strongest side.. :-)
> I'm creating a small C++ application that show a splash screen while the
> C# application is loading.
> My plan is to pass the splash window handle (hWnd) as a command line
> argument when executing the C# application and then close the window with
> the C# application when its finished loading. Everything works well except
> casting (converting) the hWnd to a string. I've tried what I know of
> casting, and using the sprintf function but I can't make functional code.
> If anybody could help me I would be very thankful!
>
> Regards
> Oyvind Eriksen
>



Re: hWnd to string by Tamas

Tamas
Tue Sep 26 16:00:22 CDT 2006

Oyvind Eriksen wrote:

> My plan is to pass the splash window handle (hWnd) as a command line
> argument when executing the C# application and then close the window with
> the C# application when its finished loading. Everything works well except
> casting (converting) the hWnd to a string.

The window handle is technically a void* pointer. Its .NET equivalent
type is IntPtr. The handle has the same size as any other pointer (32
bits on x86, 64 bits on x64). That means on Win32 you could cast it to
an integer for string conversion, but on Win64 you have to treat it as a
long long.

You migh want to use snprintf (the safe version of sprintf) with the
"%p" format specifier, which should convert the pointer to a hex string.

Tom

Re: hWnd to string by Alex

Alex
Wed Sep 27 09:37:12 CDT 2006

Oyvind Eriksen wrote:
> I usually code in C# so C++ isn't my strongest side.. :-)
> I'm creating a small C++ application that show a splash screen while the C#
> application is loading.
> My plan is to pass the splash window handle (hWnd) as a command line
> argument when executing the C# application and then close the window with
> the C# application when its finished loading. Everything works well except
> casting (converting) the hWnd to a string. I've tried what I know of
> casting, and using the sprintf function but I can't make functional code.
> If anybody could help me I would be very thankful!

Just out of curiosity, why do you need separate application
[moreover, written in C++] for splash screen? Can't you just
create another window from main C# application and show it?

Re: hWnd to string by Oyvind

Oyvind
Fri Sep 29 07:38:12 CDT 2006

"Alex Blekhman" <xfkt@oohay.moc> wrote in message
news:%23wlfsJk4GHA.4196@TK2MSFTNGP05.phx.gbl...
> Oyvind Eriksen wrote:
>> I usually code in C# so C++ isn't my strongest side.. :-)
>> I'm creating a small C++ application that show a splash screen while the
>> C# application is loading.
>> My plan is to pass the splash window handle (hWnd) as a command line
>> argument when executing the C# application and then close the window with
>> the C# application when its finished loading. Everything works well
>> except casting (converting) the hWnd to a string. I've tried what I know
>> of casting, and using the sprintf function but I can't make functional
>> code.
>> If anybody could help me I would be very thankful!
>
> Just out of curiosity, why do you need separate application [moreover,
> written in C++] for splash screen? Can't you just create another window
> from main C# application and show it?

The C# application will be running on some pretty old machines.
It's also somewhat large so on these machines it takes about 20 seconds to
start :-(
Several users will launch the application several times because apparently
nothing is happening...
This C++ application launches instantly and shows the splash screen until
the C# application is finished loading.

Btw, I'm very embarrassed about this question now I'm finished... :-)


Regards,
Oyvind Eriksen