79115409

Date: 2024-10-22 18:51:51
Score: 0.5
Natty:
Report link

Since WNDCLASSEX.lpszMenuName and WNDCLASSEX.lpszClassName are members of a struct, marshalling rules for strings in a struct apply here. Since you didn't specify any such rule for the struct, the default rule applies. From the documentation https://learn.microsoft.com/en-us/dotnet/standard/native-interop/customize-struct-marshalling#customizing-string-field-marshalling:

By default, .NET marshals a string as a pointer to a null-terminated string. The encoding depends on the value of the StructLayoutAttribute.CharSet field in the System.Runtime.InteropServices.StructLayoutAttribute. If no attribute is specified, the encoding defaults to an ANSI encoding.

So, basically the strings in your WNDCLASSEX struct are marshalled as pointers to ANSI strings. But you call the Unicode version of the RegisterClassEx WINAPI, which is expecting pointers to wide/Unicode strings. Kaboom!

Set the CharSet parameter of the WNDCLASSEX [StructLayout] attribute to Unicode to address this particular bug in your code. I don't know if there are further issues lurking in your code, but this one was relatively easy for me to spot...

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: ZippydiZip