![]() |
C-Funktion einbinden
Moin,
wie kann ich folgende C-Funktion in ein Delpi-Prog oder als Komponente wie auch immer einbinden?
Delphi-Quellcode:
Gruss
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 } EL |
Re: C-Funktion einbinden
Pack sie in eine DLL und exportier die Funktion. Oder schreib sie nach Delphi um.
|
Re: C-Funktion einbinden
Zitat:
wie mache ich das "Packen in eine DLL" ? Von mir aus würde mir da auch reichen das als C-Proggi im Rad Studio 2009 zu machen. Gruss EL |
Re: C-Funktion einbinden
Nimm dir eine IDE mit C Kompiler und erstell eine DLL. Details solltets du in entsprechenden Tutorials im Internet finden.
|
Re: C-Funktion einbinden
Was willst Du eigentlich mit dem Windows-Product-Key? :stupid:
|
Re: C-Funktion einbinden
Zitat:
Zwei Minuten Suche mit der bekannten suchmaschiene hätte das zu Tage bringen können: ![]() ;) |
Re: C-Funktion einbinden
Zitat:
Der Code von swissdelphicenter funktioniert nicht bei Vista und 64 Bit Systemen Gruss EL |
Re: C-Funktion einbinden
Zitat:
also brauchst du ein Utility (oder eine Anweisung, es geht ja auch ohne zusätzliche Software), aber nicht unbedingt sowas exotisches wie eine Delphi-Funktion. Solche Utilities gibt es unzählige, Google listet sie gerne auf. Gruss Reinhard |
Re: C-Funktion einbinden
Zitat:
Gruss EL |
Re: C-Funktion einbinden
Also wenn es unter 64-Bit laufen soll, dann brauchst du auch einen 64 Bit Compiler für die DLL und dein Delphi Programm.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:31 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz