当前位置: 首页>>代码示例>>C++>>正文


C++ AutoProcessHeapPtr::Detach方法代码示例

本文整理汇总了C++中xtl::AutoProcessHeapPtr::Detach方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoProcessHeapPtr::Detach方法的具体用法?C++ AutoProcessHeapPtr::Detach怎么用?C++ AutoProcessHeapPtr::Detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xtl::AutoProcessHeapPtr的用法示例。


在下文中一共展示了AutoProcessHeapPtr::Detach方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sizeof

PSTORAGE_DESCRIPTOR_HEADER
pStorageQueryProperty(
	HANDLE hDevice,
	STORAGE_PROPERTY_ID PropertyId,
	STORAGE_QUERY_TYPE  QueryType)
{
	STORAGE_PROPERTY_QUERY spquery;
	::ZeroMemory(&spquery, sizeof(spquery));
	spquery.PropertyId = PropertyId;
	spquery.QueryType = QueryType;

	DWORD bufferLength = sizeof(STORAGE_DESCRIPTOR_HEADER);
	XTL::AutoProcessHeapPtr<STORAGE_DESCRIPTOR_HEADER> buffer =
		static_cast<STORAGE_DESCRIPTOR_HEADER*>(
			::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, bufferLength));
	if (buffer.IsInvalid())
	{
		return NULL;
	}

	DWORD returnedLength;
	BOOL fSuccess = ::DeviceIoControl(
		hDevice, IOCTL_STORAGE_QUERY_PROPERTY, 
		&spquery, sizeof(spquery),
		buffer, bufferLength,
		&returnedLength, NULL);
	if (!fSuccess)
	{
		XTLTRACE_ERR("IOCTL_STORAGE_QUERY_PROPERTY(HEADER) failed.\n");
		return NULL;
	}

	// We only retrived the header, now we reallocate the buffer
	// required for the actual query
	bufferLength = buffer->Size; 
	XTL::AutoProcessHeapPtr<STORAGE_DESCRIPTOR_HEADER> newBuffer =
		static_cast<STORAGE_DESCRIPTOR_HEADER*>(
			::HeapReAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, buffer, bufferLength));
	if (newBuffer.IsInvalid())
	{
		return NULL;
	}
	// set the buffer with the new buffer
	buffer.Detach();
	buffer = newBuffer.Detach();
	
	// now we can query the actual property with the proper size
	fSuccess = ::DeviceIoControl(
		hDevice, IOCTL_STORAGE_QUERY_PROPERTY, 
		&spquery, sizeof(spquery),
		buffer, bufferLength,
		&returnedLength, NULL);
	if (!fSuccess)
	{
		XTLTRACE_ERR("IOCTL_STORAGE_QUERY_PROPERTY(DATA) failed.\n");
		return NULL;
	}

	return buffer.Detach();
}
开发者ID:tigtigtig,项目名称:ndas4windows,代码行数:60,代码来源:winioctlhelper.cpp

示例2: pCMGetDeviceIDList

LPTSTR
pGetVolumeInstIdListForDisk(
    LPCTSTR DiskInstId)
{
    // Disk and volumes are removal relations.
    XTL::AutoProcessHeapPtr<TCHAR> VolumeInstIdList;
    CONFIGRET ret = pCMGetDeviceIDList(
                        &VolumeInstIdList,
                        DiskInstId,
                        CM_GETIDLIST_FILTER_REMOVALRELATIONS);
    if (CR_SUCCESS != ret)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "pCMGetDeviceIDList failed, cret=0x%X\n", ret);
        ::SetLastError(ConfigRetToWin32Error(ret));
        return NULL;
    }
    return VolumeInstIdList.Detach();
}
开发者ID:yzx65,项目名称:ndas4windows,代码行数:19,代码来源:cmquery.cpp

示例3: sizeof

