• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

How to Call DLL's function?

Hello, I want to call DLL's function at Delphi 4, I have declared the function like this:
procedure openport(n:string);external 'c:\eztt95.dll'

the program can be complied, but while executed the follow statement -- openport('0'), it show a error message--'privilege structure', whatis it mean?

I have use same DLL at VB6, it is workable. the declare statemnet is
  Private Declare Sub openport lib "c:\eztt95.dll"(ByVal command$)

the execute statement is
  call openport("0")

have I made some mistake with extrenal function declaration?

0
kelvinyu
Asked:
kelvinyu
  • 3
  • 3
  • 3
  • +1
1 Solution
 
yk030299Commented:
listen
0
 
rwilson032697Commented:
The calling convention will be wrong, and the DL won't know about the short or huge pascal string types used by Delphi.

Try declaring OpenPort like this:

procedure openport(n:PChar); stdcall; external 'c:\eztt95.dll'

Cheers,

Raymond.
0
 
yk030299Commented:
strange. Why do I become KELVINYU?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
yk030299Commented:
When I open this page, it show me that
this is my question and I am Kelvinyu
and I have 465pts only.
too strange!
0
 
kelvinyuAuthor Commented:
is it?
this question is post by me(kelvinYu)

your link may have some problem
0
 
sunsetyangCommented:
delphi can only execute dll's function dynamically by load it and execute by load the right function or procedure.
you'd better write like this:
handle=LoadLibrary('xxx.dll');
pProc=GetProcAddress(handle,'FunctionName');
ProcType(pProc)(....);
FreeLibrary(handle);
Above handle is a THandle Type variable,
pProc is a TFarProc Type variable,
ProcType is a type of your calling procedure.

0
 
rwilson032697Commented:
sunsetyang: This is not true. kelvinyu is using early binding rather than late binding so he does not need to use LoadLibrary or GetProcAddress.

Cheers,

Raymond.
0
 
sunsetyangCommented:
sunsetyang changed the proposed answer to a comment
0
 
sunsetyangCommented:
Yeah,I am wrong for the question.
Rwilson,Thank you!
0
 
rwilson032697Commented:
sunsetyang: Does the change to the declaration work for you?

Cheers,

Raymond.
0
 
kelvinyuAuthor Commented:
Rwilson,

I can call the Dll now,
thank you and thanks all

kelvin
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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