convert some code from Delphi

Just starting out? Need help? Post your questions and find answers here.
User avatar
unhappy
User
User
Posts: 19
Joined: Sat Dec 10, 2005 6:58 am
Location: Prague, Czech Republic

convert some code from Delphi

Post by unhappy »

Hi, All!

i need to write small plugin for old delphi program.
in the docs i found an example:

Code: Select all

library Plugin;

uses  windows; 

type
  tInitStruct = packed record
    FunctionCount : Cardinal;
    FunctionNames : Array of Pchar;
  End;

var
  InitStruct :  tInitStruct;   // init by plugin, free on unload

function InitPlugin(App, Scr: integer; Var Version: Real):Pointer ; stdcall;
// App: Application.Handle of UOPilot
// Scr: reserved
begin
  // exported function count, For UOPilot
  InitStruct.FunctionCount := 2;
  setlength (InitStruct.FunctionNames, InitStruct.FunctionCount);
  // exported function names
  InitStruct.FunctionNames[0] := 'Function1';
  InitStruct.FunctionNames[1] := 'Function2';
  Result := @InitStruct;
End;

Procedure DonePlugin; stdcall;
begin
  // free memory
  setlength (InitStruct.FunctionNames, 0);
End;

// exported function example
function Function1(AdressPS: Pointer): boolean ; stdcall;
begin
  Result := false;
End;

function Function2(AdressPS: Pointer): boolean ; stdcall;
begin
  Result := true;
End;

Exports
  InitPlugin,
  DonePlugin,
  Function1,
  Function2;

begin
End.
i rewrote it so:

Code: Select all

Structure tInitStruct
  FunctionCount.l 
  FunctionNames.s[2]
EndStructure 

Global InitStruct.tInitStruct
   
ProcedureDLL.l InitPlugin(App.l, Scr.l, Version.f)
  InitStruct\FunctionCount = 2;
  InitStruct\FunctionNames[0] = "Function1"
  InitStruct\FunctionNames[1] = "Function2"
  ProcedureReturn @InitStruct
EndProcedure

ProcedureDLL DonePlugin()
  InitStruct\FunctionCount = 0
EndProcedure;

ProcedureDLL.b Function1(AdressPS.l)
  ProcedureReturn true
EndProcedure;

ProcedureDLL.b Function2(AdressPS.l)
  ProcedureReturn false;
EndProcedure;
I turned this plugin on. and got a message saying that we have found two new functions through loading this plugin.
but the program was unable to find the function names.

I think the problem is that I realized the wrong line for "FunctionNames : Array of Pchar;".
please give me advice - how i can rewrite this code right?

sourcecode for delphi program is unavaible :(

thank you for your attention.
--- no signal
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: convert some code from Delphi

Post by wilbert »

I have no way of testing it but does something like this work ?

Code: Select all

Structure tInitStruct
  FunctionCount.i 
  FunctionNames.i[2]
EndStructure 

Global InitStruct.tInitStruct
   
ProcedureDLL InitPlugin(App.i, Scr.i, Version.d)
  InitStruct\FunctionCount = 2
  InitStruct\FunctionNames[0] = ?FunctionName1
  InitStruct\FunctionNames[1] = ?FunctionName2
  ProcedureReturn @InitStruct
  FunctionName1 : !db 'Function1', 0
  FunctionName2 : !db 'Function2', 0
EndProcedure

ProcedureDLL DonePlugin()
  InitStruct\FunctionCount = 0
EndProcedure

ProcedureDLL Function1(AdressPS)
  ProcedureReturn #True
EndProcedure

ProcedureDLL Function2(AdressPS)
  ProcedureReturn #False
EndProcedure
User avatar
unhappy
User
User
Posts: 19
Joined: Sat Dec 10, 2005 6:58 am
Location: Prague, Czech Republic

Re: convert some code from Delphi

Post by unhappy »

wilbert wrote:I have no way of testing it but does something like this work ?
thank you!
but this code doesnt work too :(

i want write plugin for this program: http://uopilot.ultimasoft.ru/ (version 2.27.1 support it)

plugins must be located in Plugins\ folder. then its loading be shown in menu: ? -> Log Window
and names of function listed in context menu for Script Editor textbox.
--- no signal
Post Reply