HRESULT
pGetVolumeMountPointForPathW(
	__in LPCWSTR Path,
	__out LPWSTR* MountPoint)
{
	if (NULL == MountPoint)
	{
		return E_POINTER;
	}

	*MountPoint = NULL;

	// TODO: It is possible to be the path is more than MAX_PATH
	// in case of supporting unicode file names up to 65534
	DWORD mountPointLength = MAX_PATH;
	XTL::AutoProcessHeapPtr<TCHAR> mountPoint = 
		static_cast<TCHAR*>(
			::HeapAlloc(
				::GetProcessHeap(), 
				HEAP_ZERO_MEMORY,
				mountPointLength * sizeof(WCHAR)));

	if (mountPoint.IsInvalid())
	{
		return E_OUTOFMEMORY;
	}

	if (!GetVolumePathName(Path, mountPoint, mountPointLength))
	{
		HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
		XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
			"GetVolumePathName(%ls) failed, hr=0x%X\n",
			Path, hr);
		return hr;
	}

	XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION,
		"Path(%ls) is mounted from %s.\n", Path, mountPoint);

	*MountPoint = mountPoint.Detach();

	return S_OK;
}
开发者ID:tigtigtig,项目名称:ndas4windows,代码行数:43,代码来源:devrel.cpp

示例4: pCMGetDeviceInterfaceList

LPTSTR
pGetDeviceSymbolicLinkList(
    LPCGUID InterfaceClassGuid,
    DEVINSTID DevInstId,
    ULONG Flags /*= CM_GET_DEVICE_INTERFACE_LIST_PRESENT*/)
{
    XTL::AutoProcessHeapPtr<TCHAR> SymbolicLinkList;
    CONFIGRET ret = pCMGetDeviceInterfaceList(
                        &SymbolicLinkList,
                        const_cast<LPGUID>(InterfaceClassGuid),
                        DevInstId,
                        Flags);
    if (CR_SUCCESS != ret)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "pCMGetDeviceInterfaceList failed, cret=0x%X\n", ret);
        ::SetLastError(ConfigRetToWin32Error(ret));
        return NULL;
    }
    return SymbolicLinkList.Detach();
}
开发者ID:yzx65,项目名称:ndas4windows,代码行数:21,代码来源:cmquery.cpp

示例5: GetLastError

//
// Returns the symbolic link name of the disk.
//
// Caller should free the non-null returned pointer
// with HeapFree(GetProcessHeap(),...)
//
LPTSTR
pGetChildDevInstIdsForNdasScsiLocation(
    const NDAS_SCSI_LOCATION* NdasScsiLocation)
{
    DEVINST NdasScsiDevInst;
    if (!pFindNdasScsiDevInst(&NdasScsiDevInst, NdasScsiLocation->SlotNo))
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "FindNdasScsiDevInst failed, error=0x%X\n", GetLastError());
        return NULL;
    }

    TCHAR NdasScsiInstanceId[MAX_DEVICE_ID_LEN];
    CONFIGRET ret = ::CM_Get_Device_ID(
                        NdasScsiDevInst,
                        NdasScsiInstanceId,
                        RTL_NUMBER_OF(NdasScsiInstanceId),
                        0);
    if (CR_SUCCESS != ret)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "CM_Get_Device_ID failed, cret=0x%X\n", ret);
        return NULL;
    }

    XTL::AutoProcessHeapPtr<TCHAR> ChildDevInstIdList;
    ret = pCMGetDeviceIDList(
              &ChildDevInstIdList,
              NdasScsiInstanceId,
              CM_GETIDLIST_FILTER_BUSRELATIONS);
    if (CR_SUCCESS != ret)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "pCMGetDeviceIDList failed, cret=0x%X\n", ret);
        ::SetLastError(ConfigRetToWin32Error(ret));
        return NULL;
    }

    return ChildDevInstIdList.Detach();
}
开发者ID:yzx65,项目名称:ndas4windows,代码行数:46,代码来源:cmquery.cpp

示例6: MsiGetProperty

LPTSTR
pMsiGetProperty(
    MSIHANDLE hInstall, 
    LPCTSTR szPropertyName,
    LPDWORD pcch)
{
	HANDLE hHeap = ::GetProcessHeap();
	XTL::AutoProcessHeapPtr<TCHAR> pszValue;
    DWORD cchValue = 0;
    
    UINT msiret = MsiGetProperty(hInstall, szPropertyName, _T(""), &cchValue);
    
    if (ERROR_SUCCESS != msiret && ERROR_MORE_DATA != msiret)
    {
        return NULL;
    }
    
    if (ERROR_MORE_DATA == msiret)
    {
        ++cchValue;
        pszValue = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, cchValue * sizeof(TCHAR));
        if (NULL == (LPTSTR) pszValue)
        {
            return NULL;
        }
        msiret = MsiGetProperty(hInstall, szPropertyName, pszValue, &cchValue);
        if (ERROR_SUCCESS != msiret)
        {
            return NULL;
        }
    }

    if (NULL != pcch)
    {
        *pcch = cchValue;
    }
    
    return pszValue.Detach();
}
开发者ID:Nevermore2015,项目名称:ndas4windows,代码行数:39,代码来源:msisup.cpp

示例7: MsiGetSourcePath

LPTSTR
pMsiGetSourcePath(
    MSIHANDLE hInstall, 
    LPCTSTR szFolder,
    LPDWORD pcch)
{
    XTL::AutoProcessHeapPtr<TCHAR> pszValue;
    DWORD cchValue = 0;

    UINT msiret = MsiGetSourcePath(hInstall, szFolder, _T(""), &cchValue);

    if (ERROR_MORE_DATA == msiret)
    {
        ++cchValue;
        pszValue = (LPTSTR) HeapAlloc(
            GetProcessHeap(), 
            0, 
            cchValue * sizeof(TCHAR));

        if (NULL == (LPTSTR) pszValue)
        {
            return NULL;
        }

        msiret = MsiGetSourcePath(hInstall, szFolder, pszValue, &cchValue);
    }

    if (ERROR_SUCCESS != msiret)
    {
        return NULL;
    }

    if (NULL != pcch)
    {
        *pcch = cchValue;
    }
    
    return pszValue.Detach();
}
开发者ID:Nevermore2015,项目名称:ndas4windows,代码行数:39,代码来源:msisup.cpp

示例8: pGetChildDevInstIdsForNdasScsiLocation

LPTSTR
pGetDiskForNdasScsiLocationEx(
    const NDAS_SCSI_LOCATION* NdasScsiLocation,
    BOOL SymbolicLinkOrDevInstId)
{
    // Get the child device instances of the NDAS SCSI pdo
    XTL::AutoProcessHeapPtr<TCHAR> ChildDevInstIdList =
        pGetChildDevInstIdsForNdasScsiLocation(NdasScsiLocation);

    // Find the disk of TargetID and LUN for all child device instances
    for (LPCTSTR ChildDevInstId = ChildDevInstIdList;
            ChildDevInstId && *ChildDevInstId;
            ChildDevInstId += ::lstrlen(ChildDevInstId) + 1)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_VERBOSE,
                  _T("ChildDevInstId:%s\n"), ChildDevInstId);

        // Ensure that the child really is present (not ghosted)
        DEVINST ChildDevInst;
        CONFIGRET ret = ::CM_Locate_DevNode(
                            &ChildDevInst,
                            const_cast<DEVINSTID>(ChildDevInstId),
                            CM_LOCATE_DEVNODE_NORMAL);
        if (CR_SUCCESS != ret)
        {
            XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                      "CM_Locate_DevNode failed, cret=0x%X\n", ret);
            continue;
        }

        // Query the Disk Class Interface, if there are no disk class
        // interface, it is not of a disk class.
        XTL::AutoProcessHeapPtr<TCHAR> SymLinkList;
        ret = pCMGetDeviceInterfaceList(
                  &SymLinkList,
                  &DiskClassGuid,
                  const_cast<DEVINSTID>(ChildDevInstId),
                  CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
        if (CR_SUCCESS != ret)
        {
            XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                      "pCMGetDeviceInterfaceList failed, cret=0x%X\n", ret);
            continue;
        }

        // Returned list contains the list of the device file names (or
        // symbolic links) which we can open with CreateFile for IO_CTLs
        for (LPCTSTR DeviceName = SymLinkList;
                DeviceName && *DeviceName;
                DeviceName += ::lstrlen(DeviceName) + 1)
        {
            XTLTRACE2(NdasVolTrace, TRACE_LEVEL_VERBOSE,
                      _T("Device:%s\n"), DeviceName);
            XTL::AutoFileHandle hDevice = ::CreateFile(
                                              DeviceName,
                                              GENERIC_READ,
                                              FILE_SHARE_READ | FILE_SHARE_WRITE,
                                              NULL,
                                              OPEN_EXISTING,
                                              0,
                                              NULL);
            if (hDevice.IsInvalid())
            {
                XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                          _T("CreateFile(%s) failed, error=0x%X\n"),
                          DeviceName, GetLastError());
                continue;
            }
            // Query the SCSI Address and compare TargetID and LUN to
            // compare them with those of NDAS SCSI location.
            SCSI_ADDRESS scsiAddress;
            if (!pScsiGetAddress(hDevice, &scsiAddress))
            {
                XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                          _T("GetScsiAddress(%s) failed, error=0x%X\n"),
                          DeviceName, GetLastError());
                continue;
            }
            if (NdasScsiLocation->TargetID == scsiAddress.TargetId &&
                    NdasScsiLocation->LUN == scsiAddress.Lun)
            {
                // We found the target disk, and we create a buffer to
                // return. If SymbolicLinkOrDevInstId is non-zero (TRUE),
                // we will returns SymbolicLink, otherwise, we will return the DevInstId
                if (SymbolicLinkOrDevInstId)
                {
                    DWORD TargetLength = (::lstrlen(DeviceName) + 1) * sizeof(TCHAR);
                    XTL::AutoProcessHeapPtr<TCHAR> TargetDeviceName =
                        static_cast<LPTSTR>(
                            ::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, TargetLength));
                    if (TargetDeviceName.IsInvalid())
                    {
                        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                                  "HeapAlloc failed, byets=%d\n", TargetLength);
                        return NULL;
                    }
                    ::CopyMemory(TargetDeviceName, DeviceName, TargetLength);
                    return TargetDeviceName.Detach();
                }
                else
