Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to call a function in a DLL in Delphi 3?

Posted on 1998-09-01
11
Medium Priority
?
176 Views
Last Modified: 2010-04-04
Hi all... I have made a DLL in C language with the following function:

UINT WINAPI Desasm( UINT current, LPSTR target, LPSTR start );

(UINT = Unsigned int, LPSTR = Long pointer String)

The question is.. how can I declare such function in Delphi? I have:

function Desasm( Address: Integer; Target : string; Start : PChar): Integer; external 'Desasm.dll';

just after starting implementation part of the unit.

Later in other function I tried to call it this way:

var
  Texto : string;
  Buf   : array[0..19] of Char;

begin
  Buf[0] := #18;
  Buf[1] := #00;
  Buf[2] := #38;
  Desasm( 0, Texto, Buf );
  ShowMessage( Texto );
end;

The fact is that Texto must contain a string, but on return, it contains nothing. If I try to use stdcall in declaration of the function, application crashes.

Note: the DLL does work!

Who can help me?
Thanks in advance

Jaime
0
Comment
Question by:skel
[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
  • 6
  • 3
  • 2
11 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1338408
What's the function doing....which is the return value.....???
0
 

Accepted Solution

by:
kashif063098 earned 100 total points
ID: 1338409
answer is coming
0
 

Author Comment

by:skel
ID: 1338410
It's a dissasembler.

Address is the address of the instruccion
Target is the string receiving the mnemonic
Start is the buffer containing de opcode and operand

It's return the number of operands required for the instruction in ordder to know where the next instruction starts.

But I think it doesn't care about what the function actually does, because of encasulation... the problem is communication de delphi program with the library.
0
Technology Partners: 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 10

Expert Comment

by:viktornet
ID: 1338411
kashif I was just wondering why do you answer a question w/o having the answer...If you somehow don't supply any answers then the person cannot delete the file if he/she wants to

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338412
var
  I : UINT;//you can make a decalration like this one since there is UINT type in Delphi.///
----------------
function Desasm( Address: UINT; Target : PChar; Start : PChar): UINT; external 'Desasm.dll';

Why don't you try this.....??? and see if itworks

Regards,
Viktor Ivanov
0
 

Expert Comment

by:kashif063098
ID: 1338413
Sorry ,i am having some problems .....

0
 

Author Comment

by:skel
ID: 1338414
I have finally solved the problem declaring the function in the DLL as:

function Desasm( Address: UINT; Target : pointer; Start : pointer): UINT; stdcall;
         external 'Desasm.dll';

and then, calling it with

var
  Texto : array[0..255] of char;
  Buf   : array[0..19] of Byte;

begin
  Buf[0] := $12;
  Buf[1] := 00;
  Buf[2] := $26;
  Desasm( 0, @Texto, @Buf );
  .
  .
  .
end;

is there a more elegant solution? any suggestion?

Jaime
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338415
I'm not sure if you need to do this..... @Texto @Buf...what you could try doing which is almost the same is this........
var
   Texto, Buf : String;
     begin
       Buf[1] := $12;
       Buf[2] := 00;
       Buf[3] := $26;
       Desasm( 0, PChar(Texto), PChar(Buf) );
//In the first example here is what's wrong..
you wrote..Desasm( 0, Texto, Buf ); and it is suppose to be
Desasm( 0, PChar(Texto), Buf );//That's what was wrong with you function....You need to typecast the String to a PChar...which is same as declaring an array of char :+)

But still it's the same idea and maybe more writing...so you better stick to your way ;-)
Otherwise..is everything working properly now?

Regards,
Viktor Ivanov
0
 

Author Comment

by:skel
ID: 1338416
I tried that but it didn't work... the fact is that the string definition is different between C and Pascal. In C it starts from 0, while in Pascal starts from 1, with the 0 reserved for the string length. I think that is the problem.

Regarding with buf variable.. it must be an array of bytes.... I made a mistake in my first post.

Thanks for your posts
Jaime
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338417
That's what I meant kashif... I really think that your answer was best...Keep the good work...

vik
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338418
What I meant is at least I tried to help you and kashif's answer was "Answer is coming...". That doesn't look like an answer to me. Maybe I didn't give you the right answer but at least tried, and I think that's important. Anyway, I think it's (*GrEaT*) that you got your function working!
Talk to you later! Bye

{The example I gave you should work. I might have missed something small since I wrote it right on E-E, and haven't checked it with Delphi, but I'm sure it will work if something small is corrected =)

Regards,
Viktor Ivanov
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

604 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