Powerbasic to Purebasic

Just starting out? Need help? Post your questions and find answers here.
marlo
User
User
Posts: 10
Joined: Fri Jul 30, 2004 8:39 pm

Powerbasic to Purebasic

Post by marlo »

I try to convert in my little experience this powerbasic to Purebasic> Is for a dll used as a plugin by neobook,but i need help ,please:


First the powerbasic code>

%USEMACROS = 1

$PLUGIN_TITLE = "COM Communication for NeoBook"
$PLUGIN_AUTHOR = "Author"
$PLUGIN_INFO = "Allows interaction with COM ports from within NeoBook"


%ACTIONPARAM_NONE = 0
%ACTIONPARAM_ALPHA = 1
%ACTIONPARAM_ALPHASP = 2
%ACTIONPARAM_NUMERIC = 3
%ACTIONPARAM_MIXED = 4
%ACTIONPARAM_FILENAME = 5
%ACTIONPARAM_VARIABLE = 6
%ACTIONPARAM_DATAFILE = 7
%MaxActionParams = 10


Declare Sub AddActionProcType(ByVal IDNum As Long, ByRef zName As Asciiz, ByRef Hint As Asciiz, ByRef Params As Asciiz) ', ByVal NumParams As Byte)
Declare Sub AddFileProcType(ByRef s As Asciiz, ByVal AddFlag As Long)
Declare Sub GetVarProcType(ByRef VarName As Asciiz, ByRef Value As Asciiz)
Declare Sub SetVarProcType(ByRef VarName As Asciiz, ByRef Value As Asciiz)
Declare Sub PlayActionProcType(ByRef s As Asciiz)
Declare Function InterfaceProcType(ByVal InterfaceID As Long, ByRef zData As Asciiz) As Long
Declare Sub dllHandlerProcType(ByVal Reason As Long)

Sub FreeStr(ByRef S As Dword)
If S <> %NULL Then GlobalFree S
S = %NULL
End Sub

Sub SetStr(ByRef Dest As Dword, ByVal Source As String)
FreeStr Dest
If Len(Source) Then
Dest = GlobalAlloc(%GPTR, Len(Source) + 1)
Poke$ Dest, Source
End If
End Sub

Global nbGetVar As Dword
Global nbSetVar As Dword
Global nbPlayAction As Dword
Global nbInterface As Dword
Global nbAddFile As Dword
Global nbAddAction As Dword
Global nbWinHandle As Dword

Sub xnbAddAction(ByVal IDNum As Long, zName As Asciiz, zHint As Asciiz, Params As Asciiz, ByVal NumParams As Byte)

Asm push eax
Asm xor eax,eax
Asm mov al, NumParams
Asm push eax
Asm push eax
Call Dword nbAddAction Using AddActionProcType(IDNum, zName, zHint, Params)
Asm pop eax
End Sub

Function nbEditAction Alias "_nbEditAction@8" (ByVal IDNum As Long, Params As Asciiz) Export As Byte

Select Case IDNum

Case 1: Function = %True
Case 2: Function = %True
Case Else: Function = %FALSE
End Select
End Function
Function nbExecAction Alias "_nbExecAction@8" (ByVal IDNum As Long, Params As Asciiz) Export As Byte
Select Case IDNum
Case 1: gsComPort = SelectComPort(GetActiveWindow): Function = %True
Case 2: ComPortCommunicate GetActiveWindow : Function = %True
Case Else: Function = %FALSE
End Select
End Function
Sub nbInitPlugIn Alias "_nbInitPlugIn@16" (ByVal WinHandle As Dword, _
ByRef PlugInTitle As Dword, _
ByRef PlugInPublisher As Dword, _
ByRef PlugInHint As Dword) Export
nbWinHandle = WinHandle
SetStr PlugInTitle, $PLUGIN_TITLE
SetStr PlugInPublisher, $PLUGIN_AUTHOR
SetStr PlugInHint, $PLUGIN_INFO
End Sub
Sub nbRegisterScriptProcessor Alias "_nbRegisterScriptProcessor@4" (ByVal PlayActionProc As Dword) Export
nbPlayAction = PlayActionProc
End Sub
Sub nbMessage Alias "_nbMessage@8" (ByVal MsgCode As Long, ByVal Reserved As Long) Export
End Sub
Sub nbRegisterInterfaceAccess Alias "_nbRegisterInterfaceAccess@4" (ByVal InterfaceProc As Dword) Export
nbInterface = InterfaceProc
End Sub

