views:

622

answers:

3

I'm writing a DLL in Delphi using the below C++ example:

USERDLL_API double process_message (const char* pmessage, const void* param) 
{
    if (pmessage==NULL) { return 0; }
    if (param==NULL) { return 0; }

    if (strcmp(pmessage,"state")==0) 
    { 
     current_state *state = (current_state*) param;
     return process_state( (current_state*)param ); 
    }
}

Unfortunately, I know next to nothing about C++ and pointers. What should I use instead of char* (PChar?) and void*?

function process_message (const pmessage: PChar; const param: ???): Double; export;
begin
    ???
end;

exports process_message;

Any help with the body of the function will be highly appreciated, too. I realize it's not rocket science, but I wouldn't learn the basics of C++ just to convert a couple of lines, if someone's kind enough to do that for me :-)

+6  A: 
function process_message (const pmessage: PChar; const param: Pointer): Double; export; stdcall;
begin
    If (pmessage = nil) Or (param = nil) Then
        Result := 0;
    Else If StrComp(pmessage, 'state') = 0 Then
       Result := process_state(current_state^(param));

    // missing a return statement for cases where pmessage is not 'state' here!
end;

exports process_message;

Untested, but should help to get you started.

KiNgMaR
+3  A: 

Pointer datatype is an exact equivalent of C void*.

sharptooth
+5  A: 

Mikhail here you have these links with the types between Delphi and C/C++

Table of C++ and Delphi data types

http://www.drbob42.com/delphi/headconv.htm

Delphi   C/C++

ShortInt short
Byte     BYTE
char     unsigned short
Integer  int
Word     unsigned int
LongInt  long
Comp     unsigned long
Single   float
Real     None
Double   double
Extended long double
Char     char
String   None
pChar    char
Bool     bool
Boolean  Any 1byte type
Variant  None
Currency None
PChar       char*
PChar       LPSTR or PSTR
PWideChar   LPWSTR or PWSTR
Pointer     void*

Bye.

RRUZ