My first question: Is it possible to access the Windows API / Windows DLLs directly from Haxe?
.. As for c++ magic, I started to play around with @:headerCode, @:functionCode and the Windows API. I wanted to see if and how I could get some of the Windows functions to work. I began at first with just trying 'untyped MessageBox()', like in one of the above linked articles. Then I moved onto
FindWindow(). With Notepad open I was able to successfully find the window:
@:headerCode("#include <windows.h>")
class Main {
static function main() {
var hwnd = untyped FindWindow(0, "Untitled - Notepad");
trace(hwnd);
}
}
Here, 'hwnd' returns true if Notepad is open and false if Notepad is not open.
I was not expecting true or false. I imagined the actual window handle (of which I believe is a pointer value) to be returned (because Haxe is magic!). And this is where I am now stuck. I've tried several of the cpp.Pointer methods hoping they would return the actual value. Most return errors during compilation. My first thought was that cpp.Pointer.fromHandle() would work, but instead of returning an error, it successfully compiles and returns
from 'trace(cpp.Pointer.fromHandle(hwnd));'
So far, I've only been able to get the value to display with @:functionCode and writing it all in C. Of course, I still can't pass back the hwnd value, though.
@:headerCode("#include <windows.h>")
class Main {
static function main() {
var num = printMe();
trace("\n" + num);
}
@:functionCode('
HWND h;
h = FindWindow(0, "Untitled - Notepad");
printf("%p", h);
return h;
')
static function printMe(): Dynamic {
return 0;
}
}
In the above code, the pointer value gets printed from the printf() function, but trace("\n" + num); just returns 'true'.
So.... first is it possible to access the Windows API (or Windows DLLs) directly from Haxe?
And second, using c++ magic is there just no HWND type that maps to the Haxe cpp API?
Thanks!