Board index » delphi » Help with calling a function in a DLL.

Help with calling a function in a DLL.

Hi there.  I have always had problems with pointers and whatnot, so I
was wondering if any of you could help me. I have a record structure
like this:

type
    InitStruct = record
        gsVersion : DWord;
        options : DWord;
        Paths : array [0..256] of Char;
    end;

type
    pInitStruct = ^InitStruct;

then I have a function that uses these :

Function Init_Now(IR:pInitStruct):ID; stdcall;  external 'blah.dll';

Can anyone give me an example of how in my code I would call this
function?  I tried creating a var that was type InitStruct but that and
other variations failed...  I think I am typecasting wrong or something.

Thanks!

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:Help with calling a function in a DLL.


Quote
On Wed, 06 Dec 2000 21:50:17 GMT, ocken...@my-deja.com wrote:
>Hi there.  I have always had problems with pointers and whatnot, so I
>was wondering if any of you could help me. I have a record structure
>like this:

>type
>    InitStruct = record
>        gsVersion : DWord;
>        options : DWord;
>        Paths : array [0..256] of Char;
>    end;

>type
>    pInitStruct = ^InitStruct;

>then I have a function that uses these :

>Function Init_Now(IR:pInitStruct):ID; stdcall;  external 'blah.dll';

>Can anyone give me an example of how in my code I would call this
>function?  I tried creating a var that was type InitStruct but that and
>other variations failed...  I think I am typecasting wrong or something.

Assuming you've got the import declaration correct it's pretty simple,
depending on your needs you can do it either dynamically or
statically:

//dynamic approach
var
  PIS: pInitStruct;
begin  
  New(PIS);
  PIS^.gsVersion := 1;
  // etc.
  InitNow(PIS);
  ...
  Dispose(PIS);

//static approach
var
  IS: InitStruct;
begin  
  IS.gsVersion := 1;
  // etc.
  InitNow(@IS);
  ...

HTH

Stephen Posey
slpo...@concentric.net

Re:Help with calling a function in a DLL.


Thank You very much!  I was forgetting the New() and Dispose()
functions.  My knowledge of pointers is quite limited.

Thanks again!

Sent via Deja.com http://www.deja.com/
Before you buy.

Other Threads