About Monkey 2 › Forums › Monkey 2 Programming Help › Load 3d library in monkey 2
This topic contains 15 replies, has 3 voices, and was last updated by Yue 4 weeks, 1 day ago.
-
AuthorPosts
-
January 31, 2019 at 6:20 pm #16028
Yue
ParticipantHello, What is the equivalent in Monkey 2 to do the following that I do in BlitzMax?
BlitzMax
Monkey
123456Global MyLibrary:Int = LoadLibraryA("Gear3D.dll")Local SetGraphics3D(alto:Int, ancho:Int) = GetProcAddress(MyLibrary,"_SetGraphics3D@4")SetGraphics3D(1024,768)Monkey 2?
February 1, 2019 at 1:00 am #16029
scurty
ParticipantThat’s actually a very good question, not sure how this would be done in Monkey2. I think you would need to make a Monkey2 module that wraps Gear3D as of now. Any other comments?
February 1, 2019 at 4:56 am #16030
Danilo
ParticipantFirst you need to import “<win32>”, that imports the file /modules/win32/win32.monkey2
LoadLibrary and GetProcAddress are not imported yet, so you need to add it. LoadLibraryA uses ASCII chars, so better use LoadLibraryW for wide chars (Unicode).
Monkey
12345678910111213141516171819202122232425#Import "<win32>"ExternAlias FARPROC:Void PtrLoadLibraryW:win32.HMODULE( lpLibFileName:WString )GetProcAddress:FARPROC( hModule:win32.HMODULE, lpProcName:WString )PublicUsing win32..Global MyLibrary:HMODULEFunction Main()MyLibrary = LoadLibraryW("Gear3D.dll")Local SetGraphics3D(alto:Int, ancho:Int) = GetProcAddress(MyLibrary,"_SetGraphics3D@4")SetGraphics3D(1024,768)EndIf LoadLibrary() and GetProcAddress() get added to the win32 import, you could remove the ‘Extern’ section.
Of course untested, but that’s the general way how it would work with dynamic loading of DLL functions at runtime.
If you have a DLL import file (.lib), you could directly import it. If the DLL uses ASCII strings, a conversion from Unicode to ASCII would be required for the strings.If you have a Unicode version of the .dll you would use this.
February 1, 2019 at 9:31 pm #16033
Yue
ParticipantIt’s not working. Some expert, if you want I can compile a simple library that returns a number for a simple test.
?
February 3, 2019 at 5:53 pm #16038
Danilo
ParticipantShouldn’t be a problem. ? Please give download links for test lib and latest gear3d.
February 3, 2019 at 11:33 pm #16040
Yue
ParticipantOk, ?
Here download.
Gear3D.dll
Link.dllLoad Gear3d.dll
Functions on lib.“_InitG3D” ( 2 variables, height, widht secreen)
“_SetAppTitle” ( 1 variable string App Title)
“_RenderStage” ( Not Variables)
“_FlipStage”) ( Not Variables )Thanks You. ?
February 4, 2019 at 5:08 am #16041
Danilo
Participant- Is Gear3D compiled for 32bit or 64bit?
- Ascii or Unicode?
-
What type are the function parameters?
- InitG3D( Byte, Byte )
- InitG3D( Word, Word )
- InitG3D( Int, Int ) ?
February 4, 2019 at 5:18 am #16042
Yue
ParticipantI’ve made it work in BlitzMax NG, but I can’t in Monkey 2, because everything is more confusing and I don’t consider myself a programmer.
InitG3D(int,int)
for 32 bits.
Ascii or Unicode.Monkey
12345678910111213141516Framework iris3dgames.gear3dImport brl.basic' Main FileLocal App:TApp = TApp.InitG3D()RepeatApp.RenderStage()App.FlipStage()ForeverMonkey
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849'********************************************************'# Module : Gear3D for Windows #'# Url : http://www.iris3dgames.ga #'# Programmer : Yue Rexie #'# Compiler : BlitzMax NG - http://www.blitzMax.org #'# #'#*******************************************************SuperStrictModule iris3dgames.gear3dModuleInfo "Name :Gear3D For Windows"ModuleInfo "Versión : 0.0 Alpha"ModuleInfo "Copyright: LGPL. Iris3D Games"ModuleInfo "URL: http://www.iris3dgames.ga"Import pub.win32Local lib:Byte Ptr = LoadLibraryW("Gear3D.dll")Global _InitG3D:Byte Ptr(alto%,ancho%) "win32"Global _SetAppTitle:Byte Ptr(titulo$z) "win32"Global _RenderStage:Byte Ptr() "win32"Global _FlipStage:Byte Ptr() "win32"If lib% Then_InitG3D% = GetProcAddress(lib,"_InitG3D")_SetAppTitle% = GetProcAddress(lib,"_SetAppTitle")_RenderStage% = GetProcAddress(lib,"_RenderStage")_FlipStage% = GetProcAddress(lib,"_FlipStage")ElseRuntimeError("Invalid Load lib!")End If' Includes.Include "Types\TApp.bmx"February 4, 2019 at 5:29 am #16043
Yue
ParticipantHere result.
February 4, 2019 at 7:51 am #16044
Danilo
ParticipantThat GetProcAddress() method brings up some casting issues,
so it is probably easier to import a “Gear3D.lib” (DLL import).
I made a quick test using LoadLibrary and GetProcAddress in a C++ file. File is attached.
Compile it and put Gear3D.dll and Link.dll in Gear3D.products/Windows/ folder, so Gear3D.exe can find the DLLs.
Attachments:
- Gear3D.zip
February 4, 2019 at 12:15 pm #16046
Yue
ParticipantIn monkey 2 everything is very different, but I can’t make it work. I wonder what the downside will be.
February 4, 2019 at 12:20 pm #16047
Yue
ParticipantOk, this already works, when translating my lack of attention I haven’t noticed where to put the libraries correctly.
So I already have something to investigate, by the way I did not know how to stop the application, so it touched me to close moneky 2, and when I return from work I give it a deep look. Now I have some motivation to investigate with Monkey 2.
Thank you very much.
February 4, 2019 at 3:06 pm #16048
Danilo
Participantby the way I did not know how to stop the application
I put a counter 0 to 1001 in the code, otherwise it would Repeat..Forever.
The window title counts to 1001 and quits.February 4, 2019 at 11:43 pm #16049
Yue
ParticipantNo, at the moment there is no way out of the application, I only have those functions, I regret the drawbacks, in blitzmax ng the output is through the interfaces of the code writing ide.
If I can make this work I’m going to put more commands to the library and possibly be another alternative especially for BlitzMax NG and why not, for Monkey2.
One question that I still have to answer is that these are casting errors? When I was compiling in BlitzMax and switching to BlitzMax NG, I had some strange problems, so I have to modify certain points when exporting the library for NG. In such a case if that is corrected, is it possible to load the library in Monkey 2 without creating .h and C files?
Translated with http://www.DeepL.com/Translator
February 6, 2019 at 5:24 am #16054
Danilo
Participant> is it possible to load the library in Monkey 2 without creating .h and C files?
Monkey2 is a little bit different because it translates to C++.
When you import something, you need to tell Monkey2 and the C++ compiler about that stuff.
If you don’t tell Monkey2, it does not know the functions.
If you don’t tell C++, it does not know the functions and you will get an error.So you need at least the Monkey2 ‘Extern’ import section and the C/C++ header with the functions/classes.
-
AuthorPosts
You must be logged in to reply to this topic.