I try to convert a given hwnd in a std::wstring into a real HWND.
At the moment, I try it like that:
std::wstring clienthwnd = L"87CAFD04"; //clienthwnd is OK
long longclienthwnd = (LONG)_wtol((TCHAR*)clienthwnd.c_str());
//longclienthwnd = '0x00000057'
HWND pclienthwnd = reinterpret_cast<HWND>(longclienthwnd); //pclienthwnd =
'0x00000057' => unused = ??? => HWND__**
How can I convert that?
Best regards,
Carsten Unterberg|Test-Framework
http://test-framework.blogspot.com/
>Hello,
>
>I try to convert a given hwnd in a std::wstring into a real HWND.
Are you sure you need/want to do this? If you tell us why, someone may
have a better solution.
>
>At the moment, I try it like that:
>
>std::wstring clienthwnd = L"87CAFD04"; //clienthwnd is OK
If your real code is going to hard code a string like this, then I
really wonder. If you're just doing this to provide a sample, then not
so strange.
>long longclienthwnd = (LONG)_wtol((TCHAR*)clienthwnd.c_str());
Casts are generally suspect. Casts involving character strings are
even worse. your use of (TCHAR *) here looks very suspicious. First
you set clienthwnd using a UNICODE constant string, then you extract
the string using a function that always returns a pointer to an ASCII
string. And then you cast to a TCHAR pointer, which can be UNICODE or
not depending on compiler settings; for Windows CE it is always
UNICODE. If you really this confused about UNICODE, I _strongly_
recommend taking time to understand it. Otherwise, you will waste a
lot of your time tracking down odd errors.
>//longclienthwnd = '0x00000057'
>HWND pclienthwnd = reinterpret_cast<HWND>(longclienthwnd); //pclienthwnd =
>'0x00000057' => unused = ??? => HWND__**
>
>How can I convert that?
>
>Best regards,
>
>Carsten Unterberg|Test-Framework
>http://test-framework.blogspot.com/
>
>
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
thanks at first for that fast reply.
I think, I need it for my current project. I created a c++ application and a
.NetCF application. Both are communicated via Windows Messages.
I need the conversion from wstring to HWND in the c++ application to get
sure to have the correct .NetCF application on the backside, this, which
starts the c++ application. For sure, I could look with the FindWindow()
function for that .NetCF application, if there is more the application in
the processlist with "#NETCF_AGL_MSG_' as classname, I have got a problem.
S, I decided to walk the way with the parameter.
I hope, that make it better to understand.
Best regards,
Carsten
<r_z_aret@pen_fact.com> schrieb im Newsbeitrag
news:arcud55ubhc2oni9u...@4ax.com...
>hey,
>
>thanks at first for that fast reply.
>
>I think, I need it for my current project. I created a c++ application and a
>.NetCF application. Both are communicated via Windows Messages.
>
>I need the conversion from wstring to HWND in the c++ application to get
>sure to have the correct .NetCF application on the backside, this, which
>starts the c++ application.
How did you get the HWND that you stored in the string? Why not just
store the value as an HWND and compare it directly? I don't think you
can trust any HWND you store; I believe it changes every time a window
opens.
For sure, I could look with the FindWindow()
This is usually the right way to go. Particularly if the window has a
unique window class that you can use in the first argument to
FindWindow.
>function for that .NetCF application, if there is more the application in
>the processlist with "#NETCF_AGL_MSG_' as classname, I have got a problem.
If "#NETCF_AGL_MSG" is the windows class name (associated with a
window, not a C++ object), then FindWindow is pretty clearly the right
way to go.
HWND pclienthwnd = (HWND)_tcstoul(clienthwnd.c_str(), NULL, 16);
--
Giuseppe Govi
giuseppe.govi <> syncdata it