Solved

How to Call DLL's function?

Posted on 2000-03-07
11
216 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
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dev express lookupcombo 3 46
Sending files from  idTcpServer Socket to idTcpClient 2 52
Delphi: sending SMS on android platform 1 68
Microsoft Access 97 and Delphi XE2 9 74
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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