//.........这里部分代码省略.........
开发者ID:yzx65,项目名称:ndas4windows,代码行数:101,代码来源:cmquery.cpp

示例9: sizeof

CONFIGRET
pCMGetDeviceIDList(
    LPTSTR* RelDevInstIdList,
    LPCTSTR DevInstId,
    ULONG Flags)
{
    XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION,
              _T("DevInstId=%s,Flags=%08X\n"), DevInstId, Flags);

    *RelDevInstIdList = NULL;

    ULONG bufferLength;
    CONFIGRET ret = ::CM_Get_Device_ID_List_Size(
                        &bufferLength,
                        DevInstId,
                        Flags);
    if (CR_SUCCESS != ret)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "CM_Get_Device_ID_List_Size failed with cret=0x%X.\n", ret);
        return ret;
    }

    XTLTRACE2(NdasVolTrace, TRACE_LEVEL_VERBOSE,
              "RequiredBufferSize=%d chars\n", bufferLength);
    if (0 == bufferLength)
    {
        TCHAR* empty = static_cast<TCHAR*>(
                           ::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, 2 * sizeof(TCHAR)));
        *RelDevInstIdList = empty;
        return CR_SUCCESS;
    }

    XTL::AutoProcessHeapPtr<TCHAR> buffer = static_cast<TCHAR*>(
            ::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, bufferLength * sizeof(TCHAR)));
    if (buffer.IsInvalid())
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "HeapAlloc failed, bytes=%d\n", bufferLength * sizeof(TCHAR));
        return CR_OUT_OF_MEMORY;
    }

    ret = ::CM_Get_Device_ID_List(
              DevInstId,
              buffer,
              bufferLength,
              Flags);
    if (CR_SUCCESS != ret)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "CM_Get_Device_ID_List failed with cret=0x%X.\n", ret);
        return ret;
    }

    *RelDevInstIdList = buffer.Detach();

    XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION,
              _T("RelDevInstIdList=%s\n"), *RelDevInstIdList);

    return CR_SUCCESS;
}
开发者ID:yzx65,项目名称:ndas4windows,代码行数:61,代码来源:cmquery.cpp

示例10: pGetDiskForNdasScsiLocationEx

