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?

kelvinyuAsked:
Who is Participating?
 
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:
listen
0
 
yk030299Commented:
strange. Why do I become KELVINYU?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.