문제

아래 C ++ 예제를 사용하여 Delphi에서 DLL을 작성하고 있습니다.

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 ); 
    }
}

불행히도, 나는 C ++와 포인터에 대해 아무것도 알지 못합니다. char* (pchar?) 및 void* 대신에 무엇을 사용해야합니까?

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

exports process_message;

기능 본문에 대한 도움도 높이 평가할 것입니다. 나는 그것이 로켓 과학이 아니라는 것을 알고 있지만, 누군가가 나를 위해 그렇게하기에 충분히 친절하다면, 몇 줄을 변환하기 위해 C ++의 기본 사항을 배우지 않을 것입니다 :-)

도움이 되었습니까?

해결책

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;

테스트되지 않았지만 시작하는 데 도움이되어야합니다.

다른 팁

Rad Studio Online 문서에는 다음이 포함됩니다 델파이에서 C ++ 유형 매핑 C ++ 코드를 Delphi로 변환하는 데 도움이되는 테이블.

Delphi type         Platform    Corresponding C++ type

Boolean (Delphi)                bool (C++)
ShortInt (Delphi)               ShortInt, signed char (C++)
SmallInt (Delphi)               short (C++)
Integer (Delphi)                int (C++)
Byte (Delphi)                   Byte (C++)
Word (Delphi)                   Word (C++)
Cardinal (Delphi)               unsigned (C++)
Int64 (Delphi)                  __int64 (C++)
UInt64 (Delphi)                 unsigned __int64 (C++)
NativeInt (Delphi)  32-bit Win   int (C++)
                    64-bit Win  __int64 (C++)
                    64-bit iOS  long (C++)
NativeUInt (Delphi) 32-bit      unsigned (C++)
                    64-bit Win  unsigned __int64 (C++)
                    64-bit iOS  unsigned long (C++)
Single (Delphi)                 float (C++)
Double (Delphi)                 double (C++)
Extended (Delphi)               Extended (C++)
Currency (Delphi)               Currency, CurrencyBase (C++)
Comp (Delphi)                   Comp, CompBase (C++)
Real (Delphi)                   double (C++)
ShortString (Delphi)            ShortString, ShortStringBase (C++)
OpenString (Delphi)             OpenString (C++)
File (Delphi)                   file (C++)
Text (Delphi)                   TextFile (C++)
ByteBool (Delphi)               ByteBool (C++)
WordBool (Delphi)               WordBool (C++)
LongBool (Delphi)               BOOL (C++)
Real48 (Delphi)                 not supported in C++
Pointer (Delphi)                void* (C++)
PWideChar (Delphi)              WideChar* (C++)
PAnsiChar (Delphi)              char* (C++)
Variant (Delphi)                defined in sysvari.h (C++)
OleVariant (Delphi)             defined in sysvari.h (C++)
LongInt (Delphi)                int (C++)
                     64-bit iOS long (C++)
LongWord (Delphi)               unsigned (C++)
                     64-bit iOS unsigned long (C++)
FixedInt (Delphi)               int (C++)
FixedUInt (Delphi)              unsigned int (C++)
TextFile (Delphi)               TextFile (C++)

Pointer 데이터 유형은 정확한 C와 동일합니다 void*.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top