Solved

How to Call DLL's function?

Posted on 2000-03-07
11
213 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now