GetLogicalDriveString怎么不返回所有盘? 如题:怎么老是返回C:\ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 返回的字符串形式是这样的:比如你有C,D,E三个分区,这时函数返回的字符串是"C:\0D:\0E:\00",就是说每个盘符后面都有一个结束符,你如果简单的printf("%s",str)的话,只能得到C:,连续遇到两个结束符才算结束.. 楼上是正解: char *pFind = NULL; char driver[10][5]; int count = 0; int len = GetLogicalDriveStrings( 1024, // size of buffer path // drive strings buffer ); if(len > 0) {//有逻辑卷 for( char *pLogic = path, pFind = strstr(pLogic, "\\"); pFind != NULL && pLogic - path < len; pLogic = pFind + 2, pFind = strstr(pLogic, "\\")) {//找到逻辑卷标名称:A: C: D: 等 memcpy(driver[count++], pLogic, pFind - pLogic + 2); } } 不好意思,我的代码摘自UNICODE环境估计所有 + 2 的地方都要改为 + 1 TCHAR lpBuffer[256] = {0}; TCHAR temp[8] = {0}; int i = 0; ::GetLogicalDriveStrings(255, lpBuffer); while(lpBuffer[i]) { _tcscpy_s(temp, _countof(temp), &lpBuffer[i]); i += 4; MessageBox(temp); } 又见棘手问题,关于VC下位图显示 高分求教:如何截取图片任意形状的子图? socket通信数据丢失的问题。 问题1 Thumbs.db很可怕哦!!!!!!!!! 紧急求救:PreTranslateMessage ()!!! BIOS的万能密码!!!!!!!!!!!!!!1 谁来帮帮我? 请问各位,怎样通过一个子窗口关闭主窗口? 动态创建控件问题 关于IP地址转为字符串的问题 求教:如何在VC++6.0中给对话框类添加一个成员变量
就是说每个盘符后面都有一个结束符,你如果简单的printf("%s",str)的话,只能得到C:,连续遇到两个结束符才算结束..
char *pFind = NULL;
char driver[10][5];
int count = 0;
int len = GetLogicalDriveStrings(
1024, // size of buffer
path // drive strings buffer
);
if(len > 0)
{//有逻辑卷
for( char *pLogic = path, pFind = strstr(pLogic, "\\");
pFind != NULL && pLogic - path < len;
pLogic = pFind + 2, pFind = strstr(pLogic, "\\"))
{//找到逻辑卷标名称:A: C: D: 等
memcpy(driver[count++], pLogic, pFind - pLogic + 2);
} }
估计所有 + 2 的地方都要改为 + 1
TCHAR lpBuffer[256] = {0};
TCHAR temp[8] = {0};
int i = 0; ::GetLogicalDriveStrings(255, lpBuffer);
while(lpBuffer[i])
{
_tcscpy_s(temp, _countof(temp), &lpBuffer[i]);
i += 4;
MessageBox(temp);
}