Creating Delphi 7 DLL callable by LibFunc

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Creating Delphi 7 DLL callable by LibFunc

Post by adroege » Mon Mar 21, 2011 3:31 pm

I am needing to create a custom DLL in Delphi7 that can be called from within Macro Scheduler using the LibFunc> method.

My first attempt causes LibFunc> to produce an access violation and lock up Macro Scheduler.


Can someone who as done this post the Delphi source code for a very simple example to get me started on the right track?

Marcus?


Thanks.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Mar 21, 2011 3:45 pm

Make sure it is StdCall.

DLLs do not fail gracefully. Any slight error in the way you call it can lead to nasty errors.

Make sure it's stdcall, stick to simple integers and character pointers (NOT strings - use pchar).

Here's a simple Delphi DLL:

Code: Select all

library simple_dll;

uses
  SysUtils, dialogs,
  Classes;

{$R *.res}

Function MyFunction(somestring: pansichar; anumber: integer; outputbuffer: pansichar): integer; stdcall;
begin
  ShowMessage(somestring);
  StrPCopy(outputbuffer,'boo');
  result := anumber * 5;
end;

exports MyFunction name 'MyFunction';

end.
And here's the MacroScript code to use it:

Code: Select all

Let>dll=C:\...\simple_dll.dll
Let>buffer_SIZE=255
LibFunc>dll,MyFunction,res,Hello World,4,buffer
This demonstrates passing a string to the DLL, passing an integer, getting back an integer result and also passing back a string via an output buffer.

Hope this helps.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts