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);externa l '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?
procedure openport(n:string);externa
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?
listen
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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!
this is my question and I am Kelvinyu
and I have 465pts only.
too strange!
ASKER
is it?
this question is post by me(kelvinYu)
your link may have some problem
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.dl l');
pProc=GetProcAddress(handl e,'Functio nName');
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.
you'd better write like this:
handle=LoadLibrary('xxx.dl
pProc=GetProcAddress(handl
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.
Cheers,
Raymond.
sunsetyang changed the proposed answer to a comment
Yeah,I am wrong for the question.
Rwilson,Thank you!
Rwilson,Thank you!
sunsetyang: Does the change to the declaration work for you?
Cheers,
Raymond.
Cheers,
Raymond.
ASKER
Rwilson,
I can call the Dll now,
thank you and thanks all
kelvin
I can call the Dll now,
thank you and thanks all
kelvin