Hello,
I am trying new API2, Xojo 3.1, and the declaration of WNDCLASSEX WString works with CStr, but seems to crash without warning on API2? Is there another way of displaying a WString, or just keep wrapping it in a CStr() command?
Here is some example code in an action event:
[code]Sub Action() Handles Action
//Create Declares for C++ code
Declare Function GetClassInfoEx Lib “user32” Alias “GetClassInfoW” (hInstance As Integer, _
lpClassName As Ptr, _
ByRef lpWndClass As WNDCLASSEX) As Boolean
//Create a variable for Structure
Dim WCEx As WNDCLASSEX
//Create a variable for the response
Dim IsSuccessful as Boolean
//Call the function GetClassInfo
//Button is a Wstring and requires a null terminating string
Dim MyClassName as New MemoryBlock(256)
MyClassName.WString(0) = “BUTTON” + Chr(0)
IsSuccessful = GetClassInfoEx(PushButton1.Handle, MyClassName, WCEx)
Label1.Value = "IsSuccessful = " + Cstr(IsSuccessful) + EndOfLine +_
"cbSize = " + WCEx.cbSize.ToString + EndOfLine +_
"style = " + WCEx.style.ToString + EndOfLine +_
"lpfnWndProc = " + WCEx.lpfnWndProc.ToString + EndOfLine +_
"cbClsExtra = " + WCEx.cbClsExtra.ToString + EndOfLine +_
"cbWndExtra = " + WCEx.cbWndExtra.ToString + EndOfLine +_
"hInstance = " + WCEx.hInstance.ToString + EndOfLine +_
"hIcon = " + WCEx.hIcon.ToString + EndOfLine +_
"hCursor = " + WCEx.hCursor.ToString + EndOfLine +_
"hbrBackground = " + WCEx.hbrBackground.ToString + EndOfLine +_
"lpszMenuName = " + WCEx.lpszMenuName + EndOfLine +_ //Error Here
"lpszClassName = " + WCEx.lpszClassName + EndOfLine +_ //Error Here
"hIconSm = " + WCEx.hIconSm.ToString
End Sub
[/code]
Here is the structure:
Structure WNDCLASSEX
cbSize as Uint32
style as UInt32
lpfnWndProc as Integer
cbClsExtra as Int32
cbWndExtra as Int32
hInstance as Integer
hIcon as Integer
hCursor as Integer
hbrBackground as Integer
lpszMenuName as WString
lpszClassName as WString
hIconSm as Integer
End Structure
Here is some code that works with wrapping a CStr:
[code]Sub Action() Handles Action
//Create Declares for C++ code
Declare Function GetClassInfoEx Lib “user32” Alias “GetClassInfoW” (hInstance As Integer, _
lpClassName As Ptr, _
ByRef lpWndClass As WNDCLASSEX) As Boolean
//Create a variable for Structure
Dim WCEx As WNDCLASSEX
//Create a variable for the response
Dim IsSuccessful as Boolean
//Call the function GetClassInfo
//Button is a Wstring and requires a null terminating string
Dim MyClassName as New MemoryBlock(256)
MyClassName.WString(0) = “BUTTON” + Chr(0)
IsSuccessful = GetClassInfoEx(PushButton1.Handle, MyClassName, WCEx)
Label1.Value = "IsSuccessful = " + Cstr(IsSuccessful) + EndOfLine +_
"cbSize = " + WCEx.cbSize.ToString + EndOfLine +_
"style = " + WCEx.style.ToString + EndOfLine +_
"lpfnWndProc = " + WCEx.lpfnWndProc.ToString + EndOfLine +_
"cbClsExtra = " + WCEx.cbClsExtra.ToString + EndOfLine +_
"cbWndExtra = " + WCEx.cbWndExtra.ToString + EndOfLine +_
"hInstance = " + WCEx.hInstance.ToString + EndOfLine +_
"hIcon = " + WCEx.hIcon.ToString + EndOfLine +_
"hCursor = " + WCEx.hCursor.ToString + EndOfLine +_
"hbrBackground = " + WCEx.hbrBackground.ToString + EndOfLine +_
"lpszMenuName = " + CStr(WCEx.lpszMenuName) + EndOfLine +_ //<- works
"lpszClassName = " + CStr(WCEx.lpszClassName) + EndOfLine +_ // <- works
"hIconSm = " + WCEx.hIconSm.ToString
End Sub
[/code]
Is this ‘as designed’ or a bug?
Thanks