Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Developer Forum

Thread Tools Display Modes
Old 06-19-2018, 12:59 PM   #1
Human being with feelings
Join Date: Jul 2009
Posts: 1,853
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.
bool C_GetClientRect(HWND window, int* widthOut, int* heightOut);
And in ReaScript.cpp:
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 online now   Reply With Quote
Old 06-19-2018, 01:45 PM   #2
Human being with feelings
Join Date: Jul 2009
Posts: 1,853

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 online now   Reply With Quote
Old 06-19-2018, 02:32 PM   #3
Human being with feelings
cfillion's Avatar
Join Date: May 2015
Location: Québec, Canada
Posts: 1,943

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 offline   Reply With Quote

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 07:44 PM.

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