[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

DLL newbie-Calling DLL function crashes app

Hello Experts;

Trying to use a simple DLL function (written in C) that returns the DLL version number, more-or-less.

The text from the documentation file reads:
=====================================================
Name:  DLL_Version
Description: fills the array with the current DLL version number.
             for ALL beta version this will be fixed as V1.0.b
             As son as production starts this version will become
             V1.0.0 and will be maintained from then.
Entry Parameters: Pointer to a 5 byte array
Returns: none

void DLL_Version ( LPSTR )

Example:  DLL_Version ( array );

          Upon return the array contains the function as a string.
=====================================================

I've put the following into an application:

//////////
var
  Form1: TForm1;
  DLLVersionNumber : array[0..4] of char;

implementation

{$R *.DFM}

Function DLL_Version(LPSTR : array of char):pointer; stdcall; external 'THE.dll';

procedure TForm1.DLLVersion1Click(Sender: TObject);
begin
  DLL_Version(DLLVersionNumber);
  label1.caption := DLLVersionNumber;
end;
//////////

Whenever I use it, it causes an invalid page fault.  Setting a breakpoint and looking at the value of "DLLVersionNumber" shows the correct string.  So what am I doing wrong?

Thanks in advance...

Paul
0
prstein
Asked:
prstein
  • 3
  • 2
1 Solution
 
rwilson032697Commented:
I think you need to make sure the function in the DLL you are calling really is stdcall (it coulf be cdecl, or pascal), and change your declarations like this:

type
 TDLLVersionNumber = array[0..4] of char;
var
  Form1: TForm1;
  DLLVersionNumber : TDLLVersionNumber;

implementation

{$R *.DFM}

Procedure DLL_Version(LPSTR : TDLLVersionNumber); stdcall; external 'THE.dll';

Cheers,

Raymond.
0
 
rwilson032697Commented:
Oops, this line:

Procedure DLL_Version(LPSTR : TDLLVersionNumber); stdcall; external 'THE.dll';

Should read:

Procedure DLL_Version(var LPSTR : TDLLVersionNumber); stdcall; external 'THE.dll';

Cheers,

Raymond.
0
 
prsteinAuthor Commented:
Thanks for the quick response.  Regrettably, the application still crashes at the same point.

Regards,

Paul
0
 
prsteinAuthor Commented:
Hello Raymond;

Whoops!!!  Should have read the WHOLE thing before trying and rejecting...

Works perfectly now, and I consider the points very well spent. Thankyouthankyouthankyou...

Regards,

Paul
0
 
rwilson032697Commented:
Glad I could help!

Cheers,

Raymond.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now