Function VerifyRegCode(Code As Asciiz Ptr) As Long
Function = %True
End Function

Function GetRegCode(ByRef CodeStr As Asciiz) As Long
CodeStr = "ABC123"
Function = %True
End Function

Function nbVerifyLicense(ByRef Code As Asciiz) As Byte
Dim CodeStr As Asciiz * 256
If Len(Code) = 0 Then ' empty parameter
If GetRegCode(CodeStr) Then
SetStr VarPtr(Code), CodeStr
Function = %TRUE
End If
Else
Function = VerifyRegCode(VarPtr(Code))
End If
End Function

Sub nbRegisterPlugIn Alias "_nbRegisterPlugIn@16" (ByVal AddActionProc As Dword, _
ByVal AddFileProc As Dword, _
ByVal VarGetFunc As Dword, _
ByVal VarSetFunc As Dword) Export
nbGetVar = VarGetFunc
nbSetVar = VarSetFunc
nbAddAction = AddActionProc
nbAddFile = AddFileProc
End Sub
Function LibMain(ByVal hInstance As Dword, _
ByVal Reason As Long, _
ByVal Reserved As Long) As Long
If (Reason = %DLL_PROCESS_DETACH) Then
End If

Function = %True
End Function


Ok this is the Purebasic code i can make>


#USEMACROS = 1
PLUGIN_TITLE$ = "MyPlugin"
PLUGIN_AUTHOR$ = "Author"
PLUGIN_INFO$ = "any info about plugin"

#ACTIONPARAM_NONE = 0
#ACTIONPARAM_ALPHA = 1
#ACTIONPARAM_ALPHASP = 2
#ACTIONPARAM_NUMERIC = 3
#ACTIONPARAM_MIXED = 4
#ACTIONPARAM_FILENAME = 5
#ACTIONPARAM_VARIABLE = 6
#ACTIONPARAM_DATAFILE = 7
#MaxActionParams = 10

ProcedureDLL AddActionProcType(IDNum.l,*zName.s,*Hint.s,*Params.s,NumParams.b)
EndProcedure
ProcedureDLL AddFileProcType(*s.s, AddFlag.l)
EndProcedure
ProcedureDLL GetVarProcType(*VarName.s,*Value.s)
EndProcedure
ProcedureDLL SetVarProcType(*VarName.s, *Value.s)
EndProcedure
ProcedureDLL PlayActionProcType(*s.s)
EndProcedure
ProcedureDLL.l InterfaceProcType(InterfaceID.l,*zData.s)
EndProcedure
ProcedureDLL dllHandlerProcType(Reason.l)
EndProcedure

ProcedureDLL FreeStr()
S.l
If S <> #NULL
GlobalFree_(S)
EndIf
S = #NULL
EndProcedure

