Thema: Delphi C-Funktion einbinden

Einzelnen Beitrag anzeigen

Benutzerbild von emsländer
emsländer

Registriert seit: 21. Aug 2004
Ort: Lengerich
658 Beiträge
 
RAD-Studio 2009 Ent
 
#1

C-Funktion einbinden

  Alt 29. Jul 2009, 22:49
Moin,

wie kann ich folgende C-Funktion in ein Delpi-Prog oder als Komponente wie auch immer einbinden?

Delphi-Quellcode:
void GetWindowsKey(BOOL is64 = false)
{
    if (is64) {
        #define WIN64KEY
    }

   char* wsResult; //Return a Window Product Key
   HKEY hRegistryKey; //Registry Handler
   BYTE *DigitalProductID = 0; //Digital Product Key Value
   DWORD DataLength; //Digital Product Key Length
   BYTE ProductKeyExtract[15]; //Extract Key
   char sCDKey[30]; //Temp, adding a Window Product Key
   int ByteCounter; //Counter
   int k; //Convert
   int nCur; //XOR calculate
   bool bOk = false;

   const char *KeyChars[] = {
      "B","C","D","F","G","H","J","K","M",
      "P","Q","R","T","V","W","X","Y",
      "2","3","4","6","7","8","9",NULL
   }
;

   const char NT_CURRENT[] = "SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion";
   #ifdef WIN64KEY
      #ifdef KEY_WOW64_64KEY
      #else
         #define KEY_WOW64_64KEY 0x0100
      #endif
   if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, NT_CURRENT,
      REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_WOW64_64KEY,
      &hRegistryKey) == ERROR_SUCCESS )
   #else
   if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, NT_CURRENT,
      REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
      &hRegistryKey) == ERROR_SUCCESS )
   #endif
   {
      DataLength = 164;
      //Allocate Memory
      DigitalProductID = new byte[DataLength];

      //Memory Initialization
      memset(DigitalProductID, 0, DataLength);

      //Digital Product
      if( RegQueryValueEx(hRegistryKey, "DigitalProductId",
        NULL, NULL, DigitalProductID, &DataLength) == ERROR_SUCCESS )
      {
        //reading a value start position 52, by 66
        memcpy(ProductKeyExtract, DigitalProductID+52, 15);
        bOk = true;
      }


      //Release Memory
      if(DigitalProductID) delete []DigitalProductID;

      //Close Registry
      RegCloseKey(hRegistryKey);
   }

   if( !bOk )
      printf(wsResult);

   //Start Converting job, Next Step
   memset(sCDKey, 0, sizeof(sCDKey));

   for(ByteCounter=24; ByteCounter >= 0; --ByteCounter)
   {
      nCur = 0;

      for(k=14; k >= 0; --k)
      {
        nCur = (nCur * 256) ^ ProductKeyExtract[k];

        ProductKeyExtract[k] = nCur / 24;
        nCur %= 24;
      }


      strcat(sCDKey, KeyChars[nCur]);

      //Insert "-"
      if( !(ByteCounter % 5) && ByteCounter )
         strcat(sCDKey, "-");
   }

   _strrev(sCDKey);
   wsResult = sCDKey;
   char *pch;
   pch = strstr(wsResult, "-");
   if (pch != NULL) {
      printf(wsResult);
   }
 else {
      GetWindowsKey(true);
   }

#ifdef WIN64KEY
#undef WIN64KEY
#endif
}
Gruss

EL


Narben am Körper sind ein Zeichen dafür, das man gelebt hat.
Narben auf der Seele sind ein Zeichen dafür, das man geliebt hat.
  Mit Zitat antworten Zitat