本文整理汇总了C++中BaseSetLastNTError函数的典型用法代码示例。如果您正苦于以下问题:C++ BaseSetLastNTError函数的具体用法?C++ BaseSetLastNTError怎么用?C++ BaseSetLastNTError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BaseSetLastNTError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetTimeZoneInformation
/*
* @implemented
*/
BOOL
WINAPI
SetTimeZoneInformation(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation)
{
NTSTATUS Status;
DPRINT("SetTimeZoneInformation()\n");
Status = RtlSetTimeZoneInformation((LPTIME_ZONE_INFORMATION)lpTimeZoneInformation);
if (!NT_SUCCESS(Status))
{
DPRINT1("RtlSetTimeZoneInformation() failed (Status %lx)\n", Status);
BaseSetLastNTError(Status);
return FALSE;
}
Status = NtSetSystemInformation(SystemCurrentTimeZoneInformation,
(PVOID)lpTimeZoneInformation,
sizeof(TIME_ZONE_INFORMATION));
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetSystemInformation() failed (Status %lx)\n", Status);
BaseSetLastNTError(Status);
return FALSE;
}
return TRUE;
}
示例2: GetCurrentActCtx
/*
* @implemented
*/
BOOL
WINAPI
GetCurrentActCtx(OUT PHANDLE phActCtx)
{
NTSTATUS Status;
/* Check if the output handle pointer was invalid */
if (phActCtx == NULL)
{
/* Set error and bail out */
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
return FALSE;
}
/* Call the native API */
Status = RtlGetActiveActivationContext(phActCtx);
if (!NT_SUCCESS(Status))
{
/* Set error and bail out */
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
return FALSE;
}
/* It worked */
return TRUE;
}
示例3: DebugSetProcessKillOnExit
/*
* @implemented
*/
BOOL
WINAPI
DebugSetProcessKillOnExit(IN BOOL KillOnExit)
{
HANDLE Handle;
NTSTATUS Status;
ULONG State;
/* Get the debug object */
Handle = DbgUiGetThreadDebugObject();
if (!Handle)
{
/* Fail */
BaseSetLastNTError(STATUS_INVALID_HANDLE);
return FALSE;
}
/* Now set the kill-on-exit state */
State = KillOnExit != 0;
Status = NtSetInformationDebugObject(Handle,
DebugObjectKillProcessOnExitInformation,
&State,
sizeof(State),
NULL);
if (!NT_SUCCESS(Status))
{
/* Fail */
BaseSetLastNTError(Status);
return FALSE;
}
/* Success */
return TRUE;
}
示例4: ActivateActCtx
/*
* @implemented
*/
BOOL
WINAPI
ActivateActCtx(IN HANDLE hActCtx,
OUT PULONG_PTR ulCookie)
{
NTSTATUS Status;
/* Check if the handle was invalid */
if (hActCtx == INVALID_HANDLE_VALUE)
{
/* Set error and bail out */
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
return FALSE;
}
/* Call the native API */
Status = RtlActivateActivationContext(0, hActCtx, ulCookie);
if (!NT_SUCCESS(Status))
{
/* Set error and bail out */
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
return FALSE;
}
/* It worked */
return TRUE;
}
示例5: QueryFullProcessImageNameW
/*
* @implemented
*/
BOOL
WINAPI
QueryFullProcessImageNameW(HANDLE hProcess,
DWORD dwFlags,
LPWSTR lpExeName,
PDWORD pdwSize)
{
BYTE Buffer[sizeof(UNICODE_STRING) + MAX_PATH * sizeof(WCHAR)];
UNICODE_STRING *DynamicBuffer = NULL;
UNICODE_STRING *Result = NULL;
NTSTATUS Status;
DWORD Needed;
Status = NtQueryInformationProcess(hProcess,
ProcessImageFileName,
Buffer,
sizeof(Buffer) - sizeof(WCHAR),
&Needed);
if (Status == STATUS_INFO_LENGTH_MISMATCH)
{
DynamicBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Needed + sizeof(WCHAR));
if (!DynamicBuffer)
{
BaseSetLastNTError(STATUS_NO_MEMORY);
return FALSE;
}
Status = NtQueryInformationProcess(hProcess,
ProcessImageFileName,
(LPBYTE)DynamicBuffer,
Needed,
&Needed);
Result = DynamicBuffer;
}
else Result = (PUNICODE_STRING)Buffer;
if (!NT_SUCCESS(Status)) goto Cleanup;
if (Result->Length / sizeof(WCHAR) + 1 > *pdwSize)
{
Status = STATUS_BUFFER_TOO_SMALL;
goto Cleanup;
}
*pdwSize = Result->Length / sizeof(WCHAR);
memcpy(lpExeName, Result->Buffer, Result->Length);
lpExeName[*pdwSize] = 0;
Cleanup:
RtlFreeHeap(RtlGetProcessHeap(), 0, DynamicBuffer);
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
}
return !Status;
}
示例6: MoveFileExA
BOOL
APIENTRY
MoveFileExA(
LPCSTR lpExistingFileName,
LPCSTR lpNewFileName,
DWORD dwFlags
)
/*++
Routine Description:
ANSI thunk to MoveFileW
--*/
{
PUNICODE_STRING Unicode;
UNICODE_STRING UnicodeNewFileName;
ANSI_STRING AnsiString;
NTSTATUS Status;
BOOL ReturnValue;
Unicode = &NtCurrentTeb()->StaticUnicodeString;
RtlInitAnsiString(&AnsiString,lpExistingFileName);
Status = Basep8BitStringToUnicodeString(Unicode,&AnsiString,FALSE);
if ( !NT_SUCCESS(Status) ) {
if ( Status == STATUS_BUFFER_OVERFLOW ) {
SetLastError(ERROR_FILENAME_EXCED_RANGE);
}
else {
BaseSetLastNTError(Status);
}
return FALSE;
}
if (ARGUMENT_PRESENT( lpNewFileName )) {
RtlInitAnsiString(&AnsiString,lpNewFileName);
Status = Basep8BitStringToUnicodeString(&UnicodeNewFileName,&AnsiString,TRUE);
if ( !NT_SUCCESS(Status) ) {
BaseSetLastNTError(Status);
return FALSE;
}
}
else {
UnicodeNewFileName.Buffer = NULL;
}
ReturnValue = MoveFileExW((LPCWSTR)Unicode->Buffer,(LPCWSTR)UnicodeNewFileName.Buffer,dwFlags);
if (UnicodeNewFileName.Buffer != NULL) {
RtlFreeUnicodeString(&UnicodeNewFileName);
}
return ReturnValue;
}
示例7: SetTimeZoneInformation
/*
* @implemented
*/
BOOL
WINAPI
SetTimeZoneInformation(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation)
{
RTL_TIME_ZONE_INFORMATION TimeZoneInformation;
NTSTATUS Status;
DPRINT("SetTimeZoneInformation()\n");
TimeZoneInformation.Bias = lpTimeZoneInformation->Bias;
wcsncpy(TimeZoneInformation.StandardName,
lpTimeZoneInformation->StandardName,
ARRAYSIZE(TimeZoneInformation.StandardName));
TimeZoneInformation.StandardDate.Year = lpTimeZoneInformation->StandardDate.wYear;
TimeZoneInformation.StandardDate.Month = lpTimeZoneInformation->StandardDate.wMonth;
TimeZoneInformation.StandardDate.Day = lpTimeZoneInformation->StandardDate.wDay;
TimeZoneInformation.StandardDate.Hour = lpTimeZoneInformation->StandardDate.wHour;
TimeZoneInformation.StandardDate.Minute = lpTimeZoneInformation->StandardDate.wMinute;
TimeZoneInformation.StandardDate.Second = lpTimeZoneInformation->StandardDate.wSecond;
TimeZoneInformation.StandardDate.Milliseconds = lpTimeZoneInformation->StandardDate.wMilliseconds;
TimeZoneInformation.StandardDate.Weekday = lpTimeZoneInformation->StandardDate.wDayOfWeek;
TimeZoneInformation.StandardBias = lpTimeZoneInformation->StandardBias;
wcsncpy(TimeZoneInformation.DaylightName,
lpTimeZoneInformation->DaylightName,
ARRAYSIZE(TimeZoneInformation.DaylightName));
TimeZoneInformation.DaylightDate.Year = lpTimeZoneInformation->DaylightDate.wYear;
TimeZoneInformation.DaylightDate.Month = lpTimeZoneInformation->DaylightDate.wMonth;
TimeZoneInformation.DaylightDate.Day = lpTimeZoneInformation->DaylightDate.wDay;
TimeZoneInformation.DaylightDate.Hour = lpTimeZoneInformation->DaylightDate.wHour;
TimeZoneInformation.DaylightDate.Minute = lpTimeZoneInformation->DaylightDate.wMinute;
TimeZoneInformation.DaylightDate.Second = lpTimeZoneInformation->DaylightDate.wSecond;
TimeZoneInformation.DaylightDate.Milliseconds = lpTimeZoneInformation->DaylightDate.wMilliseconds;
TimeZoneInformation.DaylightDate.Weekday = lpTimeZoneInformation->DaylightDate.wDayOfWeek;
TimeZoneInformation.DaylightBias = lpTimeZoneInformation->DaylightBias;
Status = RtlSetTimeZoneInformation(&TimeZoneInformation);
if (!NT_SUCCESS(Status))
{
DPRINT1("RtlSetTimeZoneInformation() failed (Status %lx)\n", Status);
BaseSetLastNTError(Status);
return FALSE;
}
Status = NtSetSystemInformation(SystemCurrentTimeZoneInformation,
(PVOID)&TimeZoneInformation,
sizeof(RTL_TIME_ZONE_INFORMATION));
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetSystemInformation() failed (Status %lx)\n", Status);
BaseSetLastNTError(Status);
return FALSE;
}
return TRUE;
}
示例8: GetQueuedCompletionStatus
/*
* @implemented
*/
BOOL
WINAPI
GetQueuedCompletionStatus(IN HANDLE CompletionHandle,
IN LPDWORD lpNumberOfBytesTransferred,
OUT PULONG_PTR lpCompletionKey,
OUT LPOVERLAPPED *lpOverlapped,
IN DWORD dwMilliseconds)
{
NTSTATUS Status;
IO_STATUS_BLOCK IoStatus;
ULONG_PTR CompletionKey;
LARGE_INTEGER Time;
PLARGE_INTEGER TimePtr;
/* Convert the timeout and then call the native API */
TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds);
Status = NtRemoveIoCompletion(CompletionHandle,
(PVOID*)&CompletionKey,
(PVOID*)lpOverlapped,
&IoStatus,
TimePtr);
if (!(NT_SUCCESS(Status)) || (Status == STATUS_TIMEOUT))
{
/* Clear out the overlapped output */
*lpOverlapped = NULL;
/* Check what kind of error we got */
if (Status == STATUS_TIMEOUT)
{
/* Timeout error is set directly since there's no conversion */
SetLastError(WAIT_TIMEOUT);
}
else
{
/* Any other error gets converted */
BaseSetLastNTError(Status);
}
/* This is a failure case */
return FALSE;
}
/* Write back the output parameters */
*lpCompletionKey = CompletionKey;
*lpNumberOfBytesTransferred = IoStatus.Information;
/* Check for error */
if (!NT_SUCCESS(IoStatus.Status))
{
/* Convert and fail */
BaseSetLastNTError(IoStatus.Status);
return FALSE;
}
/* Return success */
return TRUE;
}
示例9: LockFileEx
/*
* @implemented
*/
BOOL
WINAPI
LockFileEx(IN HANDLE hFile,
IN DWORD dwFlags,
IN DWORD dwReserved,
IN DWORD nNumberOfBytesToLockLow,
IN DWORD nNumberOfBytesToLockHigh,
IN LPOVERLAPPED lpOverlapped)
{
LARGE_INTEGER BytesToLock, Offset;
NTSTATUS Status;
/* Is this a console handle? */
if (IsConsoleHandle(hFile))
{
/* Can't "lock" a console! */
BaseSetLastNTError(STATUS_INVALID_HANDLE);
return FALSE;
}
/* This parameter should be zero */
if (dwReserved)
{
/* Fail since it isn't */
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
/* Set the initial status in the IO_STATUS_BLOCK to pending... */
lpOverlapped->Internal = STATUS_PENDING;
/* Convert the parameters to NT format and call the native API */
Offset.u.LowPart = lpOverlapped->Offset;
Offset.u.HighPart = lpOverlapped->OffsetHigh;
BytesToLock.u.LowPart = nNumberOfBytesToLockLow;
BytesToLock.u.HighPart = nNumberOfBytesToLockHigh;
Status = NtLockFile(hFile,
lpOverlapped->hEvent,
NULL,
NULL,
(PIO_STATUS_BLOCK)lpOverlapped,
&Offset,
&BytesToLock,
0,
dwFlags & LOCKFILE_FAIL_IMMEDIATELY ? TRUE : FALSE,
dwFlags & LOCKFILE_EXCLUSIVE_LOCK ? TRUE: FALSE);
if ((NT_SUCCESS(Status)) && (Status != STATUS_PENDING))
{
/* Pending status is *not* allowed in the Ex API */
return TRUE;
}
/* Convert the error code and fail */
BaseSetLastNTError(Status);
return FALSE;
}
示例10: CreateToolhelp32Snapshot
/*
* @implemented
*/
HANDLE
WINAPI
CreateToolhelp32Snapshot(DWORD dwFlags, DWORD th32ProcessID)
{
PRTL_DEBUG_INFORMATION HeapDebug, ModuleDebug;
PVOID ProcThrdInfo;
SIZE_T ProcThrdInfoSize;
NTSTATUS Status;
HANDLE hSnapShotSection = NULL;
if(th32ProcessID == 0)
{
th32ProcessID = GetCurrentProcessId();
}
/*
* Get all information required for the snapshot
*/
Status = TH32CreateSnapshot(dwFlags,
th32ProcessID,
&HeapDebug,
&ModuleDebug,
&ProcThrdInfo,
&ProcThrdInfoSize);
if(!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return NULL;
}
/*
* Create a section handle and initialize the collected information
*/
Status = TH32CreateSnapshotSectionInitialize(dwFlags,
th32ProcessID,
HeapDebug,
ModuleDebug,
ProcThrdInfo,
&hSnapShotSection);
/*
* Free the temporarily allocated memory which is no longer needed
*/
TH32FreeAllocatedResources(HeapDebug,
ModuleDebug,
ProcThrdInfo,
ProcThrdInfoSize);
if(!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return NULL;
}
return hSnapShotSection;
}
示例11: LockFile
/*
* @implemented
*/
BOOL
WINAPI
LockFile(IN HANDLE hFile,
IN DWORD dwFileOffsetLow,
IN DWORD dwFileOffsetHigh,
IN DWORD nNumberOfBytesToLockLow,
IN DWORD nNumberOfBytesToLockHigh)
{
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
LARGE_INTEGER BytesToLock, Offset;
/* Is this a console handle? */
if (IsConsoleHandle(hFile))
{
/* Can't "lock" a console! */
BaseSetLastNTError(STATUS_INVALID_HANDLE);
return FALSE;
}
/* Setup the parameters in NT style and call the native API */
BytesToLock.u.LowPart = nNumberOfBytesToLockLow;
BytesToLock.u.HighPart = nNumberOfBytesToLockHigh;
Offset.u.LowPart = dwFileOffsetLow;
Offset.u.HighPart = dwFileOffsetHigh;
Status = NtLockFile(hFile,
NULL,
NULL,
NULL,
&IoStatusBlock,
&Offset,
&BytesToLock,
0,
TRUE,
TRUE);
if (Status == STATUS_PENDING)
{
/* Wait for completion if needed */
Status = NtWaitForSingleObject(hFile, FALSE, NULL);
if (NT_SUCCESS(Status)) Status = IoStatusBlock.Status;
}
/* Check if we failed */
if (!NT_SUCCESS(Status))
{
/* Convert the error code and fail */
BaseSetLastNTError(Status);
return FALSE;
}
/* Success! */
return TRUE;
}
示例12: GetProcAddress
/*
* @implemented
*/
FARPROC
WINAPI
GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
{
ANSI_STRING ProcedureName, *ProcNamePtr = NULL;
FARPROC fnExp = NULL;
NTSTATUS Status;
PVOID hMapped;
ULONG Ordinal = 0;
if (HIWORD(lpProcName) != 0)
{
/* Look up by name */
RtlInitAnsiString(&ProcedureName, (LPSTR)lpProcName);
ProcNamePtr = &ProcedureName;
}
else
{
/* Look up by ordinal */
Ordinal = (ULONG)lpProcName;
}
/* Map provided handle */
hMapped = BasepMapModuleHandle(hModule, FALSE);
/* Get the proc address */
Status = LdrGetProcedureAddress(hMapped,
ProcNamePtr,
Ordinal,
(PVOID*)&fnExp);
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return NULL;
}
/* Check for a special case when returned pointer is
the same as iamge's base address */
if (fnExp == hMapped)
{
/* Set correct error code */
if (HIWORD(lpProcName) != 0)
BaseSetLastNTError(STATUS_ENTRYPOINT_NOT_FOUND);
else
BaseSetLastNTError(STATUS_ORDINAL_NOT_FOUND);
return NULL;
}
/* All good, return procedure pointer */
return fnExp;
}
示例13: DuplicateHandle
/*
* @implemented
*/
BOOL
WINAPI
DuplicateHandle(IN HANDLE hSourceProcessHandle,
IN HANDLE hSourceHandle,
IN HANDLE hTargetProcessHandle,
OUT LPHANDLE lpTargetHandle,
IN DWORD dwDesiredAccess,
IN BOOL bInheritHandle,
IN DWORD dwOptions)
{
NTSTATUS Status;
HANDLE hTargetHandle;
hSourceHandle = TranslateStdHandle(hSourceHandle);
if ((IsConsoleHandle(hSourceHandle)) &&
((hSourceHandle != NtCurrentProcess()) &&
(hSourceHandle != NtCurrentThread())))
{
if ((hSourceProcessHandle != NtCurrentProcess()) &&
(hTargetProcessHandle != NtCurrentProcess()))
{
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
return FALSE;
}
hTargetHandle = DuplicateConsoleHandle(hSourceHandle,
dwDesiredAccess,
bInheritHandle,
dwOptions);
if (hTargetHandle != INVALID_HANDLE_VALUE)
{
if (lpTargetHandle) *lpTargetHandle = hTargetHandle;
return TRUE;
}
return FALSE;
}
Status = NtDuplicateObject(hSourceProcessHandle,
hSourceHandle,
hTargetProcessHandle,
lpTargetHandle,
dwDesiredAccess,
bInheritHandle ? OBJ_INHERIT : 0,
dwOptions);
if (NT_SUCCESS(Status)) return TRUE;
BaseSetLastNTError(Status);
return FALSE;
}
示例14: SetHandleInformation
/*
* @implemented
*/
BOOL
WINAPI
SetHandleInformation(IN HANDLE hObject,
IN DWORD dwMask,
IN DWORD dwFlags)
{
OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo;
ULONG BytesWritten;
NTSTATUS Status;
hObject = TranslateStdHandle(hObject);
if (IsConsoleHandle(hObject))
{
/* FIXME: SetConsoleHandleInformation required */
UNIMPLEMENTED;
BaseSetLastNTError(STATUS_NOT_IMPLEMENTED);
return FALSE;
}
Status = NtQueryObject(hObject,
ObjectHandleFlagInformation,
&HandleInfo,
sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION),
&BytesWritten);
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return FALSE;
}
if (dwMask & HANDLE_FLAG_INHERIT)
{
HandleInfo.Inherit = (dwFlags & HANDLE_FLAG_INHERIT) != 0;
}
if (dwMask & HANDLE_FLAG_PROTECT_FROM_CLOSE)
{
HandleInfo.ProtectFromClose = (dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE) != 0;
}
Status = NtSetInformationObject(hObject,
ObjectHandleFlagInformation,
&HandleInfo,
sizeof(HandleInfo));
if (NT_SUCCESS(Status)) return TRUE;
BaseSetLastNTError(Status);
return FALSE;
}
示例15: GetCompressedFileSizeA
DWORD
WINAPI
GetCompressedFileSizeA(
LPCSTR lpFileName,
LPDWORD lpFileSizeHigh
)
{
PUNICODE_STRING Unicode;
ANSI_STRING AnsiString;
NTSTATUS Status;
Unicode = &NtCurrentTeb()->StaticUnicodeString;
RtlInitAnsiString(&AnsiString,lpFileName);
Status = Basep8BitStringToUnicodeString(Unicode,&AnsiString,FALSE);
if ( !NT_SUCCESS(Status) ) {
if ( Status == STATUS_BUFFER_OVERFLOW ) {
SetLastError(ERROR_FILENAME_EXCED_RANGE);
}
else {
BaseSetLastNTError(Status);
}
return (DWORD)-1;
}
return ( GetCompressedFileSizeW((LPCWSTR)Unicode->Buffer,lpFileSizeHigh) );
return INVALID_FILE_SIZE;
}