Even if in this case I prefer netmaestro's suggestion, this is another possible approach which could be useful in other cases.
I'll use the image example anyway to make it more easily comparable.
In the above the image is created in the DLL and then re-created from the encoded data format in the client, in the following the image is created directly in the client instead, by passing the address of an helper client function to the DLL.
Code: Select all
Prototype.i CreateImageClient(n, w, h, depth, back)
Global CreateImageClient.CreateImageClient
Structure DLL_INIT
CreateImageClient.i
EndStructure
ProcedureDLL.i ReturnImage (w, h, depth, backcolor)
Protected r, img = CreateImageClient(#PB_Any, w, h, depth, backcolor)
StartDrawing(ImageOutput(img))
If w > h
r = h /2
Else
r = w /2
EndIf
Circle(w/2, h/2, r, #White)
StopDrawing()
ProcedureReturn img
EndProcedure
ProcedureDLL InitDLL (*init.DLL_INIT)
CreateImageClient = *init\CreateImageClient
EndProcedure
Code: Select all
Structure DLL_INIT ; this way you can communicate further stuff to the dll if required
CreateImageClient.i
EndStructure : Global DI.DLL_INIT
Prototype ReturnImage(w,h,d,bkg)
Prototype InitDLL (*init.DLL_INIT)
Procedure.i CreateImageClient (n, w, h, depth, back)
ProcedureReturn CreateImage (n, w, h, depth, back)
EndProcedure
OpenLibrary(0, "dll.dll")
Global ReturnImage.ReturnImage = GetFunction(0, "ReturnImage")
Global InitDLL.InitDLL = GetFunction(0, "InitDLL")
DI\CreateImageClient = @CreateImageClient()
InitDLL(@DI)
Define img = ReturnImage(256,256,24,#Red)
OpenWindow(0,0,0,ImageWidth(img),ImageHeight(img),"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,0,0,ImageID(img))
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow