Re: Need help turning this code into DLL!
Posted: Mon Aug 18, 2014 9:52 pm
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.
http://www.purebasic.com
https://www.purebasic.fr/english/
Whatever THAT means...Invalid memory access ( write error at address 8 )
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
EndProcedureCode: 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
EndCode: 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)Code: Select all
Global entity.i = MP_LoadMesh(filename)Code: Select all
saved = MP_SaveMesh(fipath, entity)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
Here's the DLL code:If FileSize(*filename\s) = -1: MessageRequester("ERROR!", "MISSING FILE: '"+*filename\s+"'!"): End: EndIf
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
EndProcedureCode: 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
EndCode: 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
EndCode: 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
EndProcedureCode: 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
End