Unusual behavior...for me.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
albinopapa
Posts: 3790
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Unusual behavior...for me.

Post by albinopapa » July 24th, 2019, 1:51 am

I decided to take a break from game-centric programming and try my hand at some Win32 stuffs. I've messed around before with some success and have never run into an issue quite like what I'm currently experiencing.

In WinMain I'm trying to create a window. I have my WNDCLASSEX structure filled out and registered with RegisterClassEx and I get the ATOM that the function returns just fine. I go to call CreateWindowEx() using the same constexpr const char* string for lpszclassname that I used for the WNDCLASSEX structure that I registered and I get error number 1407 "Cannot find window class".

I do a search and this seems to happen if the string is a temporary, but I've never had issues with this before. I thought string literals were stored in the program's data section same as global static variables. After commenting some things out and thinking the issue was invalid arguments or an incorrect HINSTANCE, I tried just using the string literal directly and this worked. Not sure what the difference is. If the string is still around then what should it matter what the address is?

Ok, figured it out. The string you use in the WNDCLASSEX struct must have same address as the one you use for the CreateWindowEx() call. So, it's not the string that matters, but the same address. Dang, all these years and not running into that issue by luck. Damn that was frustrating.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 3790
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Unusual behavior...for me.

Post by albinopapa » July 24th, 2019, 1:53 am

The only reason I was doing this was because I want to have different Window classes, one for the main "parent" window and one for the child windows like buttons and text boxes. The parent window will use the WNDCLASSEX to get registered with the system, but child windows don't have to do that, so I thought I'd take the registration of a window outside the creation ( constructor or Initialize function ) of a Window class since not all Windows would need to register.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3834
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Unusual behavior...for me.

Post by chili » July 24th, 2019, 1:13 pm

albinopapa wrote:
July 24th, 2019, 1:51 am
Ok, figured it out. The string you use in the WNDCLASSEX struct must have same address as the one you use for the CreateWindowEx() call. So, it's not the string that matters, but the same address. Dang, all these years and not running into that issue by luck. Damn that was frustrating.
This seems insane to me :lol:
Chili

albinopapa
Posts: 3790
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Unusual behavior...for me.

Post by albinopapa » July 24th, 2019, 5:31 pm

I agree, because the same string literal for both should work as well. Nevertheless, no matter what else I tried didn't work. The only thing that worked was using the same variable or string literal for both registering the WNDCLASSEX structure and the call to CreateWindowEx(). I'm guessing the compiler sees that the two string literals are the same and just uses the same static address for both.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3834
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Unusual behavior...for me.

Post by chili » July 27th, 2019, 8:32 am

Well either way, good piece of trivia to know. Might come in handy someday, so thanks for sharing :)
Chili

Post Reply