Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions

Reply
 
Thread Tools Display Modes
Old 06-19-2018, 12:59 PM   #1
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,192
Default SWS ReaScript: How to pass HWND from Lua to C++: Unknown type HWND

I am trying to convert some basic windows-related C++ functions to Lua API. In particular, GetClientRect, which takes a HWND as argument.

How do I pass a HWND from Lua to a C++ function?

If I declare the function as follows, everything builds OK and and the syntax in the auto-generated API help is also correct.
Code:
bool C_GetClientRect(HWND window, int* widthOut, int* heightOut);
And in ReaScript.cpp:
Code:
APIFUNC(C_GetClientRect), "bool", "HWND,int*,int*", "window,widthOut,heightOut", ...
However, when I try to call this function, I get an error in REAPER: "Unknown type HWND".

I checked whether any other SWS functions take a HWND as parameter, and found two: BR_MIDI_CCLaneRemove and BR_MIDI_CCLaneRemove. Surprisingly, these functions also give the same "unknown type" error.

DarkStar has noticed this error back in 2016: Q4: Lua MIDI functions.
juliansader is offline   Reply With Quote
Old 06-19-2018, 01:45 PM   #2
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,192
Default

I figured out a solution!

Use void* instead of HWND in the parameters, and then cast the argument to HWND inside the function.
juliansader is offline   Reply With Quote
Old 06-19-2018, 02:32 PM   #3
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,298
Default

The type cast is not necessary: the argument can be kept as HWND in the C++ code. As long as it's exposed to REAPER as void* in ReaScript.cpp it should work the same (because the auto-generated reascript_vararg.h does the cast anyway).

Another bug with HWND in extension APIs is that returning one always gives 0. For the FXChain window APIs I created a custom type (FXChain as an alias of HWND__) to work around this while attempting to keep type checks (it turns out REAPER doesn't seem to type check custom types – it's possible to pass a MediaTrack* just like with void*).

The BR_MIDI_CCLaneReplace and BR_MIDI_CCLaneRemove functions were broken in this commit: https://github.com/reaper-oss/sws/co...a4e4084ddeL149.

I think the best solution would be for REAPER to support HWND for extension APIs.

Last edited by cfillion; 06-19-2018 at 03:48 PM.
cfillion is online now   Reply With Quote
Old 08-20-2018, 01:37 AM   #4
doppelganger
Human being with feelings
 
Join Date: Feb 2017
Posts: 282
Default

Hi juliansader, your private messages box is hidden, so i will ask here:

how to use your Window_ListFind/Window_ListAllTop, etc?
I'm trying to get all opened Parameter modulation windows.

that's what i tried:
listfind = reaper.Window_ListFind("Parameter modulation", false, "anysectn", "anykey")
> nil

listalltop = reaper.Window_ListAllTop("anysectn","anykey")
> nil

findwnd = reaper.Window_Find("Parameter modulation", false)
finds only 1 window

findchild = reaper.Window_FindChild(reaper.GetMainHwnd(), "Parameter modulation", false)
> nil

If your functions work, i'll remove my 2 from pull requests.

Last edited by doppelganger; 08-20-2018 at 01:45 AM.
doppelganger is offline   Reply With Quote
Old 08-20-2018, 02:17 AM   #5
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,192
Default

Quote:
Originally Posted by doppelganger View Post
Hi juliansader, your private messages box is hidden, so i will ask here:
Could you please check again and let me know what is hidden? I regularly receive PMs, so AFAIK my PM box is available, but if anything is hidden, I need to unhide it.


Quote:
how to use your Window_ListFind/Window_ListAllTop, etc?
I'm trying to get all opened Parameter modulation windows.

that's what i tried:
listfind = reaper.Window_ListFind("Parameter modulation", false, "anysectn", "anykey")
> nil
To retrieve the list, you must use reaper.GetExtState("anysectn", "anykey").

Since the returned list may be much longer than the limit of API return strings (1024 characters), the function places the list in an ExtState.

Once you have retrieved the ExtState, you can use Window_HandleFromAddress to transform the addresses into REAPER objects:
Code:
t = {} -- table to store all the handles
for address in list:gmatch("%w+") do
    address = tonumber(address)
    t[#t+1] = reaper.Window_HandleFromAddress(address&0xFFFFFFFF, address>>32)
end
juliansader is offline   Reply With Quote
Old 08-20-2018, 02:29 AM   #6
doppelganger
Human being with feelings
 
Join Date: Feb 2017
Posts: 282
Default

Quote:
Originally Posted by juliansader View Post
Could you please check again and let me know what is hidden? I regularly receive PMs, so AFAIK my PM box is available, but if anything is hidden, I need to unhide it.
i see only your statistics tab, no contact info tab,
also i see on the header "send message" button, but when i click on it, nothing happens.

Quote:
Originally Posted by juliansader View Post
Window_HandleFromAddress
i got to the point with GetExtState, but didn't knew how to deal with adresses, now i can see, i will try. Thank You!
doppelganger is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:16 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.