AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Bitte um Hilfe [C++ -> Delphi]

Ein Thema von elyesa · begonnen am 3. Mär 2010 · letzter Beitrag vom 3. Mär 2010
Antwort Antwort
elyesa

Registriert seit: 15. Apr 2005
8 Beiträge
 
#1

Bitte um Hilfe [C++ -> Delphi]

  Alt 3. Mär 2010, 14:59
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.
  Mit Zitat antworten Zitat
Benutzerbild von Der.Kaktus
Der.Kaktus

Registriert seit: 22. Jan 2008
Ort: Erfurt
958 Beiträge
 
Delphi 7 Enterprise
 
#2

Re: Bitte um Hilfe [C++ -> Delphi]

  Alt 3. Mär 2010, 15:13
Herzlich Willkommen in der

schau Dir mal in Deinem Quelltext den Kommentar
//strstr without case an..vielleicht hilft es ja schon
Gruss Kaki

Repeat Until true=false;
  Mit Zitat antworten Zitat
Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#3

Re: Bitte um Hilfe [C++ -> Delphi]

  Alt 3. Mär 2010, 15:13
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.
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat
elyesa

Registriert seit: 15. Apr 2005
8 Beiträge
 
#4

Re: Bitte um Hilfe [C++ -> Delphi]

  Alt 3. Mär 2010, 16:50
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
  Mit Zitat antworten Zitat
Benutzerbild von OldGrumpy
OldGrumpy

Registriert seit: 28. Sep 2006
Ort: Sandhausen
941 Beiträge
 
Delphi 2006 Professional
 
#5

Re: Bitte um Hilfe [C++ -> Delphi]

  Alt 3. Mär 2010, 17:32
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.
"Tja ja, das Ausrufezeichen... Der virtuelle Spoiler des 21. Jahrhunderts, der Breitreifen für die Datenautobahn, die k3wle Sonnenbrille fürs Usenet. " (Henning Richter)
  Mit Zitat antworten Zitat
elyesa

Registriert seit: 15. Apr 2005
8 Beiträge
 
#6

Re: Bitte um Hilfe [C++ -> Delphi]

  Alt 3. Mär 2010, 17:46
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.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:15 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