2009-09-14 4 views
2

나는 아래의 C++ 예제를 사용하여 델파이에서 DLL을 쓰고 있어요 :C++ 함수를 Delphi로 변환 : void * 매개 변수와 함께 할 일?

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; 

본문 기능에 대한 도움도 매우 감사하겠습니다. 나는 로켓 과학은 아니지만 누군가가

+3

C++의 기본 사항을 배우는 것은 해당 코드를 번역해야하는지 여부에 관계없이 수행해야하는 작업입니다. Delphi로 작업하면 Windows에서 작업하고 Windows에서 작업하는 경우 C 및 C++를 읽는 방법을 알아야합니다. 거의 모든 문서는 해당 언어로 제공되기 때문입니다. 당신이하지 않으면, 당신은 단지 모래에 머리를 고집하고있어. –

+1

좋은 지적입니다, 롭. 그것은 제가 전문 소프트웨어 개발자가 아니란 것입니다. 필자는 일반적으로 로직을 수행하며 Delphi의 기본 제공 구성 요소만으로도 충분합니다. 드문 경우 였지만 그 이상의 것을 처리해야했습니다. 칭찬 stackoverflow :-) – Mikhail

답변

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

테스트되지 않은 :-) 나를 위해 그렇게 친절하게도 내가 만약, 그냥 몇 줄을 변환하는 C++의 기초를 배울 것 알지만에 도움이 될 것입니다 너 시작 했어.

5

Pointer 데이터 유형은 C void*과 정확히 같습니다.

10

RAD Studio 온라인 문서에는 C++ 코드를 Delphi로 변환하는 데 도움이되는 Delphi to C++ types mapping 테이블이 포함되어 있습니다.

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++) 
관련 문제