WindowHandle is an opaque pointer on Windows, that you just need to pass around. You're not supposed to "use" (dereference) it. Can you show your code?
Here it is (http://mjonir.gantzotaku.com/danmagine/download.php?file=SFMLua-src.zip), it's a complete WIP though :)
See commented lines at binding/lua_registration_SFML_window.cpp:123, 126 and 146. I'm not sure what happens behind this though, it's all deep magic for me. If it helps, compiler errors on that line:
template <class T>
class_id const registered_class<T>::id = allocate_class_id(typeid(T));
With T = HWND__ I think. It looks like luabind needs to know.
Why don't you use a wrapper library such as luabind, which allows you to declare the binding in a very simple way?
I'm actually using luabind! :)
luabind v0.9.1 (latest) doesn't allow default values for parameters (was apparently scheduled for v1, but the project is not really maintained anymore). I've Googled it and the only solution seems to be function overloading.
Forget what I said about public inheritance though, I realized that in this case (since I'm not accessing anything private) I can just make static functions for each overload that accept a pointer to that SFML class and then bind them as if they came from the class. It'll be cleaner and easier even if not ideal. Still need to implement all these overloads though ^^'
Other problems I encountered with luabind were:
- No support for class attributes, I will probably have to wrap them all in static member functions. Maybe I can inject them again in their classes as attributes once luabind has finished.
- No support for operator[], which is really annoying! I think I'll just bind it to the __call metamethod in Lua, which is the equivalent of operator(), for the moment. Perhaps I can find a workaround using the Lua C API or something on the Lua side, I don't know yet :(
Yay, I finally found out what makes it work! It took me hours of testing to isolate the cause as the behaviour seemed totally random.
To sum it up:
- In general, no matter how I did it, compilation will crash when binding something with sf::WindowHandle, the trick mentioned in the link didn't seem to work.
- It turns out that by great luck, I tried binding the window in a file that included "Window.h" for completely unrelated reasons, and it worked!
- I put everything back how it was and just included "Windows.h" in the file for window binding, and it worked as well.
To have it work in Lua, I also had to bind this:
luabind::scope register_WindowHandle()
{
#ifdef BUILD_WINDOWS
return
class_<HWND__>("HWND__")
;
#endif
}
and NOT sf::WindowHandle.
Here are updated, working sources: Download link (http://mjonir.gantzotaku.com/danmagine/download.php?file=SFMLua-src2.zip)
(By the way main.cpp in the previous archive was obviously the wrong one, sorry for that ^^')
Window executable demo (http://mjonir.gantzotaku.com/danmagine/download.php?file=SFMLuademo.zip) using the handle at main.lua:21 and 22. The window "stops responding" however, not sure if that's normal behaviour or not as I've never played with these functions before.
It's really annoying that I'd have to make the binding OS-specific though, and it looks like it's going to bring lots of problems. Maybe it's better if I left it out of the binding, or only include it with a compilation option? :/