本文整理汇总了C++中HeapAlloc函数的典型用法代码示例。如果您正苦于以下问题:C++ HeapAlloc函数的具体用法?C++ HeapAlloc怎么用?C++ HeapAlloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HeapAlloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printf
BOOL ProcessApiMon::INTViewer(IntVisitor& Visitor)
{
IMAGE_DOS_HEADER* pDos;
IMAGE_NT_HEADERS* pNt;
IMAGE_DATA_DIRECTORY* pDataDir;
IMAGE_IMPORT_DESCRIPTOR* piid;
HANDLE hProcess = NULL;
LPVOID pBuf = NULL;
BOOL ret = FALSE;
DWORD nBytes;
if (!(hProcess = OpenProcess(PROCESS_VM_READ, NULL, m_dwPid)))
{
printf("OpenProcess failed[%d]\n", GetLastError());
return FALSE;
}
pBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, m_ModuleBaseSize);
if (!pBuf)
{
printf("HeapAlloc failed[%d]\n", GetLastError());
goto $Cleanup;
}
if (!ReadProcessMemory(hProcess, m_ModulepBaseMem, pBuf, m_ModuleBaseSize, &nBytes))
{
printf("ReadProcessMemory failed[%d]\n", GetLastError());
goto $Cleanup;
}
pDos = (IMAGE_DOS_HEADER*)pBuf;
if (pDos->e_magic != IMAGE_DOS_SIGNATURE)
goto $Cleanup;
pNt = (IMAGE_NT_HEADERS*)XGetPtr(pBuf, (DWORD_PTR)pDos->e_lfanew);
if (pNt->Signature != IMAGE_NT_SIGNATURE)
goto $Cleanup;
pDataDir = &pNt->OptionalHeader.DataDirectory[1];
piid = (IMAGE_IMPORT_DESCRIPTOR*)XGetPtr(pBuf, (DWORD_PTR)pDataDir->VirtualAddress);
for (DWORD i = 0; piid[i].Name; i++)
{
try
{
if (!Visitor.visit(piid[i], pBuf))
break;
}
catch (...)
{
goto $Cleanup;
}
}
ret = TRUE;
$Cleanup:
if (hProcess)
CloseHandle(hProcess);
if (pBuf)
HeapFree(GetProcessHeap(), 0, pBuf);
return ret;
}
示例2: wined3d_dll_init
//.........这里部分代码省略.........
TRACE("Using FBOs for offscreen rendering\n");
wined3d_settings.offscreen_rendering_mode = ORM_FBO;
}
}
if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
{
if (!strcmp(buffer,"disabled"))
{
TRACE("Disabling render target locking\n");
wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
}
else if (!strcmp(buffer,"readdraw"))
{
TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
}
else if (!strcmp(buffer,"readtex"))
{
TRACE("Using glReadPixels for render target reading and textures for writing\n");
wined3d_settings.rendertargetlock_mode = RTL_READTEX;
}
}
if ( !get_config_key_dword( hkey, appkey, "VideoPciDeviceID", &tmpvalue) )
{
int pci_device_id = tmpvalue;
/* A pci device id is 16-bit */
if(pci_device_id > 0xffff)
{
ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
}
else
{
TRACE("Using PCI Device ID %04x\n", pci_device_id);
wined3d_settings.pci_device_id = pci_device_id;
}
}
if ( !get_config_key_dword( hkey, appkey, "VideoPciVendorID", &tmpvalue) )
{
int pci_vendor_id = tmpvalue;
/* A pci device id is 16-bit */
if(pci_vendor_id > 0xffff)
{
ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
}
else
{
TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
wined3d_settings.pci_vendor_id = pci_vendor_id;
}
}
if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
{
int TmpVideoMemorySize = atoi(buffer);
if(TmpVideoMemorySize > 0)
{
wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
TRACE("Use %iMB = %d byte for emulated_textureram\n",
TmpVideoMemorySize,
wined3d_settings.emulated_textureram);
}
else
ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
}
if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
{
size_t len = strlen(buffer) + 1;
wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, len);
if (!wined3d_settings.logo) ERR("Failed to allocate logo path memory.\n");
else memcpy(wined3d_settings.logo, buffer, len);
}
if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
{
if (!strcmp(buffer,"enabled"))
{
TRACE("Allow multisampling\n");
wined3d_settings.allow_multisampling = TRUE;
}
}
if (!get_config_key(hkey, appkey, "StrictDrawOrdering", buffer, size)
&& !strcmp(buffer,"enabled"))
{
TRACE("Enforcing strict draw ordering.\n");
wined3d_settings.strict_draw_ordering = TRUE;
}
}
if (wined3d_settings.vs_mode == VS_HW)
TRACE("Allow HW vertex shaders\n");
if (wined3d_settings.ps_mode == PS_NONE)
TRACE("Disable pixel shaders\n");
if (wined3d_settings.glslRequested)
TRACE("If supported by your system, GL Shading Language will be used\n");
if (appkey) RegCloseKey( appkey );
if (hkey) RegCloseKey( hkey );
return TRUE;
}
示例3: test_32bit_win
static void test_32bit_win(void)
{
DWORD hdlA, retvalA;
DWORD hdlW, retvalW = 0;
BOOL retA,retW;
PVOID pVersionInfoA = NULL;
PVOID pVersionInfoW = NULL;
char *pBufA;
WCHAR *pBufW;
UINT uiLengthA, uiLengthW;
char mypathA[MAX_PATH];
WCHAR mypathW[MAX_PATH];
char rootA[] = "\\";
WCHAR rootW[] = { '\\', 0 };
WCHAR emptyW[] = { 0 };
char varfileinfoA[] = "\\VarFileInfo\\Translation";
WCHAR varfileinfoW[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
'\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
char WineVarFileInfoA[] = { 0x09, 0x04, 0xE4, 0x04 };
char FileDescriptionA[] = "\\StringFileInfo\\040904E4\\FileDescription";
WCHAR FileDescriptionW[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
'\\','0','4','0','9','0','4','E','4',
'\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n', 0 };
char WineFileDescriptionA[] = "FileDescription";
WCHAR WineFileDescriptionW[] = { 'F','i','l','e','D','e','s','c','r','i','p','t','i','o','n', 0 };
BOOL is_unicode_enabled = TRUE;
/* A copy from dlls/version/info.c */
typedef struct
{
WORD wLength;
WORD wValueLength;
WORD wType;
WCHAR szKey[1];
#if 0 /* variable length structure */
/* DWORD aligned */
BYTE Value[];
/* DWORD aligned */
VS_VERSION_INFO_STRUCT32 Children[];
#endif
} VS_VERSION_INFO_STRUCT32;
/* If we call GetFileVersionInfoA on a system that supports Unicode, NT/W2K/XP/W2K3 (by default) and Wine,
* the versioninfo will contain Unicode strings.
* Part of the test is to call both the A and W versions, which should have the same Version Information
* for some requests, on systems that support both calls.
*/
/* First get the versioninfo via the W versions */
SetLastError(0xdeadbeef);
GetModuleFileNameW(NULL, mypathW, MAX_PATH);
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
{
win_skip("GetModuleFileNameW not existing on this platform, skipping comparison between A- and W-calls\n");
is_unicode_enabled = FALSE;
}
if (is_unicode_enabled)
{
retvalW = GetFileVersionInfoSizeW( mypathW, &hdlW);
pVersionInfoW = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalW );
retW = GetFileVersionInfoW( mypathW, 0, retvalW, pVersionInfoW );
ok(retW, "GetFileVersionInfo failed: GetLastError = %u\n", GetLastError());
}
GetModuleFileNameA(NULL, mypathA, MAX_PATH);
retvalA = GetFileVersionInfoSizeA( mypathA, &hdlA);
pVersionInfoA = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalA );
retA = GetFileVersionInfoA( mypathA, 0, retvalA, pVersionInfoA );
ok(retA, "GetFileVersionInfo failed: GetLastError = %u\n", GetLastError());
if (is_unicode_enabled)
{
ok( retvalA == retvalW, "The size of the struct should be the same for both A/W calls, it is (%d) vs. (%d)\n",
retvalA, retvalW);
ok( !memcmp(pVersionInfoA, pVersionInfoW, retvalA), "Both structs should be the same, they aren't\n");
}
/* The structs on Windows are bigger than just the struct for the basic information. The total struct
* contains also an empty part, which is used for converted strings. The converted strings are a result
* of calling VerQueryValueA on a 32bit resource and calling VerQueryValueW on a 16bit resource.
* The first WORD of the structure (wLength) shows the size of the base struct. The total struct size depends
* on the Windows version:
*
* 16bits resource (numbers are from a sample app):
*
* Windows Version Retrieved with A/W wLength StructSize
* ====================================================================================
* Win98 A 0x01B4 (436) 436
* NT4 A/W 0x01B4 (436) 2048 ???
* W2K/XP/W2K3 A/W 0x01B4 (436) 1536 which is (436 - sizeof(VS_FIXEDFILEINFO)) * 4
*
* 32bits resource (numbers are from this test executable version_crosstest.exe):
* Windows Version Retrieved with A/W wLength StructSize
* =============================================================
* Win98 A 0x01E0 (480) 848 (structure data doesn't seem correct)
* NT4 A/W 0x0350 (848) 1272 (848 * 1.5)
* W2K/XP/W2K3 A/W 0x0350 (848) 1700 which is (848 * 2) + 4
*
* Wine will follow the implementation (eventually) of W2K/XP/W2K3
//.........这里部分代码省略.........
示例4: wave_in_test_device
static void wave_in_test_device(UINT_PTR device)
{
WAVEINCAPSA capsA;
WAVEINCAPSW capsW;
WAVEFORMATEX format;
WAVEFORMATEXTENSIBLE wfex;
HWAVEIN win;
MMRESULT rc;
UINT f;
WCHAR * nameW;
CHAR * nameA;
DWORD size;
DWORD dwPageSize;
BYTE * twoPages;
SYSTEM_INFO sSysInfo;
DWORD flOldProtect;
BOOL res;
GetSystemInfo(&sSysInfo);
dwPageSize = sSysInfo.dwPageSize;
rc=waveInGetDevCapsA(device,&capsA,sizeof(capsA));
ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
rc==MMSYSERR_NODRIVER,
"waveInGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
dev_name(device),wave_in_error(rc));
if (rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER)
return;
rc=waveInGetDevCapsW(device,&capsW,sizeof(capsW));
ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
"waveInGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
"expected, got %s\n",dev_name(device),wave_in_error(rc));
rc=waveInGetDevCapsA(device,NULL,sizeof(capsA));
ok(rc==MMSYSERR_INVALPARAM,
"waveInGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
dev_name(device),wave_in_error(rc));
rc=waveInGetDevCapsW(device,NULL,sizeof(capsW));
ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
"waveInGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
"expected, got %s\n",dev_name(device),wave_in_error(rc));
if (0)
{
/* FIXME: this works on windows but crashes wine */
rc=waveInGetDevCapsA(device,(LPWAVEINCAPSA)1,sizeof(capsA));
ok(rc==MMSYSERR_INVALPARAM,
"waveInGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
dev_name(device),wave_in_error(rc));
rc=waveInGetDevCapsW(device,(LPWAVEINCAPSW)1,sizeof(capsW));
ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
"waveInGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
"expected, got %s\n",dev_name(device),wave_in_error(rc));
}
rc=waveInGetDevCapsA(device,&capsA,4);
ok(rc==MMSYSERR_NOERROR,
"waveInGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
dev_name(device),wave_in_error(rc));
rc=waveInGetDevCapsW(device,&capsW,4);
ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED ||
rc==MMSYSERR_INVALPARAM, /* Vista, W2K8 */
"waveInGetDevCapsW(%s): unexpected return value %s\n",
dev_name(device),wave_in_error(rc));
nameA=NULL;
rc=waveInMessage((HWAVEIN)device, DRV_QUERYDEVICEINTERFACESIZE,
(DWORD_PTR)&size, 0);
ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_INVALPARAM ||
rc==MMSYSERR_NOTSUPPORTED,
"waveInMessage(%s): failed to get interface size: rc=%s\n",
dev_name(device),wave_in_error(rc));
if (rc==MMSYSERR_NOERROR) {
nameW = HeapAlloc(GetProcessHeap(), 0, size);
rc=waveInMessage((HWAVEIN)device, DRV_QUERYDEVICEINTERFACE,
(DWORD_PTR)nameW, size);
ok(rc==MMSYSERR_NOERROR,"waveInMessage(%s): failed to get interface "
"name: rc=%s\n",dev_name(device),wave_in_error(rc));
ok(lstrlenW(nameW)+1==size/sizeof(WCHAR),
"got an incorrect size %d\n", size);
if (rc==MMSYSERR_NOERROR) {
nameA = HeapAlloc(GetProcessHeap(), 0, size/sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, 0, nameW, size/sizeof(WCHAR),
nameA, size/sizeof(WCHAR), NULL, NULL);
}
HeapFree(GetProcessHeap(), 0, nameW);
} else if (rc==MMSYSERR_NOTSUPPORTED) {
nameA=HeapAlloc(GetProcessHeap(), 0, sizeof("not supported"));
strcpy(nameA, "not supported");
}
trace(" %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device),capsA.szPname,
(nameA?nameA:"failed"),capsA.vDriverVersion >> 8,
capsA.vDriverVersion & 0xff,capsA.wMid,capsA.wPid);
trace(" channels=%d formats=%05x\n",
capsA.wChannels,capsA.dwFormats);
//.........这里部分代码省略.........
示例5: VideoCapDriverDescAndVer16
/***********************************************************************
* VideoCapDriverDescAndVer [MSVIDEO.22]
*/
DWORD WINAPI VideoCapDriverDescAndVer16(WORD nr, LPSTR buf1, WORD buf1len,
LPSTR buf2, WORD buf2len)
{
static const char version_info_spec[] = "\\StringFileInfo\\040904E4\\FileDescription";
DWORD verhandle;
DWORD infosize;
UINT subblocklen;
char *s, buf[2048], fn[260];
LPBYTE infobuf;
LPVOID subblock;
DWORD i, cnt = 0, lRet;
DWORD bufLen, fnLen;
FILETIME lastWrite;
HKEY hKey;
BOOL found = FALSE;
TRACE("(%d,%p,%d,%p,%d)\n", nr, buf1, buf1len, buf2, buf2len);
lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, HKLM_DRIVERS32, 0, KEY_QUERY_VALUE, &hKey);
if (lRet == ERROR_SUCCESS)
{
RegQueryInfoKeyA( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
for (i = 0; i < cnt; i++)
{
bufLen = sizeof(buf) / sizeof(buf[0]);
lRet = RegEnumKeyExA(hKey, i, buf, &bufLen, 0, 0, 0, &lastWrite);
if (lRet != ERROR_SUCCESS) continue;
if (strncasecmp(buf, "vid", 3)) continue;
if (nr--) continue;
fnLen = sizeof(fn);
lRet = RegQueryValueExA(hKey, buf, 0, 0, (LPBYTE)fn, &fnLen);
if (lRet == ERROR_SUCCESS) found = TRUE;
break;
}
RegCloseKey( hKey );
}
/* search system.ini if not found in the registry */
if (!found && GetPrivateProfileStringA("drivers32", NULL, NULL, buf, sizeof(buf), "system.ini"))
{
for (s = buf; *s; s += strlen(s) + 1)
{
if (strncasecmp(s, "vid", 3)) continue;
if (nr--) continue;
if (GetPrivateProfileStringA("drivers32", s, NULL, fn, sizeof(fn), "system.ini"))
found = TRUE;
break;
}
}
if (!found)
{
TRACE("No more VID* entries found nr=%d\n", nr);
return 20;
}
infosize = GetFileVersionInfoSizeA(fn, &verhandle);
if (!infosize)
{
TRACE("%s has no fileversioninfo.\n", fn);
return 18;
}
infobuf = HeapAlloc(GetProcessHeap(), 0, infosize);
if (GetFileVersionInfoA(fn, verhandle, infosize, infobuf))
{
/* Yes, two space behind : */
/* FIXME: test for buflen */
snprintf(buf2, buf2len, "Version: %d.%d.%d.%d\n",
((WORD*)infobuf)[0x0f],
((WORD*)infobuf)[0x0e],
((WORD*)infobuf)[0x11],
((WORD*)infobuf)[0x10]
);
TRACE("version of %s is %s\n", fn, buf2);
}
else
{
TRACE("GetFileVersionInfoA failed for %s.\n", fn);
lstrcpynA(buf2, fn, buf2len); /* msvideo.dll appears to copy fn*/
}
/* FIXME: language problem? */
if (VerQueryValueA( infobuf,
version_info_spec,
&subblock,
&subblocklen
))
{
UINT copylen = min(subblocklen,buf1len-1);
memcpy(buf1, subblock, copylen);
buf1[copylen] = '\0';
TRACE("VQA returned %s\n", (LPCSTR)subblock);
}
else
{
TRACE("VQA did not return on query \\StringFileInfo\\040904E4\\FileDescription?\n");
lstrcpynA(buf1, fn, buf1len); /* msvideo.dll appears to copy fn*/
}
HeapFree(GetProcessHeap(), 0, infobuf);
return 0;
//.........这里部分代码省略.........
示例6: cp_fields_resample
static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, float *freqAcc)
{
UINT i, channel;
UINT istride = dsb->pwfx->nBlockAlign;
UINT ostride = dsb->device->pwfx->nChannels * sizeof(float);
float freqAdjust = dsb->freqAdjust;
float freqAcc_start = *freqAcc;
float freqAcc_end = freqAcc_start + count * freqAdjust;
UINT dsbfirstep = dsb->firstep;
UINT channels = dsb->mix_channels;
UINT max_ipos = freqAcc_start + count * freqAdjust;
UINT fir_cachesize = (fir_len + dsbfirstep - 2) / dsbfirstep;
UINT required_input = max_ipos + fir_cachesize;
float* intermediate = HeapAlloc(GetProcessHeap(), 0,
sizeof(float) * required_input * channels);
float* fir_copy = HeapAlloc(GetProcessHeap(), 0,
sizeof(float) * fir_cachesize);
/* Important: this buffer MUST be non-interleaved
* if you want -msse3 to have any effect.
* This is good for CPU cache effects, too.
*/
float* itmp = intermediate;
for (channel = 0; channel < channels; channel++)
for (i = 0; i < required_input; i++)
*(itmp++) = get_current_sample(dsb,
dsb->sec_mixpos + i * istride, channel);
for(i = 0; i < count; ++i) {
float total_fir_steps = (freqAcc_start + i * freqAdjust) * dsbfirstep;
UINT int_fir_steps = total_fir_steps;
UINT ipos = int_fir_steps / dsbfirstep;
UINT idx = (ipos + 1) * dsbfirstep - int_fir_steps - 1;
float rem = int_fir_steps + 1.0 - total_fir_steps;
int fir_used = 0;
while (idx < fir_len - 1) {
fir_copy[fir_used++] = fir[idx] * (1.0 - rem) + fir[idx + 1] * rem;
idx += dsb->firstep;
}
assert(fir_used <= fir_cachesize);
assert(ipos + fir_used <= required_input);
for (channel = 0; channel < dsb->mix_channels; channel++) {
int j;
float sum = 0.0;
float* cache = &intermediate[channel * required_input + ipos];
for (j = 0; j < fir_used; j++)
sum += fir_copy[j] * cache[j];
dsb->put(dsb, i * ostride, channel, sum * dsb->firgain);
}
}
freqAcc_end -= (int)freqAcc_end;
*freqAcc = freqAcc_end;
HeapFree(GetProcessHeap(), 0, fir_copy);
HeapFree(GetProcessHeap(), 0, intermediate);
return max_ipos;
}
示例7: Alloc
// Allocates memory with @size, if requested (@zeromem) the memory will be filled with 0x0
void* Alloc(size_t size, bool zeromem = false)
{
return HeapAlloc(GetController()->heap, zeromem? HEAP_ZERO_MEMORY : 0, size);
}
示例8: _realloc_base
void * __cdecl _realloc_base (void * pBlock, size_t newsize)
{
void * pvReturn;
size_t origSize = newsize;
// if ptr is NULL, call malloc
if (pBlock == NULL)
return(_malloc_base(newsize));
// if ptr is nonNULL and size is zero, call free and return NULL
if (newsize == 0)
{
_free_base(pBlock);
return(NULL);
}
#ifndef _WIN64
if ( __active_heap == __V6_HEAP )
{
PHEADER pHeader;
size_t oldsize;
for (;;)
{
pvReturn = NULL;
if (newsize <= _HEAP_MAXREQ)
{
_mlock( _HEAP_LOCK );
__try
{
// test if current block is in the small-block heap
if ((pHeader = __sbh_find_block(pBlock)) != NULL)
{
// if the new size is not over __sbh_threshold, attempt
// to reallocate within the small-block heap
if (newsize <= __sbh_threshold)
{
if (__sbh_resize_block(pHeader, pBlock, (int)newsize))
pvReturn = pBlock;
else if ((pvReturn = __sbh_alloc_block((int)newsize)) != NULL)
{
oldsize = ((PENTRY)((char *)pBlock -
sizeof(int)))->sizeFront - 1;
memcpy(pvReturn, pBlock, __min(oldsize, newsize));
// headers may have moved, get pHeader again
pHeader = __sbh_find_block(pBlock);
__sbh_free_block(pHeader, pBlock);
}
}
// If the reallocation has not been (successfully)
// performed in the small-block heap, try to allocate
// a new block with HeapAlloc.
if (pvReturn == NULL)
{
if (newsize == 0)
newsize = 1;
newsize = (newsize + BYTES_PER_PARA - 1) &
~(BYTES_PER_PARA - 1);
if ((pvReturn = HeapAlloc(_crtheap, 0, newsize)) != NULL)
{
oldsize = ((PENTRY)((char *)pBlock -
sizeof(int)))->sizeFront - 1;
memcpy(pvReturn, pBlock, __min(oldsize, newsize));
__sbh_free_block(pHeader, pBlock);
}
}
}
}
__finally
{
_munlock( _HEAP_LOCK );
}
// the current block is NOT in the small block heap iff pHeader
// is NULL
if ( pHeader == NULL )
{
if (newsize == 0)
newsize = 1;
newsize = (newsize + BYTES_PER_PARA - 1) &
~(BYTES_PER_PARA - 1);
pvReturn = HeapReAlloc(_crtheap, 0, pBlock, newsize);
}
}
else /* newsize > _HEAP_MAXREQ */
{
示例9: aes_ctr_init
static int
aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
{
BCRYPT_ALG_HANDLE hAlg;
BCRYPT_KEY_HANDLE hKey;
DWORD keyObj_len, aes_key_len;
PBYTE keyObj;
ULONG result;
NTSTATUS status;
BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
ctx->hAlg = NULL;
ctx->hKey = NULL;
ctx->keyObj = NULL;
switch (key_len) {
case 16: aes_key_len = 128; break;
case 24: aes_key_len = 192; break;
case 32: aes_key_len = 256; break;
default: return -1;
}
status = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_AES_ALGORITHM,
MS_PRIMITIVE_PROVIDER, 0);
if (!BCRYPT_SUCCESS(status))
return -1;
status = BCryptGetProperty(hAlg, BCRYPT_KEY_LENGTHS, (PUCHAR)&key_lengths,
sizeof(key_lengths), &result, 0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlg, 0);
return -1;
}
if (key_lengths.dwMinLength > aes_key_len
|| key_lengths.dwMaxLength < aes_key_len) {
BCryptCloseAlgorithmProvider(hAlg, 0);
return -1;
}
status = BCryptGetProperty(hAlg, BCRYPT_OBJECT_LENGTH, (PUCHAR)&keyObj_len,
sizeof(keyObj_len), &result, 0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlg, 0);
return -1;
}
keyObj = (PBYTE)HeapAlloc(GetProcessHeap(), 0, keyObj_len);
if (keyObj == NULL) {
BCryptCloseAlgorithmProvider(hAlg, 0);
return -1;
}
status = BCryptSetProperty(hAlg, BCRYPT_CHAINING_MODE,
(PUCHAR)BCRYPT_CHAIN_MODE_ECB, sizeof(BCRYPT_CHAIN_MODE_ECB), 0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlg, 0);
HeapFree(GetProcessHeap(), 0, keyObj);
return -1;
}
status = BCryptGenerateSymmetricKey(hAlg, &hKey,
keyObj, keyObj_len,
(PUCHAR)(uintptr_t)key, (ULONG)key_len, 0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlg, 0);
HeapFree(GetProcessHeap(), 0, keyObj);
return -1;
}
ctx->hAlg = hAlg;
ctx->hKey = hKey;
ctx->keyObj = keyObj;
ctx->keyObj_len = keyObj_len;
ctx->encr_pos = AES_BLOCK_SIZE;
return 0;
}
示例10: UsersPageProc
INT_PTR CALLBACK
UsersPageProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
PUSER_DATA pUserData;
UNREFERENCED_PARAMETER(wParam);
pUserData = (PUSER_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
switch (uMsg)
{
case WM_INITDIALOG:
pUserData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(USER_DATA));
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pUserData);
pUserData->hPopupMenu = LoadMenu(hApplet, MAKEINTRESOURCE(IDM_POPUP_USER));
OnInitDialog(hwndDlg);
SetMenuDefaultItem(GetSubMenu(pUserData->hPopupMenu, 1),
IDM_USER_PROPERTIES,
FALSE);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_USER_CHANGE_PASSWORD:
DialogBoxParam(hApplet,
MAKEINTRESOURCE(IDD_CHANGE_PASSWORD),
hwndDlg,
ChangePasswordDlgProc,
(LPARAM)NULL);
break;
case IDM_USER_RENAME:
UserRename(hwndDlg);
break;
case IDM_USER_NEW:
case IDC_USERS_ADD:
UserNew(hwndDlg);
break;
case IDM_USER_DELETE:
case IDC_USERS_REMOVE:
UserDelete(hwndDlg);
break;
case IDM_USER_PROPERTIES:
case IDC_USERS_PROPERTIES:
if (UserProperties(hwndDlg))
{
UpdateUserProperties(hwndDlg);
}
break;
}
break;
case WM_NOTIFY:
return OnNotify(hwndDlg, pUserData, (NMHDR *)lParam);
case WM_DESTROY:
DestroyMenu(pUserData->hPopupMenu);
HeapFree(GetProcessHeap(), 0, pUserData);
break;
}
return FALSE;
}
示例11: I_RpcAllocate
/******************************************************************************
* I_RpcAllocate ([email protected])
*/
void * WINAPI I_RpcAllocate(unsigned int Size)
{
return HeapAlloc(GetProcessHeap(), 0, Size);
}
示例12: NewUserDlgProc
INT_PTR CALLBACK
NewUserDlgProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
PUSER_INFO_3 userInfo;
INT nLength;
UNREFERENCED_PARAMETER(wParam);
userInfo = (PUSER_INFO_3)GetWindowLongPtr(hwndDlg, DWLP_USER);
switch (uMsg)
{
case WM_INITDIALOG:
userInfo = (PUSER_INFO_3)lParam;
SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);
SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, EM_SETLIMITTEXT, 20, 0);
UpdateUserOptions(hwndDlg, userInfo, TRUE);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_USER_NEW_NAME:
if (HIWORD(wParam) == EN_CHANGE)
{
nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, WM_GETTEXTLENGTH, 0, 0);
EnableWindow(GetDlgItem(hwndDlg, IDOK), (nLength > 0));
}
break;
case IDC_USER_NEW_FORCE_CHANGE:
userInfo->usri3_password_expired = !userInfo->usri3_password_expired;
UpdateUserOptions(hwndDlg, userInfo, FALSE);
break;
case IDC_USER_NEW_CANNOT_CHANGE:
userInfo->usri3_flags ^= UF_PASSWD_CANT_CHANGE;
UpdateUserOptions(hwndDlg, userInfo, FALSE);
break;
case IDC_USER_NEW_NEVER_EXPIRES:
userInfo->usri3_flags ^= UF_DONT_EXPIRE_PASSWD;
UpdateUserOptions(hwndDlg, userInfo, FALSE);
break;
case IDC_USER_NEW_DISABLED:
userInfo->usri3_flags ^= UF_ACCOUNTDISABLE;
break;
case IDOK:
if (!CheckAccountName(hwndDlg, IDC_USER_NEW_NAME, NULL))
{
SetFocus(GetDlgItem(hwndDlg, IDC_USER_NEW_NAME));
SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, EM_SETSEL, 0, -1);
break;
}
if (!CheckPasswords(hwndDlg, IDC_USER_NEW_PASSWORD1, IDC_USER_NEW_PASSWORD2))
{
SetDlgItemText(hwndDlg, IDC_USER_NEW_PASSWORD1, TEXT(""));
SetDlgItemText(hwndDlg, IDC_USER_NEW_PASSWORD2, TEXT(""));
break;
}
/* Store the user name */
nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, WM_GETTEXTLENGTH, 0, 0);
if (nLength > 0)
{
userInfo->usri3_name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
GetDlgItemText(hwndDlg, IDC_USER_NEW_NAME, userInfo->usri3_name, nLength + 1);
}
/* Store the full user name */
nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_FULL_NAME, WM_GETTEXTLENGTH, 0, 0);
if (nLength > 0)
{
userInfo->usri3_full_name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
GetDlgItemText(hwndDlg, IDC_USER_NEW_FULL_NAME, userInfo->usri3_full_name, nLength + 1);
}
/* Store the description */
nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_DESCRIPTION, WM_GETTEXTLENGTH, 0, 0);
if (nLength > 0)
{
userInfo->usri3_comment = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
GetDlgItemText(hwndDlg, IDC_USER_NEW_DESCRIPTION, userInfo->usri3_comment, nLength + 1);
}
/* Store the password */
nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_PASSWORD1, WM_GETTEXTLENGTH, 0, 0);
if (nLength > 0)
{
userInfo->usri3_password = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
GetDlgItemText(hwndDlg, IDC_USER_NEW_PASSWORD1, userInfo->usri3_password, nLength + 1);
}
EndDialog(hwndDlg, IDOK);
//.........这里部分代码省略.........
示例13: GetProcessHeap
//enum processes
void CDlgProcList::EnumProc2List()
{
if(ZwQuerySystemInformation!=NULL)
{
HANDLE hHeap = GetProcessHeap();
NTSTATUS Status;
ULONG cbBuffer = 0x8000;
PVOID pBuffer = NULL;
do
{
pBuffer = HeapAlloc(hHeap, 0, cbBuffer);
if (pBuffer == NULL)
return;
Status = ZwQuerySystemInformation(
SystemProcessesAndThreadsInformation,
pBuffer, cbBuffer, NULL);
if (Status == STATUS_INFO_LENGTH_MISMATCH)
{
HeapFree(hHeap, 0, pBuffer);
cbBuffer *= 2;
}
else if (!NT_SUCCESS(Status))
{
HeapFree(hHeap, 0, pBuffer);
return;
}
}
while (Status == STATUS_INFO_LENGTH_MISMATCH);
PSYSTEM_PROCESS_INFORMATION pProcesses = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
for (;;)
{
PCWSTR pszProcessName = pProcesses->ProcessName.Buffer;
if (pszProcessName == NULL)
pszProcessName = L"Idle";
USES_CONVERSION;
std::string strProcessName=W2A(pszProcessName);
/*m_processlists.insert(std::make_pair(strProcessName,pProcesses->ProcessId));*/
FillRecord2List(strProcessName.c_str(),pProcesses->ProcessId);
if (pProcesses->NextEntryDelta == 0)
break;
// find the address of the next process structure
pProcesses = (PSYSTEM_PROCESS_INFORMATION)(((LPBYTE)pProcesses)
+ pProcesses->NextEntryDelta);
}
HeapFree(hHeap, 0, pBuffer);
}
if(m_processlists.size()!=0)
{
std::map<std::string,DWORD>::iterator iter;
for(iter=m_processlists.begin();iter!=m_processlists.end();iter++)
{
FillRecord2List(iter->first.c_str(),iter->second);
}
}
}
示例14: PSDRV_Brush
/**********************************************************************
*
* PSDRV_Brush
*
*/
BOOL PSDRV_Brush(PSDRV_PDEVICE *physDev, BOOL EO)
{
LOGBRUSH logbrush;
BOOL ret = TRUE;
if(physDev->pathdepth)
return FALSE;
if (!GetObjectA( GetCurrentObject(physDev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
{
ERR("Can't get BRUSHOBJ\n");
return FALSE;
}
switch (logbrush.lbStyle) {
case BS_SOLID:
PSDRV_WriteGSave(physDev);
PSDRV_SetBrush(physDev);
PSDRV_Fill(physDev, EO);
PSDRV_WriteGRestore(physDev);
break;
case BS_HATCHED:
PSDRV_WriteGSave(physDev);
PSDRV_SetBrush(physDev);
switch(logbrush.lbHatch) {
case HS_VERTICAL:
case HS_CROSS:
PSDRV_WriteGSave(physDev);
PSDRV_Clip(physDev, EO);
PSDRV_WriteHatch(physDev);
PSDRV_WriteStroke(physDev);
PSDRV_WriteGRestore(physDev);
if(logbrush.lbHatch == HS_VERTICAL)
break;
/* else fallthrough for HS_CROSS */
case HS_HORIZONTAL:
PSDRV_WriteGSave(physDev);
PSDRV_Clip(physDev, EO);
PSDRV_WriteRotate(physDev, 90.0);
PSDRV_WriteHatch(physDev);
PSDRV_WriteStroke(physDev);
PSDRV_WriteGRestore(physDev);
break;
case HS_FDIAGONAL:
case HS_DIAGCROSS:
PSDRV_WriteGSave(physDev);
PSDRV_Clip(physDev, EO);
PSDRV_WriteRotate(physDev, -45.0);
PSDRV_WriteHatch(physDev);
PSDRV_WriteStroke(physDev);
PSDRV_WriteGRestore(physDev);
if(logbrush.lbHatch == HS_FDIAGONAL)
break;
/* else fallthrough for HS_DIAGCROSS */
case HS_BDIAGONAL:
PSDRV_WriteGSave(physDev);
PSDRV_Clip(physDev, EO);
PSDRV_WriteRotate(physDev, 45.0);
PSDRV_WriteHatch(physDev);
PSDRV_WriteStroke(physDev);
PSDRV_WriteGRestore(physDev);
break;
default:
ERR("Unknown hatch style\n");
ret = FALSE;
break;
}
PSDRV_WriteGRestore(physDev);
break;
case BS_NULL:
break;
case BS_PATTERN:
{
BITMAP bm;
BYTE *bits;
GetObjectA( (HBITMAP)logbrush.lbHatch, sizeof(BITMAP), &bm);
TRACE("BS_PATTERN %dx%d %d bpp\n", bm.bmWidth, bm.bmHeight,
bm.bmBitsPixel);
bits = HeapAlloc(PSDRV_Heap, 0, bm.bmWidthBytes * bm.bmHeight);
GetBitmapBits( (HBITMAP)logbrush.lbHatch, bm.bmWidthBytes * bm.bmHeight, bits);
if(physDev->pi->ppd->LanguageLevel > 1) {
PSDRV_WriteGSave(physDev);
PSDRV_WritePatternDict(physDev, &bm, bits);
PSDRV_Fill(physDev, EO);
PSDRV_WriteGRestore(physDev);
} else {
//.........这里部分代码省略.........
示例15: TMSRPT14
//
// Unrostered runs report
//
BOOL FAR TMSRPT14(TMSRPTPassedDataDef *pPassedData)
{
TMSRPT14RDataDef *pTMSRPT14RData[ROSTER_MAX_DAYS];
HFILE hfOutputFile;
BOOL bKeepGoing = FALSE;
BOOL bFound;
long numRuns[ROSTER_MAX_DAYS];
char szOutputString[128];
char szDay[16];
char dummy[256];
long maxRuns;
int days[ROSTER_MAX_DAYS] = {TEXT_009, TEXT_010, TEXT_011,
TEXT_012, TEXT_013, TEXT_014, TEXT_015};
int nI;
int nJ;
int nK;
int nL;
int rcode2;
pPassedData->nReportNumber = 13;
pPassedData->numDataFiles = 1;
for(nI = 0; nI < m_LastReport; nI++)
{
if(TMSRPT[nI].originalReportNumber == pPassedData->nReportNumber)
{
StatusBarStart(hWndMain, TMSRPT[nI].szReportName);
break;
}
}
//
// Open the output file
//
StatusBarText("Opening output file...");
strcpy(tempString, szReportsTempFolder);
strcat(tempString, "\\tmsrpt14.txt");
hfOutputFile = _lcreat(tempString, 0);
if(hfOutputFile == HFILE_ERROR)
{
LoadString(hInst, ERROR_202, szFormatString, sizeof(szFormatString));
sprintf(szarString, szFormatString, tempString);
MessageBeep(MB_ICONSTOP);
MessageBox((HWND)NULL, szarString, TMS, MB_ICONSTOP);
goto deallocate;
}
strcpy(pPassedData->szReportDataFile[0], tempString);
//
// Initialize the TMSRPT14RData and TMSRPT14RDataData structures
//
rcode2 = btrieve(B_STAT, TMS_RUNS, &BSTAT, dummy, 0);
if(rcode2 != 0 || BSTAT.numRecords == 0)
{
TMSError((HWND)NULL, MB_ICONSTOP, ERROR_266, (HANDLE)NULL);
goto deallocate;
}
maxRuns = BSTAT.numRecords;
for(nI = 0; nI < ROSTER_MAX_DAYS; nI++)
{
numRuns[nI] = 0;
pTMSRPT14RData[nI] = (TMSRPT14RDataDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TMSRPT14RDataDef) * maxRuns);
if(pTMSRPT14RData[nI] == NULL)
{
AllocationError(__FILE__, __LINE__, FALSE);
goto deallocate;
}
}
//
// Read the runs into TMSRPT14RData
//
for(nI = 0; nI < ROSTER_MAX_DAYS; nI++)
{
LoadString(hInst, days[nI], szDay, sizeof(szDay));
sprintf(tempString, "Reading %s runs...", szDay);
StatusBarText(tempString);
if(StatusBarAbort())
{
goto deallocate;
}
if(ROSTERPARMS.serviceDays[nI] == NO_RECORD)
{
continue;
}
RUNSKey1.DIVISIONSrecordID = m_DivisionRecordID;
RUNSKey1.SERVICESrecordID = ROSTERPARMS.serviceDays[nI];
RUNSKey1.runNumber = NO_RECORD;
RUNSKey1.pieceNumber = NO_RECORD;
rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
while(rcode2 == 0 &&
RUNS.DIVISIONSrecordID == m_DivisionRecordID &&
RUNS.SERVICESrecordID == ROSTERPARMS.serviceDays[nI])
{
if(RUNS.pieceNumber == 1)
{
pTMSRPT14RData[nI][numRuns[nI]].recordID = RUNS.recordID;
pTMSRPT14RData[nI][numRuns[nI]].runNumber = RUNS.runNumber;
pTMSRPT14RData[nI][numRuns[nI]].cutAsRuntype = RUNS.cutAsRuntype;
numRuns[nI]++;
}
//.........这里部分代码省略.........