InPtr In Declare?

I’m trying to pass a hex value of &hC017 to a Windows declare that accepts an InPtr.

FindWindowEx(IntPtr.Zero, IntPtr.Zero, (IntPtr)0xC017, null)

I’ve tried various ways with a MemoryBlock and a Pointer with no success.

How do I accomplish this in Xojo?

FindWindowEx(0, 0, (IntPtr)0xC017, "")

@

Make a declare with integer as type and pass it with &h notation.

Thanks. I tried declaring it as UInt32 and doing this:

dim n as integer n = Ctype(&hC017, UInt32) Call FindWindowEx(0, 0, n, "")

I guess I was close.

Hmmm still doesn’t work. This is what you meant?

[code]
Declare Function FindWindowExW Lib “User32” (hwndParent As Integer, hwndChildAfter As Integer, lpszClass As Integer, lpszWindow As WString) As Integer

dim n as integer = &hC017
Dim handle As Integer
handle = FindWindowExW(0, 0, n, “”)[/code]

@Christian Schmitz

Also wanted to say the example of how to use EnumWindows I found on your site from Aaron Ballman works great and was a real help to me. :slight_smile:

An empty WString is not equal to a null pointer; pass a literal Nil as the last parameter:

handle = FindWindowExW(0, 0, n, Nil)

[quote=395700:@Andrew Lambert]An empty WString is not equal to a null pointer; pass a literal Nil as the last parameter:

handle = FindWindowExW(0, 0, n, Nil)[/quote]

Ahhhh can it really be that easy? Thanks.

[quote=395700:@Andrew Lambert]An empty WString is not equal to a null pointer; pass a literal Nil as the last parameter:

handle = FindWindowExW(0, 0, n, Nil)[/quote]

@Andrew Lambert this indeed solved my issue thanks. I was definitely overthinking it.

[quote=395700:@Andrew Lambert]An empty WString is not equal to a null pointer; pass a literal Nil as the last parameter:

handle = FindWindowExW(0, 0, n, Nil)[/quote]

@Andrew Lambert this little bit of information has opened up a lot for me. I never realized why I couldn’t get some declares working like I wanted. For instance:

  Soft Declare Function FindWindowExW Lib "User32" (hwndParent As Integer, hwndChildAfter As Integer, lpszClass As WString, lpszWindow As WString) As Integer  

By making the params for lpszClass and lpszWindow Variants and passing Nil I can finally loop through all the window handles manually like this:

while (ct < intMax) currChild = FindWindowEx(GetDesktopWindow, prevChild, Nil, Nil) if (currChild = -1) then exit else inthWndCList.Append(currChild) prevChild = currChild ct = ct + 1 end wend

:slight_smile: