如题:
怎么老是返回C:\

解决方案 »

  1.   

    返回的字符串形式是这样的:比如你有C,D,E三个分区,这时函数返回的字符串是"C:\0D:\0E:\00",
    就是说每个盘符后面都有一个结束符,你如果简单的printf("%s",str)的话,只能得到C:,连续遇到两个结束符才算结束..
      

  2.   

    楼上是正解:
    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);
    } }
      

  3.   

    不好意思,我的代码摘自UNICODE环境
    估计所有 + 2 的地方都要改为 + 1
      

  4.   


        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);
        }