Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointers and memory and stuff... 1

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
Hi, I'm coding a quick example of a program for someone and part of what I want it to do requires that it passes a large amount of text to a function in a dll. I guess that creating an area in memory, sticking the text in there and then passing a pointer to it to the dll function would be the best way to do it, but I have no idea how to use pointers in Delphi. I have a vague idea how to do it in c++, but that would cause other problems.

Basically, I was wondering if anyone could explain how to do this, or show me some example code so I can figure it out myself, or anything at all.

In fact, if there's a better way to do it then any suggestions are welcome.

Thanks.
 
passing strings towards dll's is best done via PChars or shortstrings (255 chars max). if the dll is yours (eg made in delphi) and both your project and dll have unit Sharemem in the 'uses' clause, you can pass "normal" (big)stringtypes to dll functions and procedures.

greetings,

 
Well.... I don't want to use ShareMem and I want to pass in what could potentially be a LOT of text.
 
I wrote a little sample app :

here's to code interfacing with the dll :

unit Unit1;

interface

uses
Windows, Classes, Forms, Controls, StdCtrls, Sysutils;

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

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

type Tlibfunc = procedure(txt : pchar);

var exepath : string;
temp : pchar;
libraryid : integer;
libfunc : tlibfunc;

begin
ExePath := ExtractFilePath(Application.ExeName);
Temp := PChar(ExePath+'s1.dll');
LibraryID := LoadLibrary(Temp);
If LibraryID > 0 then
begin
@Libfunc:=GetProcAddress(libraryid, 'transfertext');
if @libfunc <> nil then libfunc(pchar('cool'));
end;
end;

end.


and here's the dll :

Library s1;

uses dialogs;


procedure transfertext(txt : pchar);

begin
showmessage(string(txt));
end;

exports transfertext;


End.

greetings,

 
k, thanks, should be able to figure stuff out from a combination of that and what I know from c++
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top