本文整理汇总了C++中PtrToUlong函数的典型用法代码示例。如果您正苦于以下问题:C++ PtrToUlong函数的具体用法?C++ PtrToUlong怎么用?C++ PtrToUlong使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PtrToUlong函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateConsole
void CreateConsole()
{
AllocConsole();
HANDLE lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
int hConHandle = _open_osfhandle(PtrToUlong((ULONG)lStdHandle), _O_TEXT);
FILE* fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
lStdHandle = GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong((ULONG)lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "r");
*stdin = *fp;
setvbuf(stdin, NULL, _IONBF, 0);
lStdHandle = GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong((ULONG)lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
::SetConsoleMode( lStdHandle, ENABLE_ECHO_INPUT );
char szStr[64] = {0};
sprintf_s( szStr, "vIrtuaL W0rLd - Build: %s %s", __DATE__, __TIME__ );
SetConsoleTitleA( szStr );
}
示例2: get_input_bytes
static bool /* knows nothing about records! Only about input buffers */
get_input_bytes(RECSTREAM *rstrm, char *addr, int len)
{
size_t current;
if (rstrm->nonblock) {
if (len > (int)(rstrm->in_boundry - rstrm->in_finger))
return false;
memcpy(addr, rstrm->in_finger, (size_t) len);
rstrm->in_finger += len;
return true;
}
while (len > 0) {
current =
(size_t) (PtrToUlong(rstrm->in_boundry) -
PtrToUlong(rstrm->in_finger));
if (current == 0) {
if (!fill_input_buf(rstrm))
return (false);
continue;
}
current = (len < current) ? len : current;
memmove(addr, rstrm->in_finger, current);
rstrm->in_finger += current;
addr += current;
len -= current;
}
return (true);
}
示例3: BlockedThreadHandler
DWORD WINAPI BlockedThreadHandler(PVOID pvParam) {
HANDLE hParentThread;
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
GetCurrentProcess(), &hParentThread, 0, FALSE,
DUPLICATE_SAME_ACCESS);
HANDLE handles[3];
DWORD threadID1;
handles[0] = CreateThread(NULL, 0, SimpleThreadHandler,
hParentThread, 0, &threadID1);
DWORD threadID2;
handles[1] = CreateThread(NULL, 0, SimpleThreadHandler,
hParentThread, 0, &threadID2);
DWORD threadID3;
handles[2] = CreateThread(NULL, 0, SimpleThreadHandler,
hParentThread, 0, &threadID3);
_tprintf(TEXT("LockThreads = %u\n"), GetCurrentThreadId());
_tprintf(TEXT(" thread1 = %u (0x%x)\n"), threadID1, PtrToUlong(handles[0]));
_tprintf(TEXT(" thread2 = %u (0x%x)\n"), threadID2, PtrToUlong(handles[1]));
_tprintf(TEXT(" thread3 = %u (0x%x)\n"), threadID3, PtrToUlong(handles[2]));
Sleep(100);
// Note: WaitForMultipleObjects is not handled by WCT
WaitForMultipleObjects(3, handles, TRUE, INFINITE);
//WaitForSingleObject(handles[0], INFINITE);
_tprintf(TEXT("LockThreads is over\n"));
return(0);
}
示例4: CreateConsole
void CreateConsole(const char *winTitle)
{
//http://www.gamedev.net/community/forums/viewreply.asp?ID=1958358
int hConHandle = 0;
HANDLE lStdHandle = 0;
FILE *fp = 0 ;
AllocConsole();
if(winTitle)
SetConsoleTitleA(winTitle);
// redirect unbuffered STDOUT to the console
lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
// redirect unbuffered STDIN to the console
lStdHandle = GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "r");
*stdin = *fp;
setvbuf(stdin, NULL, _IONBF, 0);
// redirect unbuffered STDERR to the console
lStdHandle = GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
}
示例5: FollowNPC_Enable
VOID FollowNPC_Enable(PBYTE pFollowNpc1, PBYTE pFollowNpc2, PBYTE pFollowFaction, PFLOAT pFollowNPCDistance, BOOL bEnable)
{
DWORD dwOldProtect;
if(pFollowNpc1 && pFollowNpc2 && VirtualProtect(pFollowNpc1, PtrToUlong(pFollowNpc2) - PtrToUlong(pFollowNpc1) + 1, PAGE_EXECUTE_READWRITE, &dwOldProtect))
{
if(bEnable)
{
if(pFollowNpc1[0] != 0x90)
{
memcpy(g_bFollowNpcBackup1, pFollowNpc1, sizeof(g_bFollowNpcBackup1));
memcpy(g_bFollowNpcBackup2, pFollowNpc2, sizeof(g_bFollowNpcBackup2));
}
memcpy(pFollowNpc1, g_bNop, sizeof(g_bFollowNpcBackup1));
memcpy(pFollowNpc2, g_bNop, sizeof(g_bFollowNpcBackup2));
}
else
{
if(pFollowNpc1[0] == 0x90)
{
memcpy(pFollowNpc1, g_bFollowNpcBackup1, sizeof(g_bFollowNpcBackup1));
memcpy(pFollowNpc2, g_bFollowNpcBackup2, sizeof(g_bFollowNpcBackup2));
}
}
VirtualProtect(pFollowNpc1, PtrToUlong(pFollowNpc2) - PtrToUlong(pFollowNpc1) + 1, dwOldProtect, &dwOldProtect);
}
if(pFollowFaction && VirtualProtect(pFollowFaction, sizeof(g_bFollowNpcBackup3), PAGE_EXECUTE_READWRITE, &dwOldProtect))
{
if(bEnable)
{
if(pFollowFaction[0] != 0x90)
{
memcpy(g_bFollowNpcBackup3, pFollowFaction, sizeof(g_bFollowNpcBackup3));
}
memcpy(pFollowFaction, g_bNop, sizeof(g_bFollowNpcBackup3));
}
else
{
if(pFollowFaction[0] == 0x90)
{
memcpy(pFollowFaction, g_bFollowNpcBackup3, sizeof(g_bFollowNpcBackup3));
}
}
VirtualProtect(pFollowFaction, sizeof(g_bFollowNpcBackup3), dwOldProtect, &dwOldProtect);
}
if(pFollowNPCDistance && VirtualProtect(pFollowNPCDistance, sizeof(FLOAT), PAGE_READWRITE, &dwOldProtect))
{
if(bEnable)
{
*(PDWORD)pFollowNPCDistance = 0x7F800000;
}
else
{
*pFollowNPCDistance = 900;
}
VirtualProtect(pFollowNPCDistance, sizeof(FLOAT), dwOldProtect, &dwOldProtect);
}
}
示例6: DrvSetPrinterData16
/******************************************************************
* DrvSetPrinterData (GDI.281)
*
*/
DWORD WINAPI DrvSetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
DWORD lpType, LPBYTE lpPrinterData,
DWORD dwSize)
{
LPSTR RegStr_Printer;
HKEY hkey = 0;
DWORD res = 0;
if (HIWORD(lpPrinter))
TRACE("printer %s\n",lpPrinter);
else
TRACE("printer %p\n",lpPrinter);
if (HIWORD(lpProfile))
TRACE("profile %s\n",lpProfile);
else
TRACE("profile %p\n",lpProfile);
TRACE("lpType %08x\n",lpType);
if ((!lpPrinter) || (!lpProfile) ||
(PtrToUlong(lpProfile) == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
(!strcmp(lpProfile, PrinterModel))))
return ERROR_INVALID_PARAMETER;
RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
strlen(Printers) + strlen(lpPrinter) + 2);
strcpy(RegStr_Printer, Printers);
strcat(RegStr_Printer, lpPrinter);
if ((PtrToUlong(lpProfile) == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
(!strcmp(lpProfile, DefaultDevMode)))) {
if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)
!= ERROR_SUCCESS ||
RegSetValueExA(hkey, DefaultDevMode, 0, REG_BINARY,
lpPrinterData, dwSize) != ERROR_SUCCESS )
res = ERROR_INVALID_PRINTER_NAME;
}
else
{
strcat(RegStr_Printer, "\\");
if( (res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ==
ERROR_SUCCESS ) {
if (!lpPrinterData)
res = RegDeleteValueA(hkey, lpProfile);
else
res = RegSetValueExA(hkey, lpProfile, 0, lpType,
lpPrinterData, dwSize);
}
}
if (hkey) RegCloseKey(hkey);
HeapFree(GetProcessHeap(), 0, RegStr_Printer);
return res;
}
示例7: scanSendChatMessage_ScanProc
VOID scanSendChatMessage_ScanProc(INT iItem, HWND hwndDlg, PBYTE pbFile)
{
PIMAGE_NT_HEADERS pNtHdr = PIMAGE_NT_HEADERS(pbFile + PIMAGE_DOS_HEADER(pbFile)->e_lfanew);
PIMAGE_SECTION_HEADER pSecHdr = PIMAGE_SECTION_HEADER(pNtHdr + 1);
PBYTE pbCode = RvaToPointer(pbFile, pSecHdr[0].VirtualAddress);
DWORD dwCodeSize = pSecHdr[0].SizeOfRawData;
PBYTE pbRData = RvaToPointer(pbFile, pSecHdr[1].VirtualAddress);
DWORD dwRDataSize = pSecHdr[1].SizeOfRawData;
PBYTE pbData = RvaToPointer(pbFile, pSecHdr[2].VirtualAddress);
DWORD dwDataSize = pSecHdr[2].SizeOfRawData;
SetItemStatus(iItem, hwndDlg, "Scanning...");
// scan data section for "Unknown chat type"
for(DWORD dwDataIndex = 0; dwDataIndex < dwDataSize - (sizeof("Unknown chat type") - 1); dwDataIndex++)
{
if(MemoryCompare(&pbData[dwDataIndex], (PBYTE)"Unknown chat type", sizeof("Unknown chat type") - 1))
{
// calculate va of found string
DWORD dwStringVA = OffsetToRva(pbFile, PtrToUlong(pbData) + dwDataIndex - PtrToUlong(pbFile));
if(dwStringVA)
{
dwStringVA += pNtHdr->OptionalHeader.ImageBase;
// scan code section for 'push dwStringVA'
for(DWORD dwCodeIndex = 0; dwCodeIndex < dwCodeSize - 8; dwCodeIndex++)
{
if(pbCode[dwCodeIndex] == 0x68 && *((PDWORD)&pbCode[dwCodeIndex + 1]) == dwStringVA)
{
// find beginning of procedure
for(DWORD dwCodeIndex2 = dwCodeIndex & 0xFFFFFFF0; dwCodeIndex2; dwCodeIndex2 -= 0x10)
{
if(pbCode[dwCodeIndex2 - 1] == 0x90 || pbCode[dwCodeIndex2 - 1] == 0xC3 || pbCode[dwCodeIndex2 - 3] == 0xC2)
{
DWORD dwProcRva = OffsetToRva(pbFile, PtrToUlong(pbCode) + dwCodeIndex2 - PtrToUlong(pbFile));
if(dwProcRva)
{
GetPPD(iItem, hwndDlg)->dwValue = dwProcRva + pNtHdr->OptionalHeader.ImageBase;
SetItemStatus(iItem, hwndDlg, "Success");
return;
}
}
}
}
}
}
}
}
GetPPD(iItem, hwndDlg)->dwValue = 0;
SetItemStatus(iItem, hwndDlg, "Fail");
}
示例8: XenUsb_CompleteXenbusInit
static NTSTATUS
XenUsb_CompleteXenbusInit(PXENUSB_DEVICE_DATA xudd) {
PUCHAR ptr;
USHORT type;
PCHAR setting, value, value2;
ULONG i;
ptr = xudd->config_page;
while((type = GET_XEN_INIT_RSP(&ptr, (PVOID)&setting, (PVOID)&value, (PVOID)&value2)) != XEN_INIT_TYPE_END) {
switch(type) {
case XEN_INIT_TYPE_RING: /* frontend ring */
FUNCTION_MSG("XEN_INIT_TYPE_RING - %s = %p\n", setting, value);
if (strcmp(setting, "urb-ring-ref") == 0) {
xudd->urb_sring = (usbif_urb_sring_t *)value;
FRONT_RING_INIT(&xudd->urb_ring, xudd->urb_sring, PAGE_SIZE);
}
if (strcmp(setting, "conn-ring-ref") == 0) {
xudd->conn_sring = (usbif_conn_sring_t *)value;
FRONT_RING_INIT(&xudd->conn_ring, xudd->conn_sring, PAGE_SIZE);
}
break;
case XEN_INIT_TYPE_EVENT_CHANNEL_DPC: /* frontend event channel */
FUNCTION_MSG("XEN_INIT_TYPE_EVENT_CHANNEL_DPC - %s = %d\n", setting, PtrToUlong(value) & 0x3FFFFFFF);
if (strcmp(setting, "event-channel") == 0) {
xudd->event_channel = PtrToUlong(value);
}
break;
case XEN_INIT_TYPE_READ_STRING_BACK:
case XEN_INIT_TYPE_READ_STRING_FRONT:
FUNCTION_MSG("XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value);
break;
default:
FUNCTION_MSG("XEN_INIT_TYPE_%d\n", type);
break;
}
}
if (xudd->urb_sring == NULL || xudd->conn_sring == NULL || xudd->event_channel == 0) {
FUNCTION_MSG("Missing settings\n");
FUNCTION_EXIT();
return STATUS_BAD_INITIAL_PC;
}
stack_new(&xudd->req_id_ss, REQ_ID_COUNT);
for (i = 0; i < REQ_ID_COUNT; i++) {
put_id_on_freelist(xudd->req_id_ss, (uint16_t)i);
}
return STATUS_SUCCESS;
}
示例9: SetWindowLongPtr
LRESULT CALLBACK DemoApp::s_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DemoApp *pThis;
LRESULT lRet = 0;
if (uMsg == WM_NCCREATE)
{
LPCREATESTRUCT pcs = reinterpret_cast<LPCREATESTRUCT> (lParam);
pThis = reinterpret_cast<DemoApp *> (pcs->lpCreateParams);
SetWindowLongPtr(hWnd, GWLP_USERDATA, PtrToUlong(pThis));
lRet = DefWindowProc(hWnd, uMsg, wParam, lParam);
}
else
{
pThis = reinterpret_cast<DemoApp *> (GetWindowLongPtr(hWnd, GWLP_USERDATA));
if (pThis)
{
lRet = pThis->WndProc(hWnd, uMsg, wParam, lParam);
}
else
{
lRet = DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
return lRet;
}
示例10: PtrToUlong
LRESULT CALLBACK SnakeD2D::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT result = 0;
bool wasHandled = false;
if (message == WM_CREATE)
{
LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
SnakeD2D *app = (SnakeD2D*)pcs->lpCreateParams;
::SetWindowLongPtrW(
hwnd,
GWLP_USERDATA,
PtrToUlong(app)
);
}
else
{
SnakeD2D *app = reinterpret_cast<SnakeD2D *>(static_cast<LONG_PTR>(
::GetWindowLongPtrW(
hwnd,
GWLP_USERDATA
)));
switch(message)
{
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
default:
break;
}
wasHandled = true;
break;
default:
break;
case WM_PAINT:
ValidateRect(hwnd, nullptr); // avoid new wm_paint messages
wasHandled = true;
result = 0;
break;
case WM_SIZE:
{
UINT width = LOWORD(lParam);
UINT height = HIWORD(lParam);
app->OnResize(width, height);
}
result = 0;
wasHandled = true;
break;
}
}
if(!wasHandled)
result = DefWindowProc(hwnd, message, wParam, lParam);
return result;
}
示例11: LockCriticalSections
void LockCriticalSections() {
InitializeCriticalSection(&cs1);
InitializeCriticalSection(&cs2);
DWORD threadID1;
CreateThread(NULL, 0, LockCriticalSectionHandler, (PVOID)1, 0, &threadID1);
DWORD threadID2;
CreateThread(NULL, 0, LockCriticalSectionHandler, (PVOID)2, 0, &threadID2);
_tprintf(TEXT("LockCriticalSections:\n"));
_tprintf(TEXT(" thread1 = %u\n"), threadID1);
_tprintf(TEXT(" thread2 = %u\n"), threadID2);
_tprintf(TEXT(" &cs1 = 0x%x\n"), PtrToUlong(&cs1));
_tprintf(TEXT(" &cs2 = 0x%x\n"), PtrToUlong(&cs2));
}
示例12: ControlPadWndProc
LRESULT CALLBACK ControlPadWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg == WM_CREATE)
{
// Pointer to a value to be passed to the window through
// the CREATESTRUCT structure is out window object instance.
LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
ControlPad* pCtrlPad = static_cast<ControlPad*>(pcs->lpCreateParams);
// Store the pointer as private data of the window
::SetWindowLongPtr(hWnd, GWLP_USERDATA, PtrToUlong(pCtrlPad));
pCtrlPad->Attach(hWnd);
pCtrlPad->OnCreate();
return 0;
}
// Extract the pointer to out window object
ControlPad* pCtrlPad = static_cast<ControlPad*>(UlongToPtr(::GetWindowLongPtr(hWnd, GWLP_USERDATA)));
if (pCtrlPad)
{
pCtrlPad->WindowProc(Msg, wParam, lParam);
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
示例13: PhGetServiceNameFromTag
PPH_STRING PhGetServiceNameFromTag(
_In_ HANDLE ProcessId,
_In_ PVOID ServiceTag
)
{
static PQUERY_TAG_INFORMATION I_QueryTagInformation = NULL;
PPH_STRING serviceName = NULL;
TAG_INFO_NAME_FROM_TAG nameFromTag;
if (!I_QueryTagInformation)
{
I_QueryTagInformation = PhGetModuleProcAddress(L"advapi32.dll", "I_QueryTagInformation");
if (!I_QueryTagInformation)
return NULL;
}
memset(&nameFromTag, 0, sizeof(TAG_INFO_NAME_FROM_TAG));
nameFromTag.InParams.dwPid = HandleToUlong(ProcessId);
nameFromTag.InParams.dwTag = PtrToUlong(ServiceTag);
I_QueryTagInformation(NULL, eTagInfoLevelNameFromTag, &nameFromTag);
if (nameFromTag.OutParams.pszName)
{
serviceName = PhCreateString(nameFromTag.OutParams.pszName);
LocalFree(nameFromTag.OutParams.pszName);
}
return serviceName;
}
示例14: PtrToUlong
// Worker Thread Start Routine
DWORD
CDeviceGeneralPage::OnWorkerThreadStart(LPVOID lpParameter)
{
UINT i = PtrToUlong(lpParameter);
ATLASSERT(i < RTL_NUMBER_OF(m_pUnitDevices));
if (i >= RTL_NUMBER_OF(m_pUnitDevices))
{
return 255;
}
ndas::UnitDevicePtr pUnitDevice = m_pUnitDevices[i];
if (NULL == pUnitDevice.get())
{
return 1;
}
(void) pUnitDevice->UpdateHostStats();
if (::IsWindow(m_hWnd))
{
ATLVERIFY(PostMessage(WM_USER_DONE, 0, static_cast<LPARAM>(i)));
}
return 0;
}
示例15: ComboBoxSelected
//-----------------------------------------------------------------------------
// Name: MultisampleTypeChanged
// Desc: Respond to a change of selected multisample type.
//-----------------------------------------------------------------------------
void CD3DSettingsDialog::MultisampleTypeChanged( void )
{
D3DMULTISAMPLE_TYPE mst = (D3DMULTISAMPLE_TYPE)PtrToUlong( ComboBoxSelected( IDC_MULTISAMPLE_COMBO ) );
m_d3dSettings.SetMultisampleType( mst );
// Set up max quality for this mst
D3DDeviceCombo* pDeviceCombo = m_d3dSettings.PDeviceCombo();
DWORD maxQuality = 0;
for( UINT ims = 0; ims < pDeviceCombo->pMultiSampleTypeList->Count(); ims++ )
{
D3DMULTISAMPLE_TYPE msType = *(D3DMULTISAMPLE_TYPE*)pDeviceCombo->pMultiSampleTypeList->GetPtr(ims);
if( msType == mst )
{
maxQuality = *(DWORD*)pDeviceCombo->pMultiSampleQualityList->GetPtr(ims);
break;
}
}
ComboBoxClear( IDC_MULTISAMPLE_QUALITY_COMBO );
for( UINT msq = 0; msq < maxQuality; msq++ )
{
TCHAR str[100];
wsprintf( str, TEXT("%d"), msq );
ComboBoxAdd( IDC_MULTISAMPLE_QUALITY_COMBO, UlongToPtr( msq ), str );
if( msq == m_d3dSettings.MultisampleQuality() )
ComboBoxSelect( IDC_MULTISAMPLE_QUALITY_COMBO, UlongToPtr( msq ) );
}
if (!ComboBoxSomethingSelected( IDC_MULTISAMPLE_QUALITY_COMBO ) &&
ComboBoxCount( IDC_MULTISAMPLE_QUALITY_COMBO ) > 0)
{
ComboBoxSelectIndex( IDC_MULTISAMPLE_QUALITY_COMBO, 0 );
}
}