简体   繁体   中英

HWND abc = 0x100; This does not work, and I understand why. How to do it then?

I have a HWND variable that I want to point to an hardcoded value, just for testing purposes. I guess that HWND is a typedef of (int*) so that is causing some kind of indirection. What should the correct code be like?

HWND abc = (HWND)(0x100);

无论如何,这是个坏主意,但您已经知道了。

You can do: HWND hWnd = reintrepret_cast<HWND>(0x100); . Use explicit cast so that it is easy to find in the code.

You can't hard code an HWND value. At best, it would not refer to an existing window. At worst, it would refer to some random window in the system.

Edit: To be clear, any tests you run using the hardcoded value will be meaningless. Your program uses that HWND for something . As soon as it passes the hardcoded HWND to an API function, either that function will fail (best case) or it will cause random, unpredictable effects in random processes (worst case).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM