您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ HeapAlloc函数代码示例

51自学网 2021-06-01 21:25:47
  C++
这篇教程C++ HeapAlloc函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中HeapAlloc函数的典型用法代码示例。如果您正苦于以下问题:C++ HeapAlloc函数的具体用法?C++ HeapAlloc怎么用?C++ HeapAlloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了HeapAlloc函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;}
开发者ID:gkscndrl,项目名称:GoldRushData,代码行数:67,


示例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;}
开发者ID:r6144,项目名称:wine,代码行数:101,


示例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//.........这里部分代码省略.........
开发者ID:ccpgames,项目名称:wine,代码行数:101,


示例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);//.........这里部分代码省略.........
开发者ID:Dimillian,项目名称:wine,代码行数:101,


示例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;//.........这里部分代码省略.........
开发者ID:WASSUM,项目名称:longene_travel,代码行数:101,


示例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;}
开发者ID:ZoloZiak,项目名称:reactos,代码行数:67,


示例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); }
开发者ID:MasterHK,项目名称:plugin-sdk,代码行数:5,


示例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 */                {
开发者ID:flychen50,项目名称:clib,代码行数:90,


示例9: aes_ctr_init

static intaes_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;}
开发者ID:Bebere,项目名称:libarchive,代码行数:70,


示例10: UsersPageProc

INT_PTR CALLBACKUsersPageProc(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;}
开发者ID:RareHare,项目名称:reactos,代码行数:72,


示例11: I_RpcAllocate

/****************************************************************************** * I_RpcAllocate   ([email
C++ HeapAllocateBuffer函数代码示例
C++ HealthBelowPct函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。