CnCrypt代码 之 为磁盘设备分配和移除盘符
BOOL ChangeMountPoint(int nDriveNo, LPCTSTR lpDevice, BOOL bAddMountPoint)
{
	BOOL bResult = FALSE;
	TCHAR szDriveLetterAndSlash[4] = { 0 };
	TCHAR szDriveLetter[3] = { 0 };
	TCHAR szUniqueVolumeName[MAX_PATH] = { 0 };
	szDriveLetter[0] = (WCHAR)(nDriveNo + L'A');
	szDriveLetter[1] = TEXT(':');
	szDriveLetter[2] = TEXT('\0');

	szDriveLetterAndSlash[0] = (WCHAR)(nDriveNo + L'A');
	szDriveLetterAndSlash[1] = TEXT(':');
	szDriveLetterAndSlash[2] = TEXT('\\');
	szDriveLetterAndSlash[3] = TEXT('\0');
	if (bAddMountPoint)
	{
		//Try to Attach lpDevice to lpDriveLetter
		bResult = DefineDosDevice(DDD_RAW_TARGET_PATH, szDriveLetter,
			lpDevice);

		if (bResult)
		{
			if (!GetVolumeNameForVolumeMountPoint(szDriveLetterAndSlash,
				szUniqueVolumeName,
				MAX_PATH))
			{
				//Can't Find Attached lpDevice 's VolumeName
				szUniqueVolumeName[0] = '\0';
			}

			bResult = DefineDosDevice(
				DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION |
				DDD_EXACT_MATCH_ON_REMOVE, szDriveLetter,
				lpDevice);

			if (!bResult)
				return bResult;

			bResult = SetVolumeMountPoint(szDriveLetterAndSlash,
				szUniqueVolumeName);
		}
	}
	else
	{
		bResult = DeleteVolumeMountPoint(szDriveLetterAndSlash);
	}

	return bResult;
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cncrypt/article/details/51951702
想对作者说点什么? 我来说一句

MTP 出现多个盘符

MTP error

q1183345443 q1183345443

2016-10-27 16:12:04

阅读数:191

没有更多推荐了,返回首页

不良信息举报

CnCrypt代码 之 为磁盘设备分配和移除盘符

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