Delgine 3D Tools & Content DeleD Community Edition
Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DeleD FreeBASIC plugin template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Plugins
View previous topic :: View next topic  
Author Message
D.J.Peters
Member


Joined: 11 Nov 2007
Posts: 8
Location: Germany

PostPosted: Sun Nov 11, 2007 9:30 am    Post subject: DeleD FreeBASIC plugin template Reply with quote

Hello i'm new here and would bublish an FreeBASIC plugin template for DeleD.

http://FreeBASIC.net

The file plugin.def for the linker removes the sdtcall name@xyz decoration from exported plugin function
"plugin.def"
Code:
LIBRARY test01.dll
EXPORTS
  PluginName
  PluginDescription
  PluginDeleDVersion
  PluginVersion
  PluginAuthor
  PluginEmail
  PluginSetCallback
  PluginExecute


here a short test plugin
"test01.bas"
Code:
' DeleD FreeBASIC plugin framework
' fbc -Wl plugin.def -dll test01.bas

#include "windows.bi" ' only for MessageBox

enum Requests
  PR_GETMEM  = 0
  PR_GETDATA = 1
  PR_SETDATA = 2
end enum

type TCallBackRecord
  as Requests    RequestID    ' reason for executing callback (0,1 or 2)
  as zstring ptr RequestXML   ' XML data send by the plugin to DeleD
  as zstring ptr ResponseXML  ' XML data send by DeleD to the plugin
  as integer     ResponseSize ' size of the response XML data in bytes
end type

' plugin errors returned by callback function
enum plugin_errors
  PE_NOERROR             = 0 ' no errors in callback
  PE_NODATA              = 1 ' no data to set or get
  PE_INVALIDVERSION      = 2 ' invalid version
  PE_INVALIDMEM          = 3 ' invalid memory size
  PE_INVALIDGET          = 4 ' invalid get operation
  PE_INVALIDSET          = 5 ' invalid set operation
  PE_INVALIDHEADER       = 6 ' invalid header
  PE_INVALIDDATASTRING   = 7 ' invalid data string
  PE_INVALIDDATAPROPERTY = 8 ' invalid data property
  PE_OBJECTDATA          =11 ' invalid object data
  PE_LIGHTDATA           =12 ' invalid light data
  PE_MATERIALDATA        =13 ' invalid material data

  PE_UNKNOWNREASON       =98 ' callback reason unknown
  PE_UNKNOWNERROR        =99 ' unknown error
end enum

type TCallBackProc as function (ACallBackRecord as TCallBackRecord ptr) as plugin_errors
dim shared as TCallBackProc gCallback

function ErrorMessage(e as plugin_errors) as string
  select case as const e
    case PE_NODATA             :return "No Data present."
    case PE_INVALIDVERSION     :return "Invalid Version."
    case PE_INVALIDMEM         :return "Invalid GetMem Command."
    case PE_INVALIDGET         :return "Invalid GetData Command."
    case PE_INVALIDSET         :return "Invalid SetData Command."
    case PE_INVALIDHEADER      :return "Invalid Header."
    case PE_INVALIDDATASTRING  :return "Invalid Data String."
    case PE_INVALIDDATAPROPERTY:return "Invalid Data Property."
    case PE_OBJECTDATA         :return "Error in Object Data."
    case PE_LIGHTDATA          :return "Error in Light Data."
    case PE_MATERIALDATA       :return "Error in Material Data."
    case PE_UNKNOWNREASON      :return "Unknown Callback Reason."
    case PE_UNKNOWNERROR       :return "Unknown Error."
    case else                  :return "Unknown Error Code."
  end select
end function

' This function returns a pointer to a character string containing
' the name of the plugin as being displayed in the Plugin menu with DeleD.
' Typically, this character string is between 10 and 20 characters in size.
function PluginName Alias "PluginName" as zstring ptr
  return @"the name"
end function

' This function returns a pointer to a character string containing
' the description of the plugin. This description is displayed in the
' Plugin window within DeleD.
function PluginDescription Alias "PluginDescription" as zstring ptr
  return @"the description"
end function

' This function returns a pointer to a character string showing the minimal
' version of DeleD needed to execute this plugin. DeleD uses this version
' number to determine if the plugin can be run and thus, if it should be
' listed in the Plugin menu.
function PluginDeleDVersion alias "PluginDeleDVersion" as zstring ptr
  return @"1.6"
end function

' This function returns a pointer to a character string showing the current
' version of the plugin itself.
function PluginVersion alias "PluginVersion" as zstring ptr
  return @"2.0"
end function

' This function returns a pointer to a character string showing
' the name of the author of the plugin.
function PluginAuthor alias "PluginAuthor" as zstring ptr
  return @"the author"
end function

' This function returns a pointer to a character string
' showing the emailaddress of the author of the plugin.
function PluginEmail alias "PluginEmail" as zstring ptr
  return @"the_mail@xyz.com"
end function

' At startup, DeleD initializes all available plugins and calls the
' PluginSetCallback routine automatically for each plugin.
' This procedure saves a pointer to DeleD's callback routine
' (as provided in the TCallBack parameter) into a parameter local to the plugin.
' The plugin then uses that local parameter to issue a callback to DeleD.
sub PluginSetCallback alias "PluginSetCallback" (aCallBackProc as TCallBackProc)
  gCallback=aCallBackProc
end sub

' This procedure is executed when the user executes a plugin
' from the Plugin menu within DeleD.
sub PluginExecute alias "PluginExecute"
  ' do the job here
  dim as TCallBackRecord rec
  dim as string Test
  dim as plugin_errors ret

  test=!"<request>\r\n" & _
       "   <installdirectory />\r\n" & _
       "   <primitives subset=""all"" retrieveID=""false"" />\r\n" & _
       "   <materials subset=""all"" />\r\n" & _
       "   <lights subset=""all"" retrieveID=""false"" />\r\n" & _
       "</request>"

  ' find out how much memory we need for the specific request
  rec.RequestID   = PR_GETMEM
  rec.RequestXML  = strptr(test)
  rec.ResponseSize= 0
  rec.ResponseXML = 0
  ret=gCallback(@rec)

  if ret=PE_NOERROR then
    ' now get the string
    rec.RequestID=PR_GETDATA
    rec.ResponseXML=callocate(rec.ResponseSize)
    ret=gCallback(@rec)
    if ret=PE_NOERROR then
      MessageBox(0,rec.ResponseXML,"got data from DelDe",mb_ok)
    else
      beep
      MessageBox(0,ErrorMessage(ret) & ret,"error: PE_GETDATA !",mb_ok)
    end if
  else
    beep
    MessageBox(0,ErrorMessage(ret) & ret,"error: PE_GETMEM !",mb_ok)
  end if
  if rec.ResponseXML<>0 then deallocate(rec.ResponseXML)
end sub

to build this example plugin DLL type:
fbc -Wl plugin.def -dll test01.bas

Have fun

Joshy
_________________
Sorry about my bad English!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum