c#中如何使用GetLogicalDriveStrings()

xiwen_cai 2005-09-04 03:40:10
C#中如何使用GetLogicalDriveStrings(),最好有實例
...全文
165 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyi8808 2005-09-04
  • 打赏
  • 举报
回复
using System;

class Sample
{
static void Main()
{
Console.WriteLine();
String [] drives = Environment.GetLogicalDrives();
Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
}
}

/* 程序输出:
GetLogicalDrives: A:\, D:\, E:\, F:\, O:\
*/
xiwen_cai 2005-09-04
  • 打赏
  • 举报
回复
我的意思是
const int nChars = 128;
StringBuilder Buff = new StringBuilder(nChars);
GetLogicalDriveStrings(nChars,Buff);
Buff.toString()得到的不是所有邏輯盤符,而只是A:\
如何才能得到所有的邏輯盤符
lyzzbbgo 2005-09-04
  • 打赏
  • 举报
回复
GetLogicalDriveStrings

The GetLogicalDriveStrings function fills a buffer with strings that specify valid drives in the system.


DWORD GetLogicalDriveStrings(
DWORD nBufferLength,
LPTSTR lpBuffer
);

Parameters
nBufferLength
[in] Maximum size of the buffer pointed to by lpBuffer, in TCHARs. This size does not include the terminating null character. If this parameter is zero, lpBuffer is not used.
lpBuffer
[out] Pointer to a buffer that receives a series of null-terminated strings, one for each valid drive in the system, that end with a second null character. The following example shows the buffer contents with <null> representing the terminating null character.
c:\<null>d:\<null><null>

明白了吧
xiwen_cai 2005-09-04
  • 打赏
  • 举报
回复
我明白不一定要用API,但是我想知道如何用
wxwx110 2005-09-04
  • 打赏
  • 举报
回复
没必要一定用API啊
xiwen_cai 2005-09-04
  • 打赏
  • 举报
回复
我明白這個API怎么用,在C#中我想用它來返回本机所有的邏輯盤符,

const int nChars = 128;
StringBuilder Buff = new StringBuilder(nChars);
GetLogicalDriveStrings(nChars,Buff);

但只能得到A:\,而不是所有的.
lovefootball 2005-09-04
  • 打赏
  • 举报
回复
只是一个很简单的api

手头没有资料
明天给你详细的语法

这种东西都是最基本的语法

建议楼主看看msdn的介绍

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