About Monkey 2 › Forums › Monkey 2 Programming Help › Can't compile simple WinApi call
This topic contains 8 replies, has 2 voices, and was last updated by
Mark Sibly
1 year, 8 months ago.
-
AuthorPosts
-
August 15, 2017 at 10:35 am #9836
I’m trying to get this to compile, but get :
C:/Monkey2-v1.1.06/tmp/untitled2.buildv1.1.06/windows_debug/src/untitled2_untitled2.cpp:19:3: error: ‘WINRECT__’ was not declared in this scope
WINRECT__* l_parentrect{};
^~~~~~~~~
C:/Monkey2-v1.1.06/tmp/untitled2.buildv1.1.06/windows_debug/src/untitled2_untitled2.cpp:19:14: error: ‘l_parentrect’ was not declared in this scope
WINRECT__* l_parentrect{};
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546#Import "<libuser32.a>"#Import "<std>"#Import "<windows.h>"#Import "<std>"#Import "<mojo>"Using mojo..Using std..ExternAlias LPCTSTR:CStringStruct HWND__EndAlias HWND:HWND__ PtrStruct WINRECT__Field left:IntField top:IntField right:IntField bottom:IntEndAlias LPRECT:WINRECT__ PtrExternFunction GetClientRect:Bool(in:HWND,out:LPRECT)Function GetCommandLineW:LPCTSTR()Function MessageBoxA:Int (hWnd:HWND, lpText:CString, lpCaption:CString, uType:Int)PublicFunction Main()Local phwnd:HWND ' dummyLocal parentrect:LPRECTGetClientRect(phwnd, parentrect)EndAugust 16, 2017 at 5:57 am #9850Never heard of struct WINDRECT__ before – try plain old RECT instead, works fine here:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx
Possibly time to start a win32 module?
August 16, 2017 at 6:19 am #9851I just called it something, does the naming of the struct matter?
A Win32 module seems like a good idea.
August 16, 2017 at 6:36 am #9853[EDIT]
Got it compiling by using RECT (no underscores), don’t know why though. I’m thinking the struct needs to match the naming in windows.h or… ?
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344#Import "<libuser32.a>"#Import "<std>"#Import "<windows.h>"#Import "<std>"#Import "<mojo>"Using mojo..Using std..ExternAlias LPCTSTR:CStringStruct HWND__EndAlias HWND:HWND__ PtrStruct RECTField left:LONGField top:LONGField right:LONGField bottom:LONGEndFunction GetClientRect:Bool(in:HWND,out:RECT Ptr)Function GetCommandLineW:LPCTSTR()Function MessageBoxA:Int (hWnd:HWND, lpText:CString, lpCaption:CString, uType:Int)PublicFunction Main()Local phwnd:HWND ' dummyLocal parentrect:RECTGetClientRect(phwnd, Varptr parentrect)EndAugust 16, 2017 at 7:36 am #9858I’m thinking the struct needs to match the naming in windows.h or… ?
Yes, defnitely, that’s why WINRECT__ didn’t work, there’s no such thing in windows.h.
So yes, the naming is important, the compiler has to be able to find the definition of struct RECT or whatever it is somewhere.
August 16, 2017 at 8:36 am #9860ok, thanks got it now.
I don’t get why some things are written:
Struct HWND__
End
Alias HWND:HWND__ Ptrand some
struct RECT
and where to look it up though.
August 16, 2017 at 3:52 pm #9868> I don’t get why some things are written:
Mainly because this is how it’s written in the .h files, ie: the equivalent ‘c’ is probably something like:
Monkey1234567struct HWND__{};typdef HWND__ *HWND;typedef struct _RECT{DWORD l,t,r,b; //no idea about this actually...}RECT;It’s wildly inconsistent, but that’s how windows is written and it has it’s own sort of logic.
The goal here is to come up with monkey2 code that matches the meaning of the actual ‘c’ code in windows.h so the compiler accepts the output monkey code.
Where to look it all up is a bit tricky. Header files are a good start, and googling ‘msdn HWND’ etc still works pretty well a lot of the time. I should be able to do most the HWND etc type stuff myself, and after that it’s just a matter of entering the APIs.
This is kind of one level of abstraction away from how blitzmax worked, where you had to declare structs very precisely so that struct byte sizes and field offsets were exactly right or all hell would break lose at the binary level. With monkey2, you really just have to get types and names right or things break at the compiler level instead!
August 17, 2017 at 6:40 am #9879Thanks for explaing. I see now that I need only write the names of constants, and then the values are automaticly picked up, very handy like in:
Const WS_CHILD:Int
August 17, 2017 at 6:52 am #9882Yes, the values of these consts are already defined in windows.h!
-
AuthorPosts
You must be logged in to reply to this topic.