Need help turning this code into DLL!
Re: Need help turning this code into DLL!
I already asked him if I could use it & he said yes. I read all the copyrights and I respect his privacy. If he tells me I can't, then I won't.
Re: Need help turning this code into DLL!
Guys, for some reason I'm getting:
Code to compile DLL & code to test DLL, below...
Save_X_Mesh.pb:
Compile the above into a DLL using the subsystem: dx9 & the latest version for PB 5.30 of MP3D Library to compile & test if necessary.
Now for example..
Save_X_Mesh_Example.pb:
You don't HAVE to compile it, just trying to find it in the source is help enough for me, thank you.
How to fix? ><
Thanks!
Mythros
Whatever THAT means...Invalid memory access ( write error at address 8 )
Code to compile DLL & code to test DLL, below...
Save_X_Mesh.pb:
Code: Select all
ProcedureDLL Save_X_Mesh(filename.s, entity.i)
Protected.s fipath
Protected.i saved
fipath = (filename)
saved = MP_SaveMesh(fipath, entity)
ProcedureReturn saved
EndProcedureNow for example..
Save_X_Mesh_Example.pb:
Code: Select all
MP_Graphics3D(800, 600, 0, 2)
Global filename.s = GetCurrentDirectory()+"models\dwarf\dwarf1.x"
MessageRequester(Str(FileSize(filename)), Str(FileSize(filename)))
Global entity.i = MP_LoadMesh(filename)
MessageRequester(Str(entity), Str(entity))
Prototype.i ProtoSave_X_Mesh(filename.s, entity.i)
Global library.i = OpenLibrary(#PB_Any, "Save_X_Mesh.dll")
If library
SaveXMesh.ProtoSave_X_Mesh = GetFunction(library, "Save_X_Mesh")
saved.i = CallFunction(library.i, "Save_X_Mesh", @filename.s, @entity.i)
MessageRequester(Str(saved.i), Str(saved.i))
EndIf
While Not MP_KeyDown(1) And Not WindowEvent() = #PB_Event_CloseWindow
MP_RenderWorld()
MP_Flip()
Wend
EndHow to fix? ><
Thanks!
Mythros
Last edited by Mythros on Tue Aug 19, 2014 4:21 pm, edited 1 time in total.
Re: Need help turning this code into DLL!
Can someone please help?
Thank You!
Mythros
Thank You!
Mythros
Re: Need help turning this code into DLL!
You are making several mistakes, Mythros.
First:
The DLL function expects 'entity' to be Integer, and you give a pointer to Integer when calling the function. The '@' (AddressOf) operator is wrong.
Second:
What you try to do is not possible in the way you do it. The EXE and the DLL are two different (separate) things.
They are compiled separately, so they both have their own objects management system included.
The DLL is loaded into the process of the EXE, but the DLL still does not know about the (external)
object system within the EXE.
You load a mesh within the EXE:
Within the DLL, you want to save the same Mesh:
Both are accessing separate object systems. If you load 2 entities within the EXE,
the DLL does not know about this objects.
If you want to do that by using a DLL, you need to put everything into the DLL.
MP3D initialization, mesh loading/creation, and mesh saving.
That's basically what applePi wanted to tell you with his code, where he does everything
within one function:
- MP_Graphics3D
- MP_LoadMesh
- MP_SaveMesh
( - MP_RenderWorld + MP_Flip )
It is the same for other objects. An external DLL has no direct access to the PB object system within the EXE (gadgets/windows/files/...).
First:
Code: Select all
; DLL function:
ProcedureDLL Save_X_Mesh(filename.s, entity.i)
; call:
saved.i = CallFunction(library.i, "Save_X_Mesh", @filename.s, @entity.i)Second:
What you try to do is not possible in the way you do it. The EXE and the DLL are two different (separate) things.
They are compiled separately, so they both have their own objects management system included.
The DLL is loaded into the process of the EXE, but the DLL still does not know about the (external)
object system within the EXE.
You load a mesh within the EXE:
Code: Select all
Global entity.i = MP_LoadMesh(filename)Code: Select all
saved = MP_SaveMesh(fipath, entity)the DLL does not know about this objects.
If you want to do that by using a DLL, you need to put everything into the DLL.
MP3D initialization, mesh loading/creation, and mesh saving.
That's basically what applePi wanted to tell you with his code, where he does everything
within one function:
Put everything into the DLL (so it uses same object space):applePi wrote:Code: Select all
ProcedureDLL Save_X_Mesh(*filename.String) MP_Graphics3D(800, 600, 0, 2) Mesh=MP_CreateCube() fipath.s = (GetCurrentDirectory()+*filename\s) saved.i = MP_SaveMesh(fipath, Mesh) EndProcedure
- MP_Graphics3D
- MP_LoadMesh
- MP_SaveMesh
( - MP_RenderWorld + MP_Flip )
It is the same for other objects. An external DLL has no direct access to the PB object system within the EXE (gadgets/windows/files/...).
Re: Need help turning this code into DLL!
Ok, now it's crashing at this line. I tried my best to follow everything you & Applepi said, Danilo.
Save_X_Mesh.pb:
And...
Here's the Example:
Save_X_Mesh_Example.pb:
Thanks again!
Mythros
Here's the DLL code:If FileSize(*filename\s) = -1: MessageRequester("ERROR!", "MISSING FILE: '"+*filename\s+"'!"): End: EndIf
Save_X_Mesh.pb:
Code: Select all
ProcedureDLL.i Save_X_Mesh(*filename.String)
MessageRequester("Hello from Save_X_Mesh()!", "Hello from Save_X_Mesh()!")
;MP_Graphics3D(0, 0, 0, 2) <!--- Don't want another window popup
Mesh=MP_LoadAnimMesh(*filename\s)
MessageRequester(Str(Mesh), Str(Mesh))
If Mesh = 0
Mesh=MP_LoadMesh(*filename\s)
EndIf
fipath.s = (*filename\s)
saved.i = MP_SaveMesh(*filename\s, Mesh)
MessageRequester(Str(saved), Str(saved))
While Not MP_KeyDown(1) And Not WindowEvent() = #PB_Event_CloseWindow
If Mesh <> 0: Break : EndIf
MP_RenderWorld()
MP_Flip()
Wend
ProcedureReturn saved
EndProcedureHere's the Example:
Save_X_Mesh_Example.pb:
Code: Select all
MP_Graphics3D(800, 600, 0, 2)
*filename.String = @"models\dwarf\dwarf1.x"
If FileSize(*filename\s) = -1: MessageRequester("ERROR!", "MISSING FILE: '"+*filename\s+"'!"): End: EndIf
Prototype.s ProtoSave_X_Mesh(*filename)
Global library.i = OpenLibrary(#PB_Any, "Save_X_Mesh.dll")
If library
SaveXMesh.ProtoSave_X_Mesh = GetFunction(library, "Save_X_Mesh")
CallFunction(library, "Save_X_Mesh", @*filename\s)
EndIf
While Not MP_KeyDown(1) And Not WindowEvent() = #PB_Event_CloseWindow
MP_RenderWorld()
MP_Flip()
Wend
EndMythros
Re: Need help turning this code into DLL!
some notes about your Dll code and its calling program:
1- MP_Graphics3D is necessary inside the DLL, and as Danilo said Put everything into the DLL, the DLL can't know what is the MP_Graphics3D in the exe.
2- MP_LoadAnimMesh return a number more than zero whether it loaded animated or not animated x file, and seems MP_SaveMesh does not work with the mesh loaded by MP_LoadAnimMesh, try different x files and see.
3- not all x models loaded with MP_LoadMesh are saved. but most models in blitz3D folder can be saved except the animated one it will be saved stripped from animation, i have tried the "bones_all.x" from the MP3D demos.
4- to save a model you have already loaded save it with a different name such as "bicycle.xBAK" you can rename it later such as bicycle2.x
here is a working dll and a calling program using your example as a base. i have tried it in PB 5.30 and latest MP3D library.
Dll: compile with dx9 option
calling program:
1- MP_Graphics3D is necessary inside the DLL, and as Danilo said Put everything into the DLL, the DLL can't know what is the MP_Graphics3D in the exe.
2- MP_LoadAnimMesh return a number more than zero whether it loaded animated or not animated x file, and seems MP_SaveMesh does not work with the mesh loaded by MP_LoadAnimMesh, try different x files and see.
3- not all x models loaded with MP_LoadMesh are saved. but most models in blitz3D folder can be saved except the animated one it will be saved stripped from animation, i have tried the "bones_all.x" from the MP3D demos.
4- to save a model you have already loaded save it with a different name such as "bicycle.xBAK" you can rename it later such as bicycle2.x
here is a working dll and a calling program using your example as a base. i have tried it in PB 5.30 and latest MP3D library.
Dll: compile with dx9 option
Code: Select all
ProcedureDLL.i Save_X_Mesh(*filename.String)
MessageRequester("Hello from Save_X_Mesh()!", "Hello from Save_X_Mesh()!")
MP_Graphics3D(0, 0, 0, 2); <!--- Don't want another window popup
fipath.s = (GetCurrentDirectory()+*filename\s)
;Mesh=MP_LoadAnimMesh(fipath)
;MessageRequester(Str(Mesh), Str(Mesh))
;If Mesh = 0
Mesh=MP_LoadMesh(fipath)
;EndIf
saved.i = MP_SaveMesh(fipath+"bak", Mesh)
MessageRequester(Str(saved), Str(saved))
While Not MP_KeyDown(1) And Not WindowEvent() = #PB_Event_CloseWindow
If Mesh <> 0: Break : EndIf
MP_RenderWorld()
MP_Flip()
Wend
ProcedureReturn saved
EndProcedure
Code: Select all
MP_Graphics3D(800, 600, 0, 2)
Define filename.String
filename\s="car.x"
If FileSize(filename\s) = -1: MessageRequester("ERROR" +"MISSING FILE:", filename\s): End: EndIf
;Prototype.s ProtoSave_X_Mesh(*filename)
Global library.i = OpenLibrary(#PB_Any, "Save_X_Mesh.dll")
If library
;SaveXMesh.ProtoSave_X_Mesh = GetFunction(library, "Save_X_Mesh")
CallFunction(Library, "Save_X_Mesh", @filename)
EndIf
While Not MP_KeyDown(1) And Not WindowEvent() = #PB_Event_CloseWindow
MP_RenderWorld()
MP_Flip()
Wend
EndRe: Need help turning this code into DLL!
Hi applepi! Thanks ALOT, it works GREAT! Also, I fixed the popup window problem! I only have one more small question though. How can I save animated X files? Do they have to be binary or text in order to save their animations?
New DLL Code:
Save_X_Mesh.pb:
And...
Example:
Save_X_Mesh_Example.pb:
Thanks again, Applepi! 
Sincerely,
Mythros
New DLL Code:
Save_X_Mesh.pb:
Code: Select all
ProcedureDLL.i Save_X_Mesh(*filename.String)
MessageRequester("Hello from Save_X_Mesh()!", "Hello from Save_X_Mesh()!")
MP_Graphics3DWindow(0, 0, 1, 1 , "Test", #PB_Window_BorderLess)
fipath.s = (GetCurrentDirectory()+*filename\s)
Mesh=MP_LoadAnimMesh(fipath)
saved.i = MP_SaveMesh(fipath+"bak", Mesh)
MP_Close()
MessageRequester(Str(saved), Str(saved))
While Not MP_KeyDown(1) And Not WindowEvent() = #PB_Event_CloseWindow
If Mesh <> 0: Break : EndIf
MP_RenderWorld()
MP_Flip()
Wend
ProcedureReturn saved
EndProcedureExample:
Save_X_Mesh_Example.pb:
Code: Select all
MP_Graphics3D(800, 600, 0, 2)
Define filename.String
filename\s="models\dwarf\dwarf1.x"
If FileSize(filename\s) = -1: MessageRequester("ERROR" +"MISSING FILE:", filename\s): End: EndIf
;Prototype.s ProtoSave_X_Mesh(*filename)
Global library.i = OpenLibrary(#PB_Any, "Save_X_Mesh.dll")
If library
;SaveXMesh.ProtoSave_X_Mesh = GetFunction(library, "Save_X_Mesh")
CallFunction(Library, "Save_X_Mesh", @filename)
EndIf
While Not MP_KeyDown(1) And Not WindowEvent() = #PB_Event_CloseWindow
MP_RenderWorld()
MP_Flip()
Wend
EndSincerely,
Mythros
Re: Need help turning this code into DLL!
sorry Mythros it seems MP_LoadAnimMesh does not work with MP_SaveMesh, it loads the animated x file but MP_SaveMesh can't save it, it is not a Dll issue, a proof here is an animated robot running around a teapot i have posted 2 years ago in MP3D forum, the robot is loaded with MP_LoadAnimMesh, but can't be saved.
regarding a text or binary files, i have tried a 3 animated x files i have it is a text files and not binary. i doubts it will work if it is binary, try to find a binary file and use my attached program to see if it is saved or not.
only Michael (MPZ) have an answer.
click on the second download button at the bottom and not the big one, works okay with pb 5.30 and the latest MP3D
http://www.2shared.com/file/shAQVFc7/robot_mp3d.html
regarding a text or binary files, i have tried a 3 animated x files i have it is a text files and not binary. i doubts it will work if it is binary, try to find a binary file and use my attached program to see if it is saved or not.
only Michael (MPZ) have an answer.
click on the second download button at the bottom and not the big one, works okay with pb 5.30 and the latest MP3D
http://www.2shared.com/file/shAQVFc7/robot_mp3d.html

