Hi IanM, (and / or anyone else who can help clarify)
Have re-read a number of often contradictory and confusing threads on this topic.
When I am creating a DBPro plugin command in PureBASIC with a ProcedureCDLL.l, I know most of the stuff around this.
I just want to check and double check the form of the ProcedureCDLL.l that is returning a string... so apologies in advance for these questions - it may be it would be simplest if you could just post the right way to do it all in one set of purebasic code...
1. Does the ProcedureReturn variable have to have been declared as a global variable outside the Procedure to start with? What about the temporary or temp.l within
2. Assuming say the ProcedureCDLL.l starts with "ProcedureCDLL.l UsefulFunction(OldString.l,Parameter1.l,Parameter2.l)", is it correct to follow with:-
If OldString <> 0
CallCFunctionFast( *GlobPtr\CreateDeleteString, OldString , 0 )
EndIf
or with (note the ommission of the '\'):-
If OldString <> 0
CallCFunctionFast( *GlobPtrCreateDeleteString, OldString , 0 )
EndIf
3. If you're ending with:-
CallCFunctionFast(*GlobPtr\CreateDeleteString, @temp.l , Len( result ) + 1 )
PokeS( temp , result )
ProcedureReturn temp
EndProcedure
Is that correct? Should you omit the '\'? would you be declaring the temp variable and the result variable outside the Procedures as global??
4. Could you give me the latest and greatest version of all the globstruct code incl the constructor and destructor etc?
5. Do you need to create separate procedures for things like CreateDeleteString or is it enough that they are simply within the GlobStruct?
6. What is wrong with the attached? (if anything) (I've changed IsFunction to GetFunction which I believe is the new Purebasic equivalent...)
; needed Structures
Structure GlobChecklistStruct
dwStringSize.l : string.s
valuea.l : valueb.l : valuec.l : valued.l
fvaluea.f : fvalueb.f : fvaluec.f : fvalued.f
EndStructure
; Global DarkBasic Professional internal structure.
Structure GlobStruct
; Function Ptrs (For remote DLLs)
CreateDeleteString.l : ProcessMessageFunction.l : PrintStringFunction.l
UpdateFilenameFromVirtualTable.l : Decrypt.l : Encrypt.l
ChangeMouseFunction.l
SpareFunction1.l : SpareFunction2.l : SpareFunction3.l
; LEEMOD - 130604 - Access To ALL VARIABLES MEMORY
g_pVariableSpace.l
; LEEMOD - 150803 - Replace 'SpareFunction5' with 'g_pErrorHandler'
g_pErrorHandlerRef.l
; DLL Handles And Active Flags
g_GFX.l : g_Text.l : g_Basic2D.l : g_Sprites.l : g_Image.l
g_Input.l : g_System.l : g_File.l : g_FTP.l : g_Memblocks.l
g_Bitmap.l : g_Animation.l : g_Multiplayer.l : g_Basic3D.l : g_Camera3D.l
g_Matrix3D.l : g_Light3D.l : g_World3D.l : g_Particles.l : g_PrimObject.l
g_Vectors.l : g_XObject.l : g_3DSObject.l : g_MDLObject.l : g_MD2Object.l
g_MD3Object.l : g_Sound.l : g_Music.l : g_LODTerrain.l : g_Q2BSP.l
g_OwnBSP.l : g_BSPCompiler.l : g_CSG.l
g_igLoader.l : g_GameFX.l : g_Spare03.l : g_Spare04.l : g_Spare05.l
g_Spare06.l : g_Spare07.l : g_Spare08.l : g_Spare09.l : g_Spare10.l
g_Spare11.l : g_Spare12.l : g_Spare13.l : g_Spare14.l : g_Spare15.l
g_Spare16.l : g_Spare17.l : g_Spare18.l : g_Spare19.l : g_Spare20.l
g_GFXmade.b : g_Textmade.b : g_Basic2Dmade.b : g_Spritesmade.b : g_Imagemade.b
g_Inputmade.b : g_Systemmade.b : g_Filemade.b : g_FTPmade.b : g_Memblocksmade.b
g_Bitmapmade.b : g_Animationmade.b : g_Multiplayermade.b : g_Basic3Dmade.b : g_Camera3Dmade.b
g_Matrix3Dmade.b : g_Light3Dmade.b : g_World3Dmade.b : g_Particlesmade.b : g_PrimObjectmade.b
g_Vectorsmade.b : g_XObjectmade.b : g_3DSObjectmade.b : g_MDLObjectmade.b : g_MD2Objectmade.b
g_MD3Objectmade.b : g_Soundmade.b : g_Musicmade.b : g_LODTerrainmade.b : g_Q2BSPmade.b
g_OwnBSPmade.b : g_BSPCompilermade.b : g_CSGmade.b
g_igLoadermade.b : g_GameFXmade.b : g_Spare03made.b : g_Spare04made.b : g_Spare05made.b
g_Spare06made.b : g_Spare07made.b : g_Spare08made.b : g_Spare09made.b : g_Spare10made.b
g_Spare11made.b : g_Spare12made.b : g_Spare13made.b : g_Spare14made.b : g_Spare15made.b
g_Spare16made.b : g_Spare17made.b : g_Spare18made.b : g_Spare19made.b : g_Spare20made.b
; Executable Media Handlng Data
pEXEUnpackDirectory.b[260]
dwEncryptionUniqueKey.l : ppEXEAbsFilename.l
; LEEMOD - 200105 - Replace 'dwEMHDSpare2' with 'dwInternalFunctionCode'
dwInternalFunctionCode.l
dwEMHDSpare3.l : dwEMHDSpare4.l : dwEMHDSpare5.l
; Windows General Data
HWND.l : HINSTANCE.l
pWindowsTextEntry.l : bInvalidFlag.b : dwWindowWidth.l : dwWindowHeight.l
hAppIcon.l : dwAppDisplayModeUsing.l : dwWindowX.l : dwWindowY.l
hwndIGLoader.l : dwWGDSpare2.l : dwWGDSpare3.l : dwWGDSpare4.l : dwWGDSpare5.l
; Windows Mouse Data
bWindowsMouseVisible.l : iWindowsMouseX.l : iWindowsMouseY.l : iWindowsMouseClick.l
dwWMDSpare2.l : dwWMDSpare3.l : dwWMDSpare4.l : dwWMDSpare5.l
; Main Screen Data (backbuffer)
iScreenWidth.l : iScreenHeight.l : iScreenDepth.l : iNoDrawLeft.l : iNoDrawTop.l
iNoDrawRight.l : iNoDrawBottom.l : dwSafeRectMax.l : pSafeRects.l
dwMSDSpare3.l : dwMSDSpare4.l : dwMSDSpare5.l
; Bitmap And Surface Data (For drawing offscreen)
iCurrentBitmapNumber.l : pCurrentBitmapTexture.l : pCurrentBitmapSurface.l
pHoldBackBufferPtr.l : pHoldDepthBufferPtr.l
dwBSDSpare1.l : dwBSDSpare2.l : dwBSDSpare3.l : dwBSDSpare4.l : dwBSDSpare5.l
; Drawing Data
iCursorX.l : iCursorY.l : dwForeColor.l : dwBackColor.l : dwRenderCameraID.l
fReflectionPlaneX.f : fReflectionPlaneY.f : fReflectionPlaneZ.f
; MIKE - DARKSDK - 2011094
dwCurrentSetCameraID.l
lpDirectXVersionString.l : dw3DBackColor.l : dwDDSpare4.l : dwDDSpare5.l
; Checklist Data
checklistexists.b : checklisthasvalues.b : checklisthasstrings.b : checklistqty.l : dwChecklistArraySize.l
Checklist.GlobChecklistStruct
; Dependent 3D Data Exchange
iFogState.l : dwRedrawPhase.l : dwRedrawCount.l : dwStencilMode.l : dwStencilShadowCount.l
dwStencilReflectionCount.l : dwNumberOfPolygonsDrawn.l : dwNumberOfPrimCalls.l
dwStencilSpare3.l : dwStencilSpare4.l : dwStencilSpare5.l
; System States And Global Controls
bEscapeKeyEnabled.b : bSystemKeyEnabled.b
bSpareBool1.b : bSpareBool2.b : bSpareBool3.b : bSpareBool4.b : bSpareBool5.b
bSpareBool6.b : bSpareBool7.b : bSpareBool8.b : bSpareBool9.b
pExitPromptString.l : pExitPromptString2.l : iSoftwareVP.l
; Dynamic Memory Area For future expansion
dwDynMemSize.l : pDynMemPtr.l
EndStructure
; External Reference To Glob Pointer
Global *GlobPtr.GlobStruct
Structure char ; character structure
a.b
EndStructure
Global Dim DBP_Dependencies.s(1)
Global Dependency.s; Need this in order to return string pointer to DBPro correctly
;
; should I definte global return variables here???
Procedure.l InitialiseCorePtr()
If OpenLibrary( 3 , "DBProCore.dll" )
coreptr_handle.l = GetFunction( 3 , "?GetGlobPtr@@YAKXZ" )
*GlobPtr = CallCFunctionFast( coreptr_handle );
CloseLibrary( 3 );
EndIf
ProcedureReturn *GlobPtr
EndProcedure
ProcedureCDLL AConstructor00YAXXZ()
If *GlobPtr = 0 : InitialiseCorePtr() : EndIf
EndProcedure
; * GET NUMBER OF DEPENDENCIES
; Note: Change AGetNumDependencies00YAHXZ to ?GetNumDependencies@@YAHXZ
; after compiling the DLL. You can either use a hex editor or the PPFixer
; utility to do this.
ProcedureCDLL.l AGetNumDependencies00YAHXZ()
ProcedureReturn ArraySize(DBP_Dependencies.s()); Return number of elements in array
EndProcedure
; * GET DEPENDENCY IDs
; Note: Change AGetDependencyID00YAPBDH0Z to ?GetDependencyID@@YAPBDH@Z
; after compiling the DLL.You can either use a hex editor or the PPFixer
; utility to do this.
ProcedureCDLL.l AGetDependencyID00YAPBDH0Z(ID.l)
Dependency.s = DBP_Dependencies.s(ID)
ProcedureReturn @Dependency.s; Return string pointer
EndProcedure
; * RECEIVE CORE DATA POINTER HANDLE
; Note: Change AReceiveCoreDataPtr00YAXPAX0Z to ?ReceiveCoreDataPtr@@YAXPAX@Z
; after compiling the DLL.You can either use a hex editor or the PPFixer
; utility to do this.
ProcedureCDLL AReceiveCoreDataPtr00YAXPAX0Z(*CorePtrHandle)
*GlobPtr = *CorePtrHandle
EndProcedure
ProcedureCDLL ADestructor00YAXXZ()
EndProcedure
ProcedureCDLL AD3DDeviceLost00YAXXZ()
EndProcedure
ProcedureCDLL AD3DDeviceNotReset00YAXXZ()
EndProcedure
7. Why this:-
If OldString <> 0
CallCFunctionFast( *GlobPtr\CreateDeleteString, OldString , 0 )
EndIf
and not simply:-
If *GlobPtr = 0 : InitialiseCorePtr() : EndIf
8. Why this:-
CallCFunctionFast(*GlobPtrCreateDeleteString, @temp.l, Len(result$)+1 ) ; CreateString
PokeS(temp, result$)
ProcedureReturn temp
(also, is it meant to be
CallCFunctionFast(*GlobPtr\CreateDeleteString, @temp.l, Len(result$)+1 ie. with the '\'?)
and not simply this?:-
ProcedureReturn @result$
[edit]
9. The original TPC tutorial posted with the TGC magazine simply gave this code:-
(and in this code it almost looks like Test is both an integer and then a string within the procedure and the Test.l rather looks like OldString.l..... boh!?)
ProcedureCDLL.l NumberToText( Test.l, Number.l )
If *GlobPtr = 0 : InitialiseCorePtr() : EndIf
test.s = Str( Number )
ProcedureReturn @Test
EndProcedure
[edit]
10. Is there anywhere (at the start of every ProcedureCDLL where you're returning a string or every ProcedureCDLL full stop?) you must/could/should place the following code other than in the AConstructor00YAXXZ() Procedure?:-
<< If *GlobPtr = 0 : InitialiseCorePtr() : EndIf >>
a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...