The example given here contains, at least, incorrect error handling code. Following code:
// enable or disable privilege
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
DisplayError(TEXT("AdjustTokenPrivileges"), GetLastError());
should be replaced with something like:
// enable or disable privilege
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
DisplayError(TEXT("AdjustTokenPrivileges"), GetLastError());
DWORD dwLasError = GetLastError();
if (dwLasError != ERROR_SUCCESS)
DisplayError(TEXT("AdjustTokenPrivileges"), dwLasError);
Also, note that AdjustTokenPrivileges does not grant new privileges to a user, it just enables/disables already granted ones. So, in order to grant the user SeLockMemoryPrivilege, you would have to use either gpedit.msc or programmatically something like that: http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q132958
By default, SeLockMemoryPrivilege is not granted to any user, don't forget that you will have either to reboot your server after granting the privilege if your application is running under system account (Local Service or Network Service) or logoff/logon if your app is running under dedicated account.