Restored from previous forum. Originally posted by jazzy.
Hi all, any1 can help on this dll C code to convert to PB:
#include
const BYTE ACTIONPARAM_NONE = 0;
const int MaxActionParams = 10;
typedef char* pCharArray[MaxActionParams];
typedef void(__stdcall *AddActionProcType)(int IDNum,char* Name, char* Hint,char Params[]/*,BYTE NumParams*/);
typedef void(__stdcall *AddFileProcType)(char*,bool AddFlag);
typedef void(__stdcall *GetVarProcType)(char* VarName, char*& Value);
typedef void(__stdcall *SetVarProcType)(char* VarName, char* Value);
typedef void(__stdcall *PlayActionProcType)(char*);
typedef bool(__stdcall *InterfaceProcType)(int InterfaceID,char* Data);
typedef void(__stdcall *dllHandlerProcType)(int Reason);
AddActionProcType xnbAddAction;
AddFileProcType nbAddFile;
GetVarProcType nbGetVar;
SetVarProcType nbSetVar;
PlayActionProcType nbPlayAction;
InterfaceProcType nbInterface;
HWND nbWinHandle;
extern "C"{
bool __declspec(dllexport) __stdcall nbEditAction(int IDNum, pCharArray& Params);
bool __declspec(dllexport) __stdcall nbExecAction(int IDNum, pCharArray& Params);
void __declspec(dllexport) __stdcall nbMessage(int MsgCode, int Reserved);
void __declspec(dllexport) __stdcall nbInitPlugIn(HWND WinHandle, char*& PlugInTitle, char*& PlugInPublisher, char*& PlugInHint);
void __declspec(dllexport) __stdcall nbRegisterScriptProcessor(PlayActionProcType PlayActionProc);
void __declspec(dllexport) __stdcall nbRegisterInterfaceAccess(InterfaceProcType InterfaceProc);
void __declspec(dllexport) __stdcall nbRegisterPlugIn(AddActionProcType AddActionProc, AddFileProcType AddFileProc,
GetVarProcType VarGetFunc, SetVarProcType VarSetFunc);
void FreeStr(char* S){
if(S!=NULL){GlobalFree(HGLOBAL(S));}
S=NULL;
}
void SetStr(char*& Dest,char* Source){
int slngth=0;while(Source[slngth]){slngth++;}
if(Dest!=NULL){GlobalFree(HGLOBAL(Dest));}
Dest=(char*)(GlobalAlloc(GMEM_FIXED,slngth+1));
strcpy(Dest,Source);
}
void nbAddAction(int IDNum,char* Name, char* Hint,char Params[],BYTE NumParams){
__asm{
push eax
xor eax,eax
mov al,NumParams
push eax
push eax
}
xnbAddAction(IDNum,Name,Hint,Params);
__asm pop eax;
}
bool __declspec(dllexport) __stdcall nbEditAction(int IDNum, pCharArray& Params)
switch(IDNum){
case 1:
break;
}
return TRUE;
}
bool __declspec(dllexport) __stdcall nbExecAction(int IDNum, pCharArray& Params)
switch(IDNum){
case 1:
break;
}
return 0;
}
void __declspec(dllexport) __stdcall nbMessage(int MsgCode, int Reserved){
switch(MsgCode){
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
}
}
void __declspec(dllexport) __stdcall nbInitPlugIn(HWND WinHandle, char*& PlugInTitle, char*& PlugInPublisher, char*& PlugInHint){
nbWinHandle = WinHandle;
SetStr( PlugInTitle, "Sample Plug-In");
SetStr(PlugInPublisher, "John Doe");
SetStr(PlugInHint, "Use this display a Windows message box");
}
void __declspec(dllexport) __stdcall nbRegisterScriptProcessor(PlayActionProcType PlayActionProc)
nbPlayAction=PlayActionProc;
void __declspec(dllexport) __stdcall nbRegisterInterfaceAccess(InterfaceProcType InterfaceProc){
nbInterface = InterfaceProc;
void __declspec(dllexport) __stdcall nbRegisterPlugIn(AddActionProcType AddActionProc, AddFileProcType AddFileProc,
GetVarProcType VarGetFunc, SetVarProcType VarSetFunc){
nbGetVar=VarGetFunc;
nbSetVar=VarSetFunc;
xnbAddAction=AddActionProc;
nbAddFile=AddFileProc;
BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){
if(fdwReason==DLL_PROCESS_DETACH)
Txs for any help.
Help on "C" conversion to PB
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by dmoc.
This is my (limited time) first go. Hope it helps. Note that the code seems corrupt/ incomplete AND also that a bit more work would be needed.
This is my (limited time) first go. Hope it helps. Note that the code seems corrupt/ incomplete AND also that a bit more work would be needed.
Code: Select all
; Assuming you convert...
XIncludeFile "wtypes.pbi"
#BYTE ACTIONPARAM_NONE = 0;
#MaxActionParams.w = 10;
; All reduce to long...
;
;typedef char* pCharArray[MaxActionParams];
;typedef void(__stdcall *AddActionProcType)(int IDNum,char* Name, char* Hint,char Params[]/*,BYTE NumParams*/);
;typedef void(__stdcall *AddFileProcType)(char*,bool AddFlag);
;typedef void(__stdcall *GetVarProcType)(char* VarName, char*& Value);
;typedef void(__stdcall *SetVarProcType)(char* VarName, char* Value);
;typedef void(__stdcall *PlayActionProcType)(char*);
;typedef bool(__stdcall *InterfaceProcType)(int InterfaceID,char* Data);
;typedef void(__stdcall *dllHandlerProcType)(int Reason);
xnbAddAction.l ; AddActionProcType
nbAddFile.l ; AddFileProcType
nbGetVar.l ; GetVarProcType
nbSetVar.l ; SetVarProcType
nbPlayAction.l ; PlayActionProcType
nbInterface.l ; InterfaceProcType
nbWinHandle.l ; HWND
;extern "C"{
;bool __declspec(dllexport) __stdcall nbEditAction(int IDNum, pCharArray& Params);
;bool __declspec(dllexport) __stdcall nbExecAction(int IDNum, pCharArray& Params);
;void __declspec(dllexport) __stdcall nbMessage(int MsgCode, int Reserved);
;void __declspec(dllexport) __stdcall nbInitPlugIn(HWND WinHandle, char*& PlugInTitle, char*& PlugInPublisher, char*& PlugInHint);
;void __declspec(dllexport) __stdcall nbRegisterScriptProcessor(PlayActionProcType PlayActionProc);
;void __declspec(dllexport) __stdcall nbRegisterInterfaceAccess(InterfaceProcType InterfaceProc);
;void __declspec(dllexport) __stdcall nbRegisterPlugIn(AddActionProcType AddActionProc, AddFileProcType AddFileProc,
;GetVarProcType VarGetFunc, SetVarProcType VarSetFunc);
;
; Not sure if these actually do return byte or long...
;
Declare.b nbEditAction(IDNum.w, Params.l);
Declare.b nbExecAction(IDNum.w, Params.l);
Declare nbMessage(MsgCode.w, Reserved.w);
Declare nbInitPlugIn(WinHandle.l, PlugInTitle.l, PlugInPublisher.l, PlugInHint.l);
Declare nbRegisterScriptProcessor(PlayActionProc.l);
Declare nbRegisterInterfaceAccess(InterfaceProc.l);
Declare nbRegisterPlugIn(AddActionProc.l, AddFileProc.l, VarGetFunc.l, VarSetFunc.l);
;void FreeStr(char* S){
;if(S!=NULL){GlobalFree(HGLOBAL(S));}
;S=NULL;
;}
;
Procedure FreeStr(S.s)
if S: GlobalFree_(S): endif
S = 0
EndProcedure
;void SetStr(char*& Dest,char* Source){
;int slngth=0;while(Source[slngth]){slngth++;}
;if(Dest!=NULL){GlobalFree(HGLOBAL(Dest));}
;Dest=(char*)(GlobalAlloc(GMEM_FIXED,slngth+1));
;strcpy(Dest,Source);
}
;
Procedure SetStr(Dest.s, Source.s)
slngth.w = 0;
;while(Source[slngth]){slngth++;}
slngth = len(Source)
if Dest; GlobalFree_(Dest): endif
Dest = GlobalAlloc_(#GMEM_FIXED,slngth+1);
strcpy_(Dest,Source);
EndProcedure
;void nbAddAction(int IDNum,char* Name, char* Hint,char Params[],BYTE NumParams){
; __asm{
; push eax
; xor eax,eax
; mov al,NumParams
; push eax
; push eax
; }
; xnbAddAction(IDNum,Name,Hint,Params);
; __asm pop eax;
;}
ProcedureDLL nbAddAction(IDNum.w, Name.s, Hint.s, Params.b[], NumParams.b) ; UNFINISHED
EndProcedure
; Assumed missing {
;bool __declspec(dllexport) __stdcall nbEditAction(int IDNum, pCharArray& Params){
; switch(IDNum){
; case 1:
; break;
; }
; return TRUE;
;}
;
ProcedureDLL nbEditAction(IDNum.w, Params.l);
EndProcedure
; Assumed missing {
;bool __declspec(dllexport) __stdcall nbExecAction(int IDNum, pCharArray& Params){
; switch(IDNum){
; case 1:
; break;
; }
; return 0;
;}
;
ProcedureDLL nbExecAction(IDNum.w, Params.l);
EndProcedure
;void __declspec(dllexport) __stdcall nbMessage(int MsgCode, int Reserved){
; switch(MsgCode){
; case 1:
; break;
; case 2:
; break;
; case 3:
; break;
; case 4:
; break;
; case 5:
; break;
; case 6:
; break;
; }
;}
;
ProcedureDLL nbMessage(MsgCode.w, Reserved.w);
EndProcedure
;void __declspec(dllexport) __stdcall nbInitPlugIn(HWND WinHandle, char*& PlugInTitle, char*& PlugInPublisher, char*& PlugInHint){
; nbWinHandle = WinHandle;
; SetStr( PlugInTitle, "Sample Plug-In");
; SetStr(PlugInPublisher, "John Doe");
; SetStr(PlugInHint, "Use this display a Windows message box");
;}
;
ProcedureDLL nbInitPlugIn(WinHandle.l, PlugInTitle.l, PlugInPublisher.l, PlugInHint.l);
EndProcedure
; Things look too suspicious from this point...
void __declspec(dllexport) __stdcall nbRegisterScriptProcessor(PlayActionProcType PlayActionProc)
nbPlayAction=PlayActionProc;
void __declspec(dllexport) __stdcall nbRegisterInterfaceAccess(InterfaceProcType InterfaceProc){
nbInterface = InterfaceProc;
void __declspec(dllexport) __stdcall nbRegisterPlugIn(AddActionProcType AddActionProc, AddFileProcType AddFileProc,
GetVarProcType VarGetFunc, SetVarProcType VarSetFunc){
nbGetVar=VarGetFunc;
nbSetVar=VarSetFunc;
xnbAddAction=AddActionProc;
nbAddFile=AddFileProc;
BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){
if(fdwReason==DLL_PROCESS_DETACH)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tinman.
--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.62, external editor)
If you are just trying to use the DLL functions in PureBasic then v3.62 comes with a DLL import tool which converts DLLs to PB libraries, allowing you to call the functions.Originally posted by jazzy
Hi all, any1 can help on this dll C code to convert to PB:
--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.62, external editor)