[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to Call DLL's function?

Posted on 2000-03-07
11
Medium Priority
?
222 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 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

650 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