Protection API - SDP_SetRegistrationKey


SDP_SetRegistrationKey

The SDP_SetRegistrationKey passes the registration key to SDProtector. This function allows to keep registration keys in any place and in any format.

  For C++:

        LPSTR __declspec(dllexport) SDP_SetRegistrationKey();

  For Delphi:

      function SDP_SetRegistrationKey: PChar;stdcall;
exports SDP_SetRegistrationKey;

Parameters
lpdwNum

This function has no parameters.

Return Values
Points to the buffer that holds registration key

Remarks
The string passed to SDProtector should not contain more than 192 character.
Example
for C/C++

    // This sample reads the key from key.txt file, which is located in the application folder.


extern "C" LPSTR __declspec(dllexport) SDP_SetRegistrationKey() { HANDLE hFile; DWORD dFileSize; DWORD dReadSize; char *p; static char szKey[192]; char szFileName[MAX_PATH];
if(!GetModuleFileName(NULL,szFileName,MAX_PATH))
{ return NULL; }
p=strrchr(szFileName,'\\'); if(!p) { return NULL; } *p='\0'; strcat(szFileName,"\\key.txt"); memset(szKey,0,192); hFile=CreateFile(szFileName,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE
,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
return NULL; }
dFileSize=GetFileSize(hFile, NULL);
if(dFileSize==-1||dFileSize>=192)
{ CloseHandle(hFile);
return NULL;
} if(!ReadFile(hFile,szKey,dFileSize,&dReadSize,NULL))
{ CloseHandle(hFile);
return NULL;
} CloseHandle(hFile); if(dFileSize!=dReadSize) { return NULL; }

return (LPSTR)szKey;
}


for Delphi

    // This sample reads the key from key.txt file, which is located in the application folder.

var
Key : Pointer;

function SDP_SetRegistrationKey: PChar;stdcall;
var
FileName : String;
begin
Result := '';
try
FileName := ExtractFilePath(ParamStr(0))+'key.txt';
with TFileStream.Create(FileName, fmOpenRead) do
try
GetMem(szKey, Size+1);
FillChar(szKey^, Size+1, 0);
Read(szKey^,Size);
finally
Free;
end;
Result := szKey;
except
end;
end;
exports SDP_SetRegistrationKey;

Sample application is located in \Examples\Delphi\API\ and \Examples\VC\API\ directory.
 
CopyRight(C) 2003 SDProtector.com All Rights Reserved