阅读:3641回复:3
[求助]用CreateFile函数时如何获取设备名
CreateFile函数第一个参数是要打开设备的设备名
请问如何获取设备名??? |
|
最新喜欢:phoeni... |
沙发#
发布于:2007-06-05 21:49
这个应该跟fopen(char *p,char *flag)里的第一个参数一样,
例如C:\\test\\test.txt 如果是驱动里的设备的话我就不知道了。 |
|
|
板凳#
发布于:2007-06-13 20:29
\\.\PHYSICALDRIVE0 表示打开第一个物理设备,依次类推
MSDN上面都有 |
|
地板#
发布于:2007-06-29 17:54
win32 api: QueryDosDevice 可以枚举当前系统中的所有设备名,不知道是不是你想要的。
昨天看到这个函数,写了个demo,先贴出来。 // QueryDosDevice.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <windows.h> void printmsg() { printf(" QueryDosDevice Example v0.1\n"); printf(" Author: ×××××××××××××\n"); printf(" Date: 2007-06-29 11:20\n"); printf(" CopyRigth(C) 2007 All Right Reserved\n\n"); } int main(int argc, char* argv[]) { int dwReturn, dwMaxSize, iCount; LPSTR szDeviceNames, szTemp; dwMaxSize = 1024; szDeviceNames = new char[dwMaxSize]; printmsg(); ZeroMemory(szDeviceNames, dwMaxSize); dwReturn = QueryDosDevice(NULL, szDeviceNames, dwMaxSize); if (dwReturn <= 0) // for 2k/xp { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { while (dwReturn == 0) { delete [] szDeviceNames; dwMaxSize = dwMaxSize * 2; szDeviceNames = new char[dwMaxSize]; dwReturn = QueryDosDevice(NULL, szDeviceNames, dwMaxSize); } } else { delete [] szDeviceNames; printf("error occurs #%d. \n", GetLastError()); return 0; } } else { delete [] szDeviceNames; dwMaxSize = dwReturn; szDeviceNames = new char[dwMaxSize]; }; ZeroMemory(szDeviceNames, dwMaxSize); dwReturn = QueryDosDevice(NULL, szDeviceNames, dwMaxSize); szTemp = szDeviceNames; printf(" DosDeviceName List: \n\n"); iCount = 1; printf(" %4d, ", iCount); while (! ((*szTemp == '\0') && (*(szTemp + 1) == '\0'))) { if (*szTemp == '\0') { iCount++; printf("\n %4d, ", iCount); } else printf("%c", *szTemp); szTemp++; } delete [] szDeviceNames; printf("\n\n finished. total %d DosDiviceName. press any key to exit.", iCount); scanf("%c", &szTemp); return 0; } |
|