Page 1 of 1

Please Help!

Posted: Mon Aug 02, 2004 12:12 am
by marlo
Hi all, can you help me to convert this powerbasic code to Purebasic? Its to make DLLs used as plugins, i think this be possible ,if its possible in powerbasic , this is only a interface for plugins>


#INCLUDE "WIN32API.INC"

' ****************** Interface Functions DO NOT MODIFY***********
' * Action Command Parameter Types...

%ACTIONPARAM_NONE = 0
%ACTIONPARAM_ALPHA = 1 ' May contain alpha, numeric, punctuation, etc.
%ACTIONPARAM_ALPHASP = 2 ' Contains aplha text that can be spell checked.
%ACTIONPARAM_NUMERIC = 3 ' Must be numeric value 0..9
%ACTIONPARAM_MIXED = 4 ' May be either numeric or alpha. May contain math expression
%ACTIONPARAM_FILENAME = 5 ' Parameter is a file name
%ACTIONPARAM_VARIABLE = 6 ' Parameter is a variable name
%ACTIONPARAM_DATAFILE = 7 ' Parameter is data file - if not a variable then should be localized

%MaxActionParams = 10 ' Maximum number of parameters per action


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)


' 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...

SUB FreeStr(BYREF S AS DWORD)
IF S <> %NULL THEN GlobalFree S
S = %NULL
END SUB

' Used to modify PChar parameters. You must use this if you modify any
' PChars sent to and from your Plug-In DLL. Failure to use this
' procedure may result in memory allocation errors, crashes, etc...

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
GLOBAL RetValue$


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

SUB SetVariable(BYVAL Variable$,BYVAL Wert$)
CALL DWORD nbSetVar USING SetVarProcType(BYCOPY Variable$,BYCOPY Wert$)
END SUB

SUB PlayScript(BYVAL Script$)
CALL DWORD nbPlayAction USING PlayActionProcType(BYCOPY Script$)
END SUB

FUNCTION GetVariable(par$) AS STRING
RetValue$=""
PlayScript $FUNKTIONS_NAME1+CHR$(32,34)+"<#["+par$+"]#>"+CHR$(34)
FUNCTION=RetValue$
END FUNCTION


' ******************** End of Interface Functions**********

Im a newbie but registered from 2.60 version. Thanks for any help!

Re: Please Help!

Posted: Mon Aug 02, 2004 12:25 am
by Doobrey
It`s even simpler than that..
Use ProcedureDLL or ProcedureCDLL (depends how the program calls the plugin) instead of a normal Procedure, and under 'Compiler Options' and set Executable Format to 'Shared DLL'

how?

Posted: Mon Aug 02, 2004 2:10 pm
by marlo
This lines are > ProcedureDLL,Estructure, or What in Purebasic?

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)

Re: how?

Posted: Mon Aug 02, 2004 11:38 pm
by Doobrey
Well, this is only a best guess, since I`ve never used Powerbasic..
I`m assuming the only difference between a sub and a function in PowerBasic, is that a sub doesn`t return a value.
And whats with the AddActionProcType line ? It has mismatching brackets!
(one open, two close)


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

In PureBasic, you don`t have to 'declare' a function, in the way you do with VB, although you can if you want to...

Simply start your DLL function with one of the above, and at the end of it use 'ProcedureReturn somevariable.l ' if it needs it (such as the InterfaceProcType), then finish it with EndProcedure as normal.

BTW, read then re-read the DLL section in the manual as there are certain rules of what you can and can`t do in them.

Posted: Tue Aug 03, 2004 4:27 pm
by marlo
Thanks Doobrey for your help!