ProcedureDLL SetStr()
Dest.l
Source.s
FreeMemory(Dest)
If Len(Source)
Dest = GlobalAlloc_(#GPTR, Len(Source) + 1)
PokeS(*Dest, Source)
EndIf


EndProcedure
Global nbGetVar .l
Global nbSetVar .l
Global nbPlayAction.l
Global nbInterface .l
Global nbAddFile .l
Global nbAddAction .l
Global nbWinHandle .l
Global gsComPort .s
ProcedureDLL xnbAddAction()
IDNum.l
zName.s
zHint.s
Params.s
NumParams.b
PUSH eax
XOR eax,eax
MOV al, NumParams
PUSH eax
PUSH eax
CALL nbAddAction
POP eax
EndProcedure

Well, the code is not complete ,maybe anyone knows powerbasic and can help me.

Txs
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Post by Doobrey »

marlo wrote:
ProcedureDLL FreeStr()
S.l
If S <> #NULL
GlobalFree_(S)
EndIf
S = #NULL
EndProcedure

ProcedureDLL SetStr()
Dest.l
Source.s
FreeMemory(Dest)
If Len(Source)
Dest = GlobalAlloc_(#GPTR, Len(Source) + 1)
PokeS(*Dest, Source)
EndIf
EndProcedure
Why have you removed the parameters from the procedure declaration ?
By doing that, the procedure gets no parameters.
they should be..

Code: Select all

ProcedureDLL FreeStr(*S.l)
If *S\l 
 GlobalFree_(*S\l)
EndIf
*S\l=0
EndProcedure

ProcedureDLL SetStr(*Dest.l,Source.s)
FreeStr(*Dest)
If Len(Source)
  *Dest\l = GlobalAlloc_(#GPTR, Len(Source) + 1)
  PokeS(*Dest\l, Source)
EndIf
EndProcedure
Is there an SDK for C for neobook? It`d probably be a lot easier to convert.
marlo
User
User
Posts: 10
Joined: Fri Jul 30, 2004 8:39 pm

Post by marlo »

Thanks Doobrey, you are my only support here. This is the C example:


#include <wtypes.h>

//******Neobook Interface Function - Do not edit*******************
/**/const BYTE ACTIONPARAM_NONE = 0;
/**/const BYTE ACTIONPARAM_ALPHA = 1;
/**/const BYTE ACTIONPARAM_ALPHASP = 2;
/**/const BYTE ACTIONPARAM_NUMERIC = 3;
/**/const BYTE ACTIONPARAM_MIXED = 4;
/**/const BYTE ACTIONPARAM_FILENAME = 5;
/**/const BYTE ACTIONPARAM_VARIABLE = 6;
/**/const BYTE ACTIONPARAM_DATAFILE = 7;
/**/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);
/**/}
/**/
/* Used to free memory allocated to PChars. You must use this if you create any
/* PChars to send between NeoBook and your Plug-In DLL. Failure to use this
/* procedure may result in memory allocation errors, memory leaks, crashes, etc...
/**/void FreeStr(char* S){
/**/ if(S!=NULL){GlobalFree(HGLOBAL(S));}
/**/ S=NULL;
/**/}
/* Used to modify PChar parameteres. You must use this if you modify any
/* PChars sent between NeoBook and your Plug-In DLL. Failure to use this
/* procedure may result in memory allocation errors, crashes, etc...
/**/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){
//////Do not edit. This is to match Delphi's calling conventions.
/**/__asm{
/**/ push eax
/**/ xor eax,eax
/**/ mov al,NumParams
/**/ push eax
/**/ push eax
/**/}
/**/xnbAddAction(IDNum,Name,Hint,Params);
/**/__asm pop eax;
/**/}
///////////////////////////////////////////////////////


/******************** End of NeoBook Interface Functions **********************/


/******************* Your Custom Plug-In Functions Go Here ********************/



/********** NeoBook Plug-In Functions that Must be Customized by You **********/
// nbEditAction - called by NeoBook to edit/define on of the Plug-In's commands.
// Plug-In may display a dialog box with fields for user to fill in. Return
// TRUE if successful, FALSE if not..
bool __declspec(dllexport) __stdcall nbEditAction(int IDNum, pCharArray& Params){

//Examine the Action string to determine which Plug-In command to execute... }
switch(IDNum){
case 1:
break;
}
return TRUE;

}


//nbExecAction - called by NeoBook to execute one of the Plug-In's commands...
bool __declspec(dllexport) __stdcall nbExecAction(int IDNum, pCharArray& Params){
//Examine the Action string to determine which Plug-In command to execute... }
switch(IDNum){
case 1:
break;

}
return 0;
}

// nbMessage - sent by NeoBook to inform plug-in of important NeoBook activities... }
void __declspec(dllexport) __stdcall nbMessage(int MsgCode, int Reserved){
/* Not all types of plug-ins will care about these messages,
so they can be ignored if not needed. This procedure must be present even if
none of the messages are used.

Possible MsgCode values are:

1 = Pub has entered run mode
2 = Pub is about to exit run mode and return to design mode.
3 = Pub window has been deactivated
4 = Pub window has been activated
5 = Pub window has been moved or sized
6 = Pub is about to display another page

Reserved value is not currently used */

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){
// Save handle of Parent NeoBook App or compiled pub Window - may be required by some Windows functions }
nbWinHandle = WinHandle;

// Title of this Plug-In (appears as heading in NeoBook's action list) }
SetStr( PlugInTitle, "Sample Plug-In");

// Publisher of this Plug-In }
SetStr(PlugInPublisher, "John Doe");

// Description of this Plug-In }
SetStr(PlugInHint, "Use this plug-in to display a Windows message box");

}


// nbRegisterScriptProcessor - called by NeoBook when registering your plug-in
// Provides access to NeoBook's Action Script Player via nbPlayAction...
void __declspec(dllexport) __stdcall nbRegisterScriptProcessor(PlayActionProcType PlayActionProc){
//***************************** DO NOT MODIFY ********************************}
nbPlayAction=PlayActionProc;
//****************************************************************************}
}

// nbRegisterInterfaceAccess - called by NeoBook when registering your plug-in
// Provides access to some of NeoBook's design-time interface via nbInterface...
void __declspec(dllexport) __stdcall nbRegisterInterfaceAccess(InterfaceProcType InterfaceProc){
//***************************** DO NOT MODIFY ********************************}
nbInterface = InterfaceProc;
//****************************************************************************}
}




//nbRegisterPlugIn - called by NeoBook when it wants you to register your plug-in's actions... }
void __declspec(dllexport) __stdcall nbRegisterPlugIn(AddActionProcType AddActionProc, AddFileProcType AddFileProc,
GetVarProcType VarGetFunc, SetVarProcType VarSetFunc){
//***************************** DO NOT MODIFY ********************************}
nbGetVar=VarGetFunc;
nbSetVar=VarSetFunc;
xnbAddAction=AddActionProc;
nbAddFile=AddFileProc;
//****************************************************************************}


/* Call the AddAction procedure for each of Plug-In command.

Parameters for the ndAddAction procedure:

Item 1 = Action ID number - must use a unique identifier for each of your actions.
Item 2 = Action Name
Item 3 = Action Description
Item 4 = Array describing each of the Action's parameters - choose from the following:

ACTIONPARAM_NONE = Use if action contains no parameters.
ACTIONPARAM_ALPHA = Parameter is a string. May contain alpha, numeric, punctuation, etc.
ACTIONPARAM_ALPHASP = Parameter is a string that can be spell checked.
ACTIONPARAM_NUMERIC = Parameter is a number.
ACTIONPARAM_MIXED = May be either numeric or alpha. May contain math expression.
ACTIONPARAM_FILENAME = Parameter is a file name.
ACTIONPARAM_VARIABLE = Parameter is a variable name.
ACTIONPARAM_DATAFILE = Parameter is data file - if not a variable then should be localized.

Item 5 = Number of parameters required by this action

*/

//******************* Enter your Plug-In's actions below *********************}




/*Next, if necessary, tell NeoBook what extra files are required for your plug-in.
These are the files that NeoBook will collect when compiling publications that
use this plug-in. If your plug-in uses any data files, drivers or special DLLs
this is where you will tell NeoBook about it. It is NOT necessary to include
the name of the plug-in itself since NeoBook will automatically assume that
it is required.

Parameters for the ndAddFile procedure:

Item 1 = File name including correct drive and path
Item 2 = TRUE to add the file, FALSE to remove the file

For example:

nbAddFile( "c:\path\somefile.xyz", TRUE );*/


}

BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){

if(fdwReason==DLL_PROCESS_DETACH){
//If this plug-in requires any special processing before being unloaded from
//memory, do that here. Leave blank if no special processing is needed. }
}
}

Thanks again.
ivory
User
User
Posts: 36
Joined: Fri Jun 25, 2004 2:30 am

Post by ivory »

You don't need the usemacro field, it controls the include files (and either includes callable subs or macros to handle some of the api's).

If the PowerBasic code works, it might be simplest to write a wrapper DLL in powerbasic, and just let it pass the parms from purebasic on to neo.
Stefke28
User
User
Posts: 11
Joined: Thu Jul 15, 2004 9:06 am
Location: BELGIUM

Marlo can you please help me ?

Post by Stefke28 »

Dear Marlo

Can you please help me for written the functions for dynamic datastructures such as stack, queue, linkedlist, sortedlist for PowerBASIC and where can I find it for PureBASIC ?

What are the mosly used functions for :
1. Stack
2. Queue
3. Linkedlist
4. SortedList
5. ArrayList

I have urgent this functions needed for my project

Kind regards
Steve
Post Reply