CallDll

Blitz3D Forums/Blitz3D Beginners Area/CallDll

I have created a DLL with Delphi. It is a file requestor. It works fine with Darkbasic (the fileselector dialog appears, I can select a file, The file path and name are returned to darkbasic) , but when I try to use it with BlitzBasic it works up to the point of selecting a file. The file path and name do not return to Blitzbasic. Only a number is returned. I can select the same file over and over again and get a different number each time. How do I get Blitzbasic to return a string from a dll? What am I doing wrong.

Thanks
RestKrat

Post some code.

Here is the delphi code:

library FormDLL;

uses
Unit1 in 'Unit1.pas' {Form1};

exports
getfile;

end.


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

function getfile (fis: Pchar) : pchar; stdcall;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
opendialog1.Execute;
end;

function getfile (fis: Pchar) : pchar; stdcall
var
Form1 : TForm1;
begin
Form1 := Tform1.Create (application);
form1.OpenDialog1.Execute;
end;

end.


Here is the Blitzbasic code:

While Not KeyHit(1)

If KeyDown ( 32 )=True Then
s$=CallDLL("i:\programs code\darkpro\testdll\FormDll.dll","getfile")
EndIf

Text 10,130,"Return " + s$
Flip
Wend
End

It's probably a pointer to a string (character). If you absolutely must use CallDLL (i.e. if you just have BlitzBasic) then you'll probably have to use RtlMoveMemory (kernel32) to copy the contents of the memory buffer that's being pointed to.

If he has just BlitzBasic, he can't use RtlMoveMemory() as it hasn't WinAPI support either. :)

Ah, I'm glad we have userlib support now.

CallDLL, I never knew thee, and never I shall...

wouldn't he have to create a user.decls file with the "getfile" call?