Converting power to Purebasic code

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

Converting power to Purebasic code

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