Source language: Translate to:

PureBasic plugin template?

Questions about NeoBook PlugIns

Moderator: Neosoft Support

PureBasic plugin template?

Postby Moonchild » Mon Jul 22, 2013 1:30 am

Hi Folks,

Been a while since I've poked around on the fora here, so bear with me :)

I have a rather specific question - I recently was forced to find a better way to do some low-level stuff from Neobook (a way to call WinAPI functions) since WMI is slow, dodgy and simply doesn't work half the time the way it is supposed to when you poke it with VBScript. I found a way to easily do this from Purebasic, in a compiled size of only 8 KB without dependencies - and instead of having to write a text file, then parse the file back in my Neobook pubs, I'd rather write a plugin for NB to pass the results back directly. However, the SDK provides powerbasic as a template, but not purebasic (and the dialects seem to differ quite a bit?). I'd look at powerbasic as an alternative but it seems the site is down, they may have folded...

Are there any people here who have a working template for nbp written in purebasic?

TIA
User avatar
Moonchild
 
Posts: 34
Joined: Mon Apr 04, 2005 12:01 pm

Re: PureBasic plugin template?

Postby Neosoft Support » Mon Jul 22, 2013 12:12 pm

I don't use either one, but unless the differences are severe, you should be able to adapt the powerbasic template to work with purebasic. Evidently, purebasic can be used to create DLLs which NeoBook plug-ins are derived from:

http://www.purebasic.com/documentation/reference/dll.html
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: PureBasic plugin template?

Postby Moonchild » Mon Jul 22, 2013 12:46 pm

Well, so far the differences seem to be quite big :/ I can probably come up with a template for purebasic myself, but I would need more information for the neobook side of things - looks like I'll have to write things from scratch.

I guess the most important things to know are:
  1. PureBasic has features for DLL building, and provides ProcedureDLL() And ProcedureCDLL() to put DLL procedures in - with the difference being the calling convention, either stdcall or C-type calls. Which one should be used for a neobook plugin?
  2. The powerbasic template has a few tweaks and ASM snippets in them which aren't really explained. would I need those, and if so, what exactly needs to be done with that?
  3. Which DLL procedures does Neobook expect to be in the nbp DLL, exactly, with which kind of parameters and which kind of return? The powerbasic framework uses "byref" and "byval" which are completely unknown to me, so i'll have to work with what I have available on the purebasic side - it seems to have all the tools for building DLLs but I need to know what is expected by the nbp framework in neobook to make it work.
  4. Would I need to define anything in the Window events AttachProcess(Instance), DetachProcess(Instance), AttachThread(Instance) and DetachThread(Instance) for using as a plugin?

If you can supply the details, I think i can come up with a reusable framework.
User avatar
Moonchild
 
Posts: 34
Joined: Mon Apr 04, 2005 12:01 pm

Re: PureBasic plugin template?

Postby Neosoft Support » Tue Jul 23, 2013 8:53 pm

1. PureBasic has features for DLL building, and provides ProcedureDLL() And ProcedureCDLL() to put DLL procedures in - with the difference being the calling convention, either stdcall or C-type calls. Which one should be used for a neobook plugin?


NeoBook was written in Delphi, so stdcall works best, but it also supports plug-ins written in C which uses cdecl.

2. The powerbasic template has a few tweaks and ASM snippets in them which aren't really explained. would I need those, and if so, what exactly needs to be done with that?


The Powerbasic template was written by one of our users, so I can't really help with that. You might try looking at the Delphi template which doesn't include any ASM.

3. Which DLL procedures does Neobook expect to be in the nbp DLL, exactly, with which kind of parameters and which kind of return? The powerbasic framework uses "byref" and "byval" which are completely unknown to me, so i'll have to work with what I have available on the purebasic side - it seems to have all the tools for building DLLs but I need to know what is expected by the nbp framework in neobook to make it work.


Byref and byval aren't terms that are used with Delphi either. Delphi parameters are defined as "var", "const", etc. Again, looking at the Delphi template may be helpful.

4. Would I need to define anything in the Window events AttachProcess(Instance), DetachProcess(Instance), AttachThread(Instance) and DetachThread(Instance) for using as a plugin?


I don't know about Purebasic, but Delphi handles the process stuff automatically so you can usually ignore it unless your DLL requires some special initialization or shutdown code. The DLL just needs to "export" the procedures and functions shown in the template so that NeoBook can call them. The plug-in help file also contains information that may be helpful, although written primarily for Delphi programmers.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: PureBasic plugin template?

Postby Moonchild » Wed Jul 24, 2013 1:23 am

Thanks for the info - I'll have a closer look at the Delphi example then -- My pascal is very rusty but I guess i can figure it out ;)

I'll keep you informed - and will share the framework once I have it working.
User avatar
Moonchild
 
Posts: 34
Joined: Mon Apr 04, 2005 12:01 pm

Re: PureBasic plugin template?

Postby Neosoft Support » Wed Jul 24, 2013 9:46 am

I'll keep you informed - and will share the framework once I have it working.


