Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Bitte um Hilfe [C++ -> Delphi] (https://www.delphipraxis.net/148523-bitte-um-hilfe-%5Bc-delphi%5D.html)

elyesa 3. Mär 2010 14:59


Bitte um Hilfe [C++ -> Delphi]
 
hallo,
brauche hilfe um diese funktion in delphi umzuwandeln. jedoch habe ich keine ahnung von c++.

Code:
//strstr without case
char* stristr(const char *String, const char *Pattern)
{
      char *pptr, *sptr, *start;

      for (start = (char *)String; *start != NULL; start++)
      {
            /* find start of pattern in string */
            for ( ; ((*start!=NULL) && (toupper(*start) != toupper(*Pattern))); start++)
                  ;
            if (NULL == *start)
                  return NULL;

            pptr = (char *)Pattern;
            sptr = (char *)start;

            while (toupper(*sptr) == toupper(*pptr))
            {
                  sptr++;
                  pptr++;

                  /* if end of pattern then pattern was found */

                  if (NULL == *pptr)
                        return (start);
            }
      }
      return NULL;
}
wäre echt super wenn mir jemand helfen könnte.

Der.Kaktus 3. Mär 2010 15:13

Re: Bitte um Hilfe [C++ -> Delphi]
 
Herzlich Willkommen in der :dp:

schau Dir mal in Deinem Quelltext den Kommentar
Delphi-Quellcode:
//strstr without case
an..vielleicht hilft es ja schon :wink:

SirThornberry 3. Mär 2010 15:13

Re: Bitte um Hilfe [C++ -> Delphi]
 
wie weit bist du denn bereits? Wenn wir das komplett machen ist dir rein gar nicht geholfen weil du dann immer wieder das gleiche Problem haben wirst. Fange einfach mal an und wenn du an einer konkreten Stelle nicht weiter kommst kannst du gern noch einmal nachfragen. Dann hat das auch den Vorteil das du einen aussagekräftigen Titel wählen kannst (weil du dann weißt was du wissen willst).

wie "Der.Kaktus" bereits angedeutet hat, ist es nicht immer sinnvoll Dinge eins zu eins zu übersetzen. Denn wenn man weiß was der entsprechende Quelltext macht kann man einfach schauen ob es in der Zielsprache nicht bereits etwas gibt was genau das gleiche macht.

elyesa 3. Mär 2010 16:50

Re: Bitte um Hilfe [C++ -> Delphi]
 
hello,
danke für die hinweise.

also wenn ich nach den kommentar gehe "//strstr without case" wird hier nach einem string im string gesucht.
jedoch verstehe ich nicht warum die funktion als ergebnis einen pchar zurück gibt.

diese funktion wird wie folgt aufgerufen im c++ programm:

Code:
if (stristr(rInformation.pContentType, "image/") ||
    stristr(rInformation.pContentType, "video/") ||
    stristr(rInformation.pContentType,  "audio/") ||
   (stristr(rInformation.pContentType, "application/") && !stristr(rInformation.pContentType, "java")))
  //Don't send the reply
  rServerCheck=false;*/
meint ihr es wäre ok wenn ich diese funktion mit dieser ersetze (delhi fundamentals ):

Delphi-Quellcode:
function StrPMatchLen(const P: PAnsiChar; const Len: Integer;
    const M: CharSet): Integer;
var Q: PAnsiChar;
    L: Integer;
begin
  Q := P;
  L := Len;
  Result := 0;
  While L > 0 do
    if Q^ in M then
      begin
        Inc(Q);
        Dec(L);
        Inc(Result);
      end else
      exit;
end;

function StrMatchChar(const S: AnsiString; const M: CharSet): Boolean;
var L: Integer;
begin
  L := Length(S);
  Result := (L > 0) and (StrPMatchLen(Pointer(S), L, M) = L);
end;
danke und gruss

OldGrumpy 3. Mär 2010 17:32

Re: Bitte um Hilfe [C++ -> Delphi]
 
Wie wärs stattdessen mit einer Kombination aus Lowercase() und Pos()? Wenn Dein stristr nur an der einen Stelle verwendet wird, brauchst Du Dir ja nicht die Mühe machen die gesamte Funktionalität zu implementieren.

elyesa 3. Mär 2010 17:46

Re: Bitte um Hilfe [C++ -> Delphi]
 
ja hast recht.
ich musste erstmal einen tutorial lesen um den c++ syntax einwenig zu verstehen.
danke allen die mir geantwortet haben.
ich muss nur noch eine header datei umwandeln habe es auch soweit gemacht.
wäre super wenn ihr mal schaut ob das so richtig ist.

Code:
#ifndef _DLLDef_H_
#define _DLLDef_H_

#pragma pack(push)
#pragma pack(4)

//Connection specific information
typedef struct _ConnectionInfo
{
   DWORD         dwPID;
   bool         bIncomingConnection;
   bool         bSSL;
   DWORD         dwOutgoingAddress;
   unsigned short   usOutgoingPort;
   DWORD         dwLocalAddress;   //Reserved, not implemented
   unsigned short   usLocalPort;   //Reserved, not implemented
} ConnectionInfo;

#pragma pack(pop)

//The callback function
//If the callback is called with NULL data and 0 data size it means that the socket was closed
typedef DWORD (_stdcall *DLLCallback)(const ConnectionInfo& rConnectionInfo,
                             DWORD dwID,
                             const char* pData,
                             DWORD dwDataSize,
                             bool bOutgoingData,
                             DWORD dwTickCount);
typedef DLLCallback PDLLCallback;

//Call back for HTTP decoder
//Request HTTP information
typedef struct _HTTPRequestInformation
{
   const char* pVerb; //Get, post
   const char* pURL;
   const char* pHost;
} HTTPRequestInformation;

//This will be called for HTTP request
typedef DWORD (_stdcall *DLLCallbackHTTPRequest)(const ConnectionInfo& rConnectionInfo,
                                     DWORD dwID,
                                     const HTTPRequestInformation& rInformation,
                                     const char* pRequest,
                                     DWORD dwRequestSize,
                                     DWORD dwFirstTickCount,
                                     DWORD dwLastTickCount,
                                     bool& rProcess);
typedef DLLCallbackHTTPRequest PDLLCallbackHTTPRequest;

//Reply HTTP information
typedef struct _HTTPReplyInformation
{
   DWORD      dwReplyCode;
   const char*   pContentType;
} HTTPReplyInformation;

//This will be called for HTTP reply
typedef DWORD (_stdcall *DLLCallbackHTTPReply)(const ConnectionInfo& rConnectionInfo,
                                    DWORD dwID,
                                    const HTTPReplyInformation& rInformation,
                                    const char* pReplyHeader,
                                    DWORD dwReplyHeaderSize,
                                    const char* pReply,
                                    DWORD dwReplySize,
                                    DWORD dwTotalReplyOriginalSize,
                                    DWORD dwFirstTickCount,
                                    DWORD dwLastTickCount,
                                    bool& rServerCheck);
typedef DLLCallbackHTTPReply PDLLCallbackHTTPReply;

//Callbacks to modify the data structures
//The initialize function
typedef bool (_stdcall *InitializeProto)(PDLLCallback pCallback,
                               DWORD dwReg);
typedef InitializeProto PInitializeProto;

//HTTP initialize function
typedef bool (_stdcall *InitializeHTTPProto)(PDLLCallback pCallback,
                                  PDLLCallbackHTTPRequest pRequestCallback,
                                  PDLLCallbackHTTPReply pReplyCallback,
                                  DWORD dwReg);
typedef InitializeHTTPProto PInitializeHTTPProto;

//The uninitialize function
typedef void (_stdcall *UninitializeProto)();
typedef UninitializeProto PUninitializeProto;

//The license function
typedef DWORD (_stdcall *GetInfoProto)();
typedef GetInfoProto PGetInfoProto;

//Load/save func
typedef bool (_stdcall *LoadSaveProto)();
typedef LoadSaveProto PLoadSaveProto;

//Clear data
typedef void (_stdcall *ClearDataProto)();
typedef ClearDataProto PClearDataProto;

//Enum of the add data
typedef enum _AddDataType
{
   adApplication=0,
   adPort,
   adIP,
   adApplicationInv,
   adPortInv,
   adIPInv
} AddDataType;

//Inv types
typedef enum _InvType
{
   itApp,
   itPort,
   itIP
} InvType;

//Add data
typedef void (_stdcall *AddDataProto)(AddDataType aType,
                             const unsigned short* pData);
typedef AddDataProto PAddDataProto;

//Query data
typedef bool (_stdcall *DoesDataExistsProto)(AddDataType aType,
                                  const unsigned short* pData);
typedef DoesDataExistsProto PDoesDataExistsProto;

//Set inv
typedef void (_stdcall *SetInvProto)(InvType aType,
                            bool bSet);
typedef SetInvProto PSetInvProto;

//Set inv
typedef bool (_stdcall *GetInvProto)(InvType aType);
typedef GetInvProto PGetInvProto;

#endif
so hier mein delphi code:

Delphi-Quellcode:
unit DLLDef;

interface

uses
  Windows;

  type
  {$ALIGN 4}

  ConnectionInfo = record
     dwPID:               DWORD;
     bIncomingConnection: Boolean;
     bSSL:                Boolean;
     dwOutgoingAddress:   DWORD;
     usOutgoingPort:      WORD;
     dwLocalAddress:      DWORD;   //Reserved, not implemented
     usLocalPort:         WORD;   //Reserved, not implemented
  end;
 
  PConnectionInfo = ^ConnectionInfo;
   {$ALIGN OFF}
                            
  TDLLCallback = function(rConnectionInfo: PConnectionInfo; dwID: DWORD; pData: Pointer; dwDataSize: DWORD; bOutgoingData: BOOL; dwTickcount): DWORD; stdcall;

                            
//typedef DLLCallback PDLLCallback;
HTTPRequestInformation = record
   pVerb : Pchar;
   pUrl : Pchar;
   pHost : Pchar;
end;  

pHttpRequestInformation = ^HttpRequestInformation;


TDLLCallbackHTTPRequest = function(rConnectionInfo: PConnectionInfo; dwID: DWORD; rInformation: pHttpRequestInformation; pRequest: pointer; dwFirstTickCount: DWORD; dwLastTickCount: DWORD;rProcess : Bool): DWORD; stdcall;

HTTPReplyInformation = record
  dwReplyCode= DWORD;
  pContentType= Pchar;
end;

pHTTPReplyInformation= ^HTTPReplyInformation

                                    
TDLLCallbackHTTPReply = function(rConnectionInfo: PConnectionInfo; dwID: DWORD; rInformation: pHttpRequestInformation; pReplyHeader: pointer;
dwReplyHeaderSize: DWORD; pReply: Pointer; dwReplySize: DWORD; dwFirstTickCount: DWORD; dwLastTickCount: DWORD;rServerCheck : Bool): DWORD; stdcall;
                                    
//typedef DLLCallbackHTTPReply PDLLCallbackHTTPReply;


TInitializeProto = function(pCallback: TDLLCallback; dwReg: DWORD): BOOL; stdcall;


TInitializeHTTPProto = function(pCallback: TDLLCallback; pRequestCallback: TDLLCallbackHTTPRequest;
pReplyCallback: TDLLCallbackHTTPReply; dwReg: DWORD): BOOL; stdcall;                                  
                                  
                                  
//typedef InitializeHTTPProto PInitializeHTTPProto;

TUninitializeProto = procedure; stdcall;

//typedef UninitializeProto PUninitializeProto;


TGetInfoProto = function: DWORD; stdcall;

//typedef GetInfoProto PGetInfoProto;


TLoadSaveProto = function: Bool; stdcall;

//typedef LoadSaveProto PLoadSaveProto;

TClearDataProto = procedure; stdcall;

//typedef ClearDataProto PClearDataProto;


type
   TAddDataType =
    ( const adApplication=0,
     adPort,
     adIP,
     adApplicationInv,
     adPortInv,
     adIPInv);



type
 TInvType =
   (itApp,
    itPort,
    itIP);

                            
TAddDataProto = procedure(pType: TAddDataType; pData: Pchar); stdcall;
                            
//typedef AddDataProto PAddDataProto;

                                  
TDoesDataExistsProto = function(aType: TAddDataType; pData: Pchar ): Bool; stdcall;                                   
                                  
//typedef DoesDataExistsProto PDoesDataExistsProto;

//Set inv

TSetInvProto = procedure(pType: TInvType; bSet: bool); stdcall;                            
         
//typedef SetInvProto PSetInvProto;

//Set inv
typedef bool (_stdcall *GetInvProto)(InvType aType);

TGetInvProto = function(aType: TinvType ): Bool; stdcall;                                   

//typedef GetInvProto PGetInvProto;

implementation

end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:30 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz