[每日一码] 实现磁盘驱动器相关(序列号等)信息返回给LISP使用
#include "StdAfx.h"#include "VolumeManagement.h"
#pragma region //DriveTypeFlags
struct // DriveType
{
UINT type; // return code from GetDriveType
LPCTSTR name; // ascii name
}
DriveTypeFlags [] =
{
{ DRIVE采用UNKNOWN, 采用T("Unknown") },
{ DRIVE采用NO采用ROOT采用DIR, 采用T("Invalid path") },
{ DRIVE采用REMOVABLE, 采用T("Removable") },
{ DRIVE采用FIXED, 采用T("Fixed") },
{ DRIVE采用REMOTE, 采用T("Network drive") },
{ DRIVE采用CDROM, 采用T("CD-ROM") },
{ DRIVE采用RAMDISK, 采用T("RAM disk") },
{ 0, NULL}
};
#pragma endregion
#pragma region //driveserialno
//(crpdriveserialno "c")
int DriveSerialNo(void)
{
//Declare string variables
CString str;
struct resbuf *pArgs =acedGetArgs ();
if(pArgs == NULL)
str = 采用T("C");
else
{
if(pArgs->restype == RTSTR)
str = pArgs->resval.rstring;
else
str = 采用T("C");
}
str.Truncate(1);
str = str + 采用T(":\\");
DWORD VolumeSerialNumber = 0;
GetVolumeInformation(str, NULL, 0, (DWORD *)&VolumeSerialNumber, NULL, NULL, NULL, 0 );
if (VolumeSerialNumber != 0)
{
TCHAR Result = {0};
采用sntprintf(Result , sizeof(TCHAR)*10 , 采用T("%X") , VolumeSerialNumber );
acedRetStr(Result);
}
else
acedRetNil();
return (RSRSLT) ;
}
#pragma endregion
#pragma region //filesystem
//(crpfilesystem "c")
int FileSystem(void)
{
CString str;
struct resbuf *pArgs =acedGetArgs () ;
//get the resbuf from lisp, test validity
if(pArgs == NULL)
str = 采用T("C");
else
{
if(pArgs->restype == RTSTR)
str = pArgs->resval.rstring;
else
str = 采用T("C");
}
str.Truncate(1);
str = str + 采用T(":\\");
TCHAR FileSystem = {0};
GetVolumeInformation(str, NULL, 0, NULL, NULL, NULL, FileSystem, sizeof(TCHAR)*MAX采用PATH);
if (采用tcsclen(FileSystem) != NULL)
acedRetStr(FileSystem);
else
acedRetNil();
return (RSRSLT) ;
}
#pragma endregion
#pragma region //drivetype
//(crpdrivetype "c")
int DriveType(void)
{
//
CString str;
CString DriveType;
//
struct resbuf *rb = NULL;
//
struct resbuf *pArgs =acedGetArgs () ;
if(pArgs == NULL)
str = 采用T("C");
else
{
if(pArgs->restype == RTSTR)
str = pArgs->resval.rstring;
else
str = 采用T("C");
};
//
str.Truncate(1);
str += 采用T(":\\");
UINT uDriveType = GetDriveType(str);
for (int i=0; DriveTypeFlags<i>.name; i++)
{
if (uDriveType == DriveTypeFlags<i>.type)
{
DriveType = DriveTypeFlags<i>.name;
break;
}
}
//
if (!DriveType.IsEmpty())
acedRetStr(DriveType);
else
acedRetNil();
return (RSRSLT) ;
}
#pragma endregion
#pragma region //drives
//(crpdrives)
int Drives(void)
{
struct resbuf* pRbRet = acutNewRb(RTT);
struct resbuf* pRbTail;
pRbTail = pRbRet;
TCHAR szBuffer = {0};
GetLogicalDriveStrings(1024, szBuffer);
TCHAR *drv = szBuffer;
while (*drv)
{
pRbTail = pRbTail->rbnext = acutBuildList(RTSTR,drv,RTNONE);
drv = &drv[采用tcslen(drv) + 1];
}
acedRetList(pRbRet->rbnext);
acutRelRb(pRbRet);
return (RSRSLT) ;
}
#pragma endregion
页:
[1]