That would be great! Thanks.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: PureBasic plugin template?

Postby Moonchild » Thu Jul 25, 2013 4:27 am

Looks like it may take a while, but I'll do my best to try and make it work.
Passing parameters back and forth, also for the required nbp interface functions, is an absolute nightmare. e.g. I have no clue how to pass results back from a call made from nbExecAction to Neobook (since that in turn will call another function with its own input and output)...
Unfortunately "code by example" from the delphi example isn't as easy as I thought either. So far all I managed to get is a headache :wink:

EDIT: What confuses me most is that you aren't passing strings to procedures for things that ARE strings. You're using PChar, an address pointer to a single character... how does that work, exactly?
e.g.:
Code: Select all
TAddActionProc = PROCEDURE( IDNum      : INTEGER;
                                 Name, Hint : PChar;
                                 Params     : ARRAY OF BYTE;
                                 NumParams  : BYTE );

IDnum: pretty straight-forward. -> IDnum.i
Name, Hint: these are strings, but passed as pointers to chars? How should I read this in purebasic?
as a pointer to an object with unknown binary length? -> *Name ?
how do I determine the size of the string?
...or would this be a pointer to a string type, instead? @name$ -- and can I treat all PChars as such or not?
Params: rather self-explanatory, [type, type, type] -- I can do that in purebasic with Array A.b(1)
NumParams: no issue -> numparams.b

So, either
Code: Select all
prototype TAddActionProc(IDNum.i, *Name, *Hint, Array Params.b(1), NumParams.b)

or
Code: Select all
prototype TAddActionProc(IDNum.i, @Name$, @Hint$, Array Params.b(1), NumParams.b)

unless I'm missing something...
Last edited by Moonchild on Thu Jul 25, 2013 9:31 am, edited 1 time in total.
User avatar
Moonchild
 
Posts: 34
Joined: Mon Apr 04, 2005 12:01 pm

Re: PureBasic plugin template?

Postby Neosoft Support » Thu Jul 25, 2013 9:28 am

A PChar is a pointer to a null-terminated array of characters. The reason we PChar instead of String has to do with the way Delphi allocates memory, which is explained here: http://delphi.about.com/od/objectpascalide/l/aa103003a.htm. PChars are used for many DLLs and Windows API calls, so Purebasic should have methods for dealing with them.

A search engine (Goolge, Bing, etc.) can be very helpful when confronted with unusual programming challenges. More often than not someone else has already encountered and solved the exact same problem. For example:

https://www.google.com/search?q=purebas ... e&ie=UTF-8
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: PureBasic plugin template?

Postby Moonchild » Thu Jul 25, 2013 9:43 am

Thanks again - I guess I should do a bit more searches on purebasic + delphi ;) Sorry about that.

Just leaves me with one more issue: Most of the example code is a "one way street" -> Neobook is used to let a plugin perform some task with no or at most one return.
One of my main remaining challenges is to have the plugin perform a task and return multiple results to Neobook from a single plugin procedure.
Would I use nbSetVar in the nbp to achieve this, or should I do it another way? If I understand, nbSetVar would set a variable globally in the pub, not necessarily what I'd want -- how would I use a variable to be passed to the plugin, to return a value? Could I just write the variable passed to the plugin and Neobook would read it upon return?
User avatar
Moonchild
 
Posts: 34
Joined: Mon Apr 04, 2005 12:01 pm

Re: PureBasic plugin template?

Postby Neosoft Support » Thu Jul 25, 2013 10:45 am

The only way to return data back to NeoBook is by setting variables. Some developers use variables with fixed names for this. Others let the user pass the names of the variables by defining a variable parameter with the nbAddAction procedure. You then stuff data into the variables from the plug-in using nbSetVar. When your action returns control to NeoBook the user can examine the variable to get the data. An example in Delphi:

Code: Select all
PROCEDURE nbRegisterPlugIn( AddActionProc, AddFileProc, VarGetFunc, VarSetFunc : POINTER );
BEGIN
  ...
  {******************* Enter your Plug-In's actions below *********************}
 
   nbAddAction( 1, 'xyzDoSomething', 'This action returns a special message.', ACTIONPARAM_VARIABLE], 1 );

END;

FUNCTION nbExecAction( IDNum : INTEGER; VAR Params : ARRAY OF PChar ) : BOOLEAN;
BEGIN
  Result := FALSE;
  { Examine the Action string to determine which Plug-In command to execute... }
  CASE IDNum OF
     1 : nbSetVar( 'Params[0]', 'Plug-Ins are cool.' );
  END;
END;

Executing this action from NeoBook:

Code: Select all
xyzDoSomething "[ResultVar]"
AlertBox "Hello" "The plug-in returned: [ResultVar]"
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: PureBasic plugin template?

Postby Moonchild » Thu Jul 25, 2013 3:31 pm

Thanks, I'll be able to do something with that.
User avatar
Moonchild
 
Posts: 34
Joined: Mon Apr 04, 2005 12:01 pm


Return to PlugIn Discussions

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests