Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling a DLL

Posted on 2002-04-16
12
Medium Priority
?
216 Views
Last Modified: 2010-04-04

The function you are looking for is called cq_calc, and you can find it
by looking for "cq_calc" in that case.

This function has the exact (C/C++) prototype:  char* cq_calc(char*);

You send cq_calc a pointer to a character.


I can't call that routine without getting a mem error

the Dll if you would like to try for yourself is here:

http://geocities.com/tcjdelphi/tjc.zip
0
Comment
Question by:craig_capel
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 100 total points
ID: 6945483
The conversion is
function cq_calc(Param: PChar): PChar; stdcall; external 'TheDll.DLL';
or
function cq_calc(Param: PChar): PChar; cdecl; external 'TheDll.DLL';

Call it like this:

var
  Buffer: array[0..SomeMaxValue] of Char;
  RetVal: PChar;
begin
  // initialize buffer if needed
  RetVal := cq_calc(@Buffer[0]);

I would guess that RetVal points somewhere into the buffer.

0
 
LVL 2

Author Comment

by:craig_capel
ID: 6945550
how do you conver it to a string?

Function CqCalc(calcst: String): String;
var
 Buffer: array[0..255] of Char;
 RetVal: PChar;
begin
  // initialize buffer if needed
    Buffer:=CalcSt;
    RetVal := cq_calc(@Buffer[0]);
End;


Thanks for your help so far, nearly got it :)
0
 
LVL 2

Author Comment

by:craig_capel
ID: 6945597
how do you conver it to a string?

Function CqCalc(calcst: String): String;
var
 Buffer: array[0..255] of Char;
 RetVal: PChar;
begin
  // initialize buffer if needed
    Buffer:=CalcSt;
    RetVal := cq_calc(@Buffer[0]);
End;


Thanks for your help so far, nearly got it :)
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 2

Author Comment

by:craig_capel
ID: 6945673
Function CqCalc(calcst: String): String;
var
 Buffer: array[0..255] of Char;
 RetVal: PChar;
 I: Integer;
begin
  // initialize buffer if needed
    CalcSt:=CalcSt+#$0;
    move(calcst[1],buffer,length(calcst));
    I:=Length(CalcSt);
    RetVal := cq_calc(@Buffer[0]);
    move(RetVal,Result,Length(CalcSt));
    Result:=Copy(Result,0,pos(#$0,Result)-1);
End;

ok that works for me, but is there a better way, when i try setlength like SetLength(Buffer,Length(CalcSt)); it says something about not able to pass a Delphi  object?

ok can you improve that code? - the points are yours anyhow, i just want to help me understand this better... thank you

-

Craig C.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 6945821
oops that code gives me an error :((
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6945826
var
  s: string;
begin
  ...
  S := RetVal;

0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6946265
or simply do :

Function CqCalc(calcst: String): String;
begin
  SetLength(Result, 255);  
  Result := string(cq_calc(PChar(calcst)));
End;
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6946531
String := StrPas(PChar)

So:

Function CqCalc(calcst: String): String;
begin
   Buffer:=CalcSt;
   Result := StrPas(cq_calc(pChar(CalcST)));
end;

Easy! :)

Stu
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6946994
stuart: StrPas is fo backward compatibility
you should use typecasting now
and what  is buffer in your case ? :)
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6947003
Well I'll be!  I've been using that function for so many years I don't think I could stand to be without it!  It's the first time that I've looked at in the help file.

Can you tell me why it's been made redundant?

Stu
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6947010
Strangely enough, Lee, you're comment wasn't even there when I posted mine.  Even though there was almost an hour between the postings.
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6947111
The assignment of a PChar to a string nowadays takes care of converting.
0

Featured Post

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.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

926 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