Link to home
Create AccountLog in
Avatar of kelvinyu
kelvinyu

asked on

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?

Avatar of yk030299
yk030299

listen
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
strange. Why do I become KELVINYU?
When I open this page, it show me that
this is my question and I am Kelvinyu
and I have 465pts only.
too strange!
Avatar of kelvinyu

ASKER

is it?
this question is post by me(kelvinYu)

your link may have some problem
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.

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.
sunsetyang changed the proposed answer to a comment
Yeah,I am wrong for the question.
Rwilson,Thank you!
sunsetyang: Does the change to the declaration work for you?

Cheers,

Raymond.
Rwilson,

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

kelvin