|
Post by DJLinux on Apr 30, 2008 17:38:03 GMT -5
for none C++ programmers you can create Basic4GL plugins with FreeBASIC too. Joshy Download: FreeBASIC_Basic4GL_PLugin_SDK.zipexample: 'fbc -dll test01.bas #include "Basic4GLPlugin.bi"
const PLUGIN_DESC = "Test01 Plugin for Basic4GL" const PLUGIN_MAJOR = 0 const PLUGIN_MINOR = 1
extern "C" ' int=AddInt(int,int) private sub AddInt(THIS_RUNTIME) 'SetIntegerResult(GetIntegerParam(1)+GetIntegerParam(2)) SIR(GIP(1)+GIP(2)) end sub ' float=AddFloat(float,float) private sub AddFloat(THIS_RUNTIME) 'SetFloatResult(GetFloatParam(1)+GetFloatParam(2)) SFR(GFP(1)+GFP(2)) end sub
' ########## ' # Plugin # ' ##########
dim shared as IDLL_Basic4GL_Plugin ptr MyPlugin
' register exported Datatypes,Const's,Function's,Sub's function Load (THIS_PLUGIN , _ THIS_REGISTRY, _ blnIsExe as byte) as integer ' RegisterFloatConstant(NAME,VALUE) RFC (TEST_VERSION,PLUGIN_MAJOR+PLUGIN_MINOR*0.1) ' RegisterIntegerConstant(NAME,VALUE) RIC(TEST_INT,12345) 'RegisterIntegerFunction(name,address):RegisterIntegerParam,RegisterIntegerParam RIF(AddInt,@addint):AIP:AIP 'RegisterFloatFunction(name,address):RegisterFloatParam,RegisterFloatParam RFF(AddFloat,@addfloat):AFP:AFP return 1 end function
' interface sub Unload (THIS_PLUGIN) if MyPlugin then delete MyPlugin MyPlugin = 0 end if end sub
function Start(THIS_PLUGIN) as integer return 1 end function
sub Ends (THIS_PLUGIN)
end sub
sub Pause (THIS_PLUGIN)
end sub
sub Resumed (THIS_PLUGIN)
end sub
sub DelayedResume (THIS_PLUGIN)
end sub
sub GetError (THIS_PLUGIN,ErrMsg as zstring ptr)
end sub
sub ProcessMessages(THIS_PLUGIN)
end sub
' Query function function Basic4GL_Query alias "Basic4GL_Query" (byval details as string, _ byref major as integer, _ byref minor as integer) as integer export dim as string DetailSrc = PLUGIN_DESC for i as integer = 0 to len(detailSrc) Details = DetailSrc next major = PLUGIN_MAJOR minor = PLUGIN_MINOR return BASIC4GL_DLL_VERSION end function
' Main initialisation function. ' Here we will construct and return our plugin object function Basic4GL_Init alias "Basic4GL_Init" () as IDLL_Basic4GL_Plugin ptr ptr export ' Construct and return our plugin object MyPlugin=new IDLL_Basic4GL_Plugin MyPlugin->Load =@load MyPlugin->Unload =@unload MyPlugin->Start =@start MyPlugin->Ends =@ends MyPlugin->Pause =@pause MyPlugin->Resumed =@resumed MyPlugin->DelayedResume =@delayedresume MyPlugin->GetError =@geterror MyPlugin->ProcessMessages=@processmessages return @myplugin end function
end extern
|
|
|
Post by DJLinux on May 1, 2008 0:07:40 GMT -5
here are the ToolBox plugin in FreeBASIC syntax. you can see/learn how to handle many types of params int,float,string, byval, byref array's and so on. Joshy #include "GL\GLU.bi" #define WIN_INCLUDEALL #include "windows.bi" #include once "crt.bi" #include once "fbpng.bi" #inclib "fbpng"
#include "d:\basic4GL\Basic4GLPlugin.bi" type _OLD_HEADER field = 1 bpp : 3 as ushort width : 13 as ushort height as ushort end type
Type BMP_HEADER Field=1 as ushort bfType as integer bfSize as integer bfReserved as integer bfOffBits ' 54
As Integer biSize ' 40 bytes As Integer biWidth As Integer biHeight As Short biPlanes As Short biBitCount As Integer biCompression As Integer biSizeImage As Integer biXPelsPerMeter As Integer biYPelsPerMeter As Integer biClrUsed As Integer biClrImportant End Type
type BASIC4GL_WINDOW as HWND hWin as HDC DC as HGLRC RC end type
const PLUGIN_DESC = "ToolBox Plugin for Basic4GL" const PLUGIN_MAJOR = 0 const PLUGIN_MINOR = 1 ' 0-9 const MAX_WINDOWS = 16 const MAIN_WINDOW_INDEX = 0 extern "C"
dim shared as IDLL_Basic4GL_Plugin ptr Plugin dim shared as BASIC4GL_WINDOW Windows(MAX_WINDOWS-1) dim shared as PIXELFORMATDESCRIPTOR gPFD dim shared as integer gCurentWindow,gPause,gIsExe
' #################### ' # advanced section # ' #################### sub StandAlone(THIS_RUNTIME) SIR(gIsExe<>0) end sub sub WindowHandle(THIS_RUNTIME) SIR(cast(integer,Windows(0).hWin)) end sub sub DeviceContext(THIS_RUNTIME) SIR(cast(integer,Windows(0).DC)) end sub sub RenderContext(THIS_RUNTIME) SIR(cast(integer,Windows(0).RC)) end sub
' ################ ' # file section # ' ################ 'GetOpenFilename(Title$,FLAGS,Filter) private _ sub Get_OpenFileNameTFF(THIS_RUNTIME) Dim ofn As OPENFILENAME Dim as zstring ptr Title =GSP(3) dim as integer Flags =GIP(2) Dim as ubyte ptr Filter=GSP(1) dim as string dialogfilter dim as integer i while Filter<>0 if Filter=asc("|") then dialogFilter &=chr(0) else dialogFilter &=chr(Filter) end if i+=1 wend dialogFilter &=chr(0) & chr(0)
Dim filename As Zstring * MAX_PATH+1 With ofn .lStructSize = sizeof( OPENFILENAME ) .hwndOwner = Windows(gCurentWindow).hWin .hInstance = GetModuleHandle( NULL ) .lpstrFilter = strptr(DialogFilter) .lpstrCustomFilter = NULL .nMaxCustFilter = 0 .nFilterIndex = 0 .lpstrFile = @filename .nMaxFile = sizeof( filename ) .lpstrFileTitle = NULL .nMaxFileTitle = 0 .lpstrInitialDir = NULL .lpstrTitle = Title .Flags = Flags .nFileOffset = 0 .nFileExtension = 0 .lpstrDefExt = NULL .lCustData = 0 .lpfnHook = NULL .lpTemplateName = NULL End With If( GetOpenFileName( @ofn ) = FALSE ) Then filename="" end if SSR(filename) End sub
'GetSaveFilename(Title$,FLAGS,Filter) private _ sub Get_SaveFileNameTFF(THIS_RUNTIME) Dim ofn As OPENFILENAME Dim as zstring ptr Title =GSP(3) dim as integer Flags =GIP(2) Dim as ubyte ptr Filter =GSP(1) dim as string dialogfilter dim as integer i while Filter<>0 if Filter=asc("|") then dialogFilter &=chr(0) else dialogFilter &=chr(Filter) end if i+=1 wend dialogFilter &=chr(0) & chr(0)
Dim filename As Zstring * MAX_PATH+1 With ofn .lStructSize = sizeof( OPENFILENAME ) .hwndOwner = Windows(gCurentWindow).hWin .hInstance = GetModuleHandle( NULL ) .lpstrFilter = strptr(DialogFilter) .lpstrCustomFilter = NULL .nMaxCustFilter = 0 .nFilterIndex = 0 .lpstrFile = @filename .nMaxFile = sizeof( filename ) .lpstrFileTitle = NULL .nMaxFileTitle = 0 .lpstrInitialDir = NULL .lpstrTitle = Title .Flags = Flags .nFileOffset = 0 .nFileExtension = 0 .lpstrDefExt = NULL .lCustData = 0 .lpfnHook = NULL .lpTemplateName = NULL End With If( GetSaveFileName( @ofn ) = FALSE ) Then filename="" end if SSR(filename) End sub
' ExePath$=Path() sub Exe_Path(THIS_RUNTIME) dim as string P=ExePath() dim as zstring ptr lpP=strptr(P) SSR(lpP) end sub
' ExePath$=Path() sub CurentPath(THIS_RUNTIME) dim as string P=CurDir() dim as zstring ptr lpP=strptr(P) SSR(lpP) end sub
' ret=ChangePath$(NewPath$) sub ChangePath(THIS_RUNTIME) dim as zstring ptr lpP=GSP(1) dim as integer ret=ChDir(*lpP) if ret=0 then SIR(-1) else SIR(0) end if Deallocate(lpP) end sub
' ret=CreatePath$(NewPath$) sub CreatePath(THIS_RUNTIME) dim as zstring ptr lpP=GSP(1) dim as integer ret=MkDir(*lpP) if ret=0 then SIR(-1) else SIR(0) end if end sub ' ret=DeletePath$(NewPath$) sub DeletePath(THIS_RUNTIME) dim as zstring ptr lpP=GSP(1) dim as integer ret=RMDir(*lpP) if ret=0 then SIR(-1) else SIR(0) end if end sub
' ################## ' # window section # ' ################## private _ sub Show_Cursor(THIS_RUNTIME) ShowCursor(iif(GIP(1),1,0)) end sub
private _ sub Show_Window (THIS_RUNTIME) if Windows(gCurentWindow).hWin=NULL then return if GIP(1)<>0 then ShowWindow(Windows(gCurentWindow).hWin,SW_SHOW) else ShowWindow(Windows(gCurentWindow).hWin,SW_HIDE) end if end sub
private _ sub SetWindowTitle (THIS_RUNTIME) if Windows(gCurentWindow).hWin=NULL then return SetWindowText(Windows(gCurentWindow).hWin,GSP(1)) end sub private _ sub GetWindowTitle (THIS_RUNTIME) dim as zstring ptr lpText if Windows(gCurentWindow).hWin=NULL then return lpText=callocate(256) GetWindowText(Windows(gCurentWindow).hWin,lpText,256) SSR(lpText) deallocate lpText end sub
private _ sub SetWindowOntop(THIS_RUNTIME) if Windows(gCurentWindow).hWin=NULL then return SetWindowPos(Windows(gCurentWindow).hWin,HWND_TOPMOST,0,0,0,0,SWP_ASYNCWINDOWPOS or SWP_NOSIZE or SWP_NOMOVE) end sub
private _ sub WindowPos(THIS_RUNTIME) if Windows(gCurentWindow).hWin=NULL then return SetWindowPos(Windows(gCurentWindow).hWin,NULL,GIP(2),GIP(1),0,0,SWP_ASYNCWINDOWPOS or SWP_NOZORDER or SWP_NOSIZE) end sub private _ sub WindowSize(THIS_RUNTIME) if Windows(gCurentWindow).hWin=NULL then return SetWindowPos(Windows(gCurentWindow).hWin,NULL,0,0,GIP(2),GIP(1),SWP_ASYNCWINDOWPOS or SWP_NOZORDER or SWP_NOMOVE) end sub private _ sub WindowPosSize(THIS_RUNTIME) if Windows(gCurentWindow).hWin=NULL then return SetWindowPos(Windows(gCurentWindow).hWin,NULL,GIP(4),GIP(3),GIP(2),GIP(1),SWP_ASYNCWINDOWPOS or SWP_NOZORDER) end sub
' section tools private _ sub ExecuteProgram(THIS_RUNTIME) dim as zstring ptr cmd=GSP(2) dim as zstring ptr arg=GSP(1) dim as string c=*cmd dim as string a=*arg SIR(Exec(c,a)) end sub sub RunProgram(THIS_RUNTIME) dim as zstring ptr cmd=GSP(2) dim as zstring ptr arg=GSP(1) dim as string c=*cmd dim as string a=*arg SIR(Run(c,a)) end sub
private _ sub SwapInt(THIS_RUNTIME) dim as integer a,b GIPR(2,@a) GIPR(1,@b) SIPR(2,@b) SIPR(1,@a) end sub private _ sub SwapFloat(THIS_RUNTIME) dim as single a,b GFPR(2,@a) GFPR(1,@b) SFPR(2,@b) SFPR(1,@a) end sub private _ sub SwapString(THIS_RUNTIME) dim as zstring ptr a=callocate(1024) dim as zstring ptr b=callocate(1024) GSPR(2,1024,a) GSPR(1,1024,b) dim as integer al=len(*a),bl=len(*b)
SSPR(2,bl,b) SSPR(1,al,a) deallocate a deallocate b end sub
private _ sub MinFloat(THIS_RUNTIME) dim as single a=GFP(2),b=GFP(1) if a<b then SFR(a) else SFR(b) end if end sub private _ sub MaxFloat(THIS_RUNTIME) dim as single a=GFP(2),b=GFP(1) if a>b then SFR(a) else SFR(b) end if end sub
sub ToHex(THIS_RUNTIME) dim as string h=hex(GIP(1))+chr(0) SSR(StrPtr(h)) end sub sub ToHexN(THIS_RUNTIME) dim as string h=hex(GIP(2),GIP(1))+chr(0) SSR(StrPtr(h)) end sub
sub ToBin(THIS_RUNTIME) dim as string h=bin(GIP(1))+chr(0) SSR(StrPtr(h)) end sub sub ToBinN(THIS_RUNTIME) dim as string h=bin(GIP(2),GIP(1))+chr(0) SSR(StrPtr(h)) end sub
' GetPixels(x,y,w,h,Array(w,h)) private _ sub GetPixels(THIS_RUNTIME) dim as integer x=GIP(5),y=GIP(4),w=GIP(3),h=GIP(2) dim as integer nPixels=w*h dim as ubyte ptr Pixels=allocate(nPixels*4) dim as ubyte ptr Array =allocate(nPixels*4) glReadPixels(x,y,w,h,GL_RGBA,GL_UNSIGNED_BYTE,Pixels) for i as integer=0 to nPixels-1 Array[i*4+2]=Pixels[i*4+0] Array[i*4+1]=Pixels[i*4+1] Array[i*4+0]=Pixels[i*4+2] Array[i*4+3]=Pixels[i*4+3] next '_runtime->SetType(_runtime,DLL_BASIC4GL_EXT_BYTE) _runtime->SetType(_runtime,DLL_BASIC4GL_EXT_INT) _runtime->ModTypeArray(_runtime,1,w*h) _runtime->SetParam(_runtime,1,Array) deallocate Pixels deallocate Array end sub
sub SavePNG(THIS_RUNTIME) dim as integer x=GIP(5),y=GIP(4),w=GIP(3),h=GIP(2) dim as zstring ptr filename=GSP(1) dim as integer nPixels dim as ubyte ptr Pixels dim as _old_header ptr Img dim as ubyte ptr Src,Des
x=abs(x):y=abs(y):w=abs(w):h=abs(h) if w<1 then w=1 if h<1 then h=1
nPixels=w*h Pixels =allocate(nPixels*4) Img =allocate(nPixels*4+4) Src=Pixels Des=cptr(ubyte ptr,img) Des+=4+(h-1)*(w*4) glReadPixels(x,y,w,h,GL_RGBA,GL_UNSIGNED_BYTE,Pixels) src=Pixels for y =0 to h-1 for x =0 to w-1 Des[x*4+2]=Src[x*4+0] Des[x*4+1]=Src[x*4+1] Des[x*4+0]=Src[x*4+2] Des[x*4+3]=Src[x*4+3] next Src+=w*4 Des-=w*4 next Img->bpp =4 Img->width =w Img->height =h png_save(*Filename,Img) deallocate Pixels deallocate Img end sub
' SavePNGMask(x,y,w,h,File$,r,g,b) sub SavePNGMask(THIS_RUNTIME) dim as integer x=GIP(8),y=GIP(7),w=GIP(6),h=GIP(5) dim as zstring ptr filename=GSP(4) dim as ubyte r,g,b dim as integer nPixels dim as ubyte ptr Pixels dim as _old_header ptr Img dim as ubyte ptr Src,Des
x=abs(x):y=abs(y):w=abs(w):h=abs(h) if w<1 then w=1 if h<1 then h=1 nPixels=GIP(3):r=nPixels and 255 nPixels=GIP(2):g=nPixels and 255 nPixels=GIP(1):b=nPixels and 255
nPixels=w*h Pixels =allocate(nPixels*4) Img =allocate(nPixels*4+4) Src=Pixels Des=cptr(ubyte ptr,img) Des+=4+(h-1)*(w*4) glReadPixels(x,y,w,h,GL_RGBA,GL_UNSIGNED_BYTE,Pixels) src=Pixels for y =0 to h-1 for x =0 to w-1 Des[x*4+2]=Src[x*4+0] Des[x*4+1]=Src[x*4+1] Des[x*4+0]=Src[x*4+2] if Des[x*4+2]=r and Des[x*4+1]=g and Des[x*4+0]=b then Des[x*4+3]=0 else Des[x*4+3]=255 end if next Src+=w*4 Des-=w*4 next Img->bpp =4 Img->width =w Img->height =h png_save(*Filename,Img) deallocate Pixels deallocate Img end sub
sub SaveBMP(THIS_RUNTIME) dim as integer x=GIP(5),y=GIP(4),w=GIP(3),h=GIP(2) dim as zstring ptr filename=GSP(1) dim as integer nPixels,hFile dim as ubyte ptr Pixels dim as BMP_HEADER ptr Img dim as ubyte ptr Src,Des
x=abs(x):y=abs(y):w=abs(w):h=abs(h) if w<2 then w=2 if h<1 then h=1 w=(w+1) and &HFFFE nPixels=w*h Pixels =allocate(nPixels*3) Img =allocate(nPixels*3+SIZEOF(BMP_HEADER)) Src =Pixels Des =cptr(ubyte ptr,img) Des+ =SIZEOF(BMP_HEADER) '+(h-1)*(w*3) glReadPixels(x,y,w,h,GL_RGB,GL_UNSIGNED_BYTE,Pixels) src=Pixels for y =0 to h-1 for x =0 to w-1 Des[x*3+2]=Src[x*3+0] Des[x*3+1]=Src[x*3+1] Des[x*3+0]=Src[x*3+2] next Src+=w*3 Des+=w*3 next Img->bfType = &H4D42 Img->bfSize = SIZEOF(BMP_HEADER)+nPixels*3 Img->bfReserved = 0 Img->bfOffBits = SIZEOF(BMP_HEADER) Img->biSize = 40 Img->biWidth = w Img->biHeight = h Img->biPlanes = 1 Img->biBitCount = 24 Img->biCompression = 0 Img->biSizeImage = nPixels*3 Img->biXPelsPerMeter= 0 Img->biYPelsPerMeter= 0 Img->biClrUsed = 0 Img->biClrImportant = 0 des=cptr(ubyte ptr,img) hFile=FreeFile() open *Filename for binary access write as #hFile put #hFile,,*des,Img->bfSize close #hFile deallocate Pixels deallocate Img end sub
#if 0 sub GLPRINT(THIS_RUNTIME) dim as zstring ptr Text=GSP(1) dim as integer l=len(*Text) ' display a string indicate start of glyph display lists glListBase (1000) ' now draw the characters in a string glCallLists (l, GL_UNSIGNED_BYTE,Text) end sub #endif
' ########## ' # Plugin # ' ########## ' register exported Datatypes,Const's,Function's,Sub's function Load (THIS_PLUGIN , _ THIS_REGISTRY, _ blnIsExe as byte) as integer gIsExe=blnIsExe RFC (TOOLBOX_VERSION,PLUGIN_MAJOR+PLUGIN_MINOR*0.1)
RIC(TB_ENABLESIZING,OFN_CREATEPROMPT) RIC(TB_CREATEPROMPT,OFN_CREATEPROMPT) RIC(TB_PATHMUSTEXIST,OFN_PATHMUSTEXIST) RIC(TB_FILEMUSTEXIST,OFN_FILEMUSTEXIST) RIC(TB_HIDEREADONLY,OFN_HIDEREADONLY) RIC(TB_NONETWORKBUTTON,OFN_NONETWORKBUTTON) RIC(TB_OVERWRITEPROMPT,OFN_OVERWRITEPROMPT) RIC(TB_READONLY,OFN_READONLY)
RIF(StandAlone,@standalone) RIF(DeviceContext,@devicecontext) RIF(RenderContext,@rendercontext) RIF(WindowHandle ,@windowhandle)
RSF(ExePath,@exe_Path) RSF(CurentPath,@curentpath) RIF(ChangePath,@changepath):ASP RIF(CreatePath,@createpath):ASP RIF(DeletePath,@deletepath):ASP
' windows section RVF(ShowCursor,@show_Cursor):AIP RVF(ShowWindow,@show_Window):AIP RVF(WindowTitle,@setwindowtitle):ASP RSF(WindowTitle,@getwindowtitle) RVF(WindowOntop,@setwindowontop) RVF(WindowPos,@windowpos):AIP:AIP RVF(WindowPosSize,@windowpossize):AIP:AIP:AIP:AIP RVF(WindowSize,@windowsize):AIP:AIP
RSF(GetOpenFileName,@get_OpenFilenameTFF):ASP:AIP:ASP RSF(GetSaveFileName,@get_SaveFilenameTFF):ASP:AIP:ASP
' tool section RIF(ExecuteProgram,@executeprogram):ASP:ASP RIF(RunProgram,@runprogram):ASP:ASP
RVF(Swap,@swapint):AIPR:AIPR RVF(Swap,@swapfloat):AFPR:AFPR RVF(Swap,@swapstring):ASPR:ASPR RFF(Min,@minfloat):AFP:AFP RFF(Max,@maxfloat):AFP:AFP RSF(Hex$,@tohex ):AIP RSF(Hex$,@tohexn):AIP:AIP RSF(Bin$,@tobin ):AIP RSF(Bin$,@tobinn):AIP:AIP
' GetPixels(x,y,w,h,array()) RVF(GetPixels,@getpixels):AIP:AIP:AIP:AIP:AAIP(1) ' SavePNG/BMP(x,y,w,h,file$) RVF(SavePNG,@savepng):AIP:AIP:AIP:AIP:ASP RVF(SaveBMP,@savebmp):AIP:AIP:AIP:AIP:ASP ' SavePNGMask(x,y,w,h,file$,r,g,b) RVF(SavePNGMask,@savepngmask):AIP:AIP:AIP:AIP:ASP:AIP:AIP:AIP
'RVF(glPrint,@glprint):ASP return 1 end function
sub Unload (THIS_PLUGIN) ' MSGBOX("Plugin.Unload") if Plugin then delete Plugin Plugin = 0 end if end sub
function Start(THIS_PLUGIN) as integer gCurentWindow=0 Windows(gCurentWindow).hWin=FindWindow("gbOPENGL",NULL) Windows(gCurentWindow).DC = wglGetCurrentDC() Windows(gCurentWindow).RC = wglGetCurrentContext() dim as integer iPixelFormat = GetPixelFormat(Windows(0).DC) DescribePixelFormat(Windows(gCurentWindow).DC,iPixelFormat,SizeOf(PIXELFORMATDESCRIPTOR),@gpfd) wglMakeCurrent(Windows(gCurentWindow).DC,Windows(gCurentWindow).RC) return 1 end function sub Ends (THIS_PLUGIN) ' MSGBOX("Plugin.End") end sub sub Pause (THIS_PLUGIN) ' MSGBOX("PlugPause") gPause=-1 end sub sub Resumed (THIS_PLUGIN) ' MSGBOX("PlugResume") gPause=0 end sub sub DelayedResume (THIS_PLUGIN) ' MSGBOX("DelayedResume") gPause=0 end sub sub GetError (THIS_PLUGIN,ErrMsg as string) ' MSGBOX("GetError") end sub sub ProcessMessages(THIS_PLUGIN) ' MSGBOX("ProcessMessages") end sub
' Query function function Basic4GL_Query alias "Basic4GL_Query" (byval details as string, _ byref major as integer, _ byref minor as integer) as integer export dim as string DetailSrc = PLUGIN_DESC ' messagebox 0,"BASIC4GL_Query",PlugName,MB_OK for i as integer = 0 to len(detailSrc) Details = DetailSrc next major = PLUGIN_MAJOR minor = PLUGIN_MINOR return BASIC4GL_DLL_VERSION end function
' Main initialisation function. ' Here we will construct and return our plugin object function Basic4GL_Init alias "Basic4GL_Init" () as IDLL_Basic4GL_Plugin ptr ptr export ' Construct and return our plugin object Plugin=new IDLL_Basic4GL_Plugin Plugin->Load =@load Plugin->Unload =@unload Plugin->Start =@start Plugin->Ends =@ends Plugin->Pause =@pause Plugin->Resumed =@resumed Plugin->DelayedResume =@delayedresume Plugin->GetError =@geterror Plugin->ProcessMessages=@processmessages return @plugin end function
end extern
|
|
|
Post by george on Feb 2, 2009 8:02:11 GMT -5
Hi DJLinux, Hi All i have tried to add a function JoinStr to your test01.bas as the following: private sub JoinStr(THIS_RUNTIME) 'SetStringResult(GetStringParam(1) + GetStringParam(2)) SSR(GSP(1)& GSP(2)) end sub now in the : function Load (THIS_PLUGIN , _ THIS_REGISTRY, _ blnIsExe as byte) as integer i have added below the "RFF(AddFloat,@addfloat):AFP:AFP" : 'RegisterStringFunction ... RSF(JoinStr,@joinstr):ASP:ASP and in the test01.gb: printr test_int printr test_version printr AddInt(2,3) printr AddFloat(m_PI,m_E) dim a$,b$,&ptr$ a$="hello" b$=JoinStr(a$,a$) &ptr$ = &b$ printr ptr$
after compiling to dll and running the test01.gb the last output is a big number like this : 2561622825613124 i can't get the supposed result: hellohello may be it is a pointer but somehow it is attached to the string b$ can you please add to the test01.bas an example of receiving a string by test01.bas and return it to basic4GL i enclosed my experiment: rapidshare.com/files/192890656/FreeBASIC_Basic4GL_Plugin_SDK_expr.rar.htmlthank you
|
|
|
Post by DJLinux on Feb 2, 2009 12:50:09 GMT -5
why do you need a plugin if basic4gl can do the same job? c$=a$+b$ sub AddString(THIS_RUNTIME) dim as zstring ptr a=GSP(2) dim as zstring ptr b=GSP(1) dim as integer i,l1=len(*a) dim as integer j,l2=len(*b) dim as zstring ptr result=callocate(l1+l2+1) if l1>0 then for i=0 to l1-1 result=a next end if if l2>0 then for j =0 to l2-1 result[i+j]=b[j] next end if SSR(result) deallocate result end sub function Load (THIS_PLUGIN , _ THIS_REGISTRY, _ blnIsExe as byte) as integer RSF(AddString,@addstring):ASP:ASP ' ... return 1 end function
|
|
|
Post by george on Feb 2, 2009 14:29:00 GMT -5
thank you very much for your complete code, which without i will never succeed, it works well with me. i need passing strings because i have seen in the folder of freebasic an example "pcrc_demo" which demonstrates the regular expressions(but it needs the regex engine pcrc.dll after changing its name to "libpcre-0.dll"), i envisaged a function in Basic4Gl which supply two strings: 1-the text, 2-and the pattern, to the freebasic dll which will call the "libpcre-0.dll" to find the occurences of the pattern in the string, and then return the result to Basic4GL . i don't know if this is usefull to games, but it is an experiment. i will post the findings after studying the case. best regards
|
|