Solved

How to Call DLL's function?

Posted on 2000-03-07
11
218 Views
Last Modified: 2010-08-05
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
Comment
Question by:kelvinyu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 1

Expert Comment

by:yk030299
ID: 2594256
listen
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 2594262
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
 
LVL 1

Expert Comment

by:yk030299
ID: 2594288
strange. Why do I become KELVINYU?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:yk030299
ID: 2594291
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
 

Author Comment

by:kelvinyu
ID: 2594326
is it?
this question is post by me(kelvinYu)

your link may have some problem
0
 

Expert Comment

by:sunsetyang
ID: 2594687
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2594876
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
 

Expert Comment

by:sunsetyang
ID: 2598751
sunsetyang changed the proposed answer to a comment
0
 

Expert Comment

by:sunsetyang
ID: 2598757
Yeah,I am wrong for the question.
Rwilson,Thank you!
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2598767
sunsetyang: Does the change to the declaration work for you?

Cheers,

Raymond.
0
 

Author Comment

by:kelvinyu
ID: 2610535
Rwilson,

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

kelvin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question