//
// Returns the symbolic link name list of the volume.
// Each entry is null-terminated and the last entry is terminated
// by an additional null character
//
// Caller should free the non-null returned pointer
// with HeapFree(GetProcessHeap(),...)
//
LPTSTR
pGetVolumesForNdasScsiLocation(
    const NDAS_SCSI_LOCATION* NdasScsiLocation)
{
    // Get the disk instance id of the location
    XTL::AutoProcessHeapPtr<TCHAR> DiskInstId =
        pGetDiskForNdasScsiLocationEx(NdasScsiLocation, FALSE);

    if (DiskInstId.IsInvalid())
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "GetDiskDevInstId failed, error=0x%X\n", GetLastError());
        return NULL;
    }

    // Get the volume instance id list of the disk
    XTL::AutoProcessHeapPtr<TCHAR> VolumeInstIdList =
        pGetVolumeInstIdListForDisk(DiskInstId);
    if (VolumeInstIdList.IsInvalid())
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "GetVolumeInstIdList failed, error=0x%X\n", GetLastError());
        return NULL;
    }

    // Get the volume names of the disk (via interface query)
    // Preallocate the buffer up to MAX_PATH
    DWORD bufferLength = MAX_PATH * sizeof(TCHAR);
    DWORD bufferRemaining = bufferLength;
    XTL::AutoProcessHeapPtr<TCHAR> buffer = static_cast<LPTSTR>(
            ::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, bufferLength));
    LPTSTR bufferNext = static_cast<LPTSTR>(buffer); // direct resource access (non-const)

    for (LPCTSTR VolumeInstId = VolumeInstIdList;
            VolumeInstId && *VolumeInstId;
            VolumeInstId += ::lstrlen(VolumeInstId) + 1)
    {
        // Actually returned buffer is a list of null-terminated strings
        // but we queried for a specific instance id and for the specific
        // class, where only one or zero volume name may return.
        // So the return type is just a single string.
        XTL::AutoProcessHeapPtr<TCHAR> VolumeName =
            pGetDeviceSymbolicLinkList(
                &GUID_DEVINTERFACE_VOLUME,
                const_cast<LPTSTR>(VolumeInstId),
                CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
        if (VolumeName.IsInvalid())
        {
            // may not be a volume
            XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION,
                      _T("%s is not a volume device\n"), VolumeInstId);
            continue;
        }
        for (LPCTSTR VN = VolumeName; VN && *VN; VN += ::lstrlen(VN) + 1)
        {
            XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION,
                      _T("VolumeName=%s\n"), VN);
        }

        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION,
                  _T("VolumeName=%s\n"), VolumeName);

        DWORD volumeNameLength = ::lstrlen(VolumeName);
        DWORD bufferRequired =  (volumeNameLength + 1) * sizeof(TCHAR);
        if (bufferRemaining < bufferRequired)
        {
            XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION,
                      "Reallocation\n");
            XTL::AutoProcessHeapPtr<TCHAR> newBuffer = static_cast<LPTSTR>(
                        ::HeapReAlloc(
                            ::GetProcessHeap(),
                            HEAP_ZERO_MEMORY,
                            buffer,
                            bufferLength + bufferRequired - bufferRemaining));
            if (newBuffer.IsInvalid())
            {
                XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                          "HeapReAlloc failed, bytes=%d\n",
                          bufferLength + bufferLength - bufferRemaining);
                return NULL;
            }
            size_t bufferNextOffset =
                reinterpret_cast<BYTE*>(bufferNext) -
                reinterpret_cast<BYTE*>(*(&buffer));
            // discard the old buffer and attach it to the new buffer
            buffer.Detach();
            buffer = newBuffer.Detach();
            bufferNext = reinterpret_cast<TCHAR*>(
                             reinterpret_cast<BYTE*>(static_cast<LPTSTR>(buffer)) + bufferNextOffset);
        }
        ::CopyMemory(bufferNext, VolumeName, bufferRequired);
        bufferNext += volumeNameLength + 1;
//.........这里部分代码省略.........
开发者ID:yzx65,项目名称:ndas4windows,代码行数:101,代码来源:cmquery.cpp


注:本文中的xtl::AutoProcessHeapPtr::Detach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。