首地明帆址 设漏槐罩置返闹值 长度
头文件memory.h
用c++打开一个文件夹的方法如下:可以实现单选文件或者多选文件,代码如下:需引入头文件#include "CommDlg.h"
[cpp] view plaincopy
TCHAR szBuffer[MAX_PATH] = {0}
OPENFILENAME ofn= {0}
ofn.lStructSize = sizeof(ofn)
ofn.hwndOwner = m_hWnd
ofn.lpstrFilter = _T("Exe文件(*.exe)\0*.exe\0所有文件(*.*)\0*.*\0")//要选择的文件后缀
ofn.lpstrInitialDir = _T("D:\\Program Files"誉租)//默认的文件路径
ofn.lpstrFile = szBuffer//存放文件的缓冲区
ofn.nMaxFile = sizeof(szBuffer)/sizeof(*szBuffer)
ofn.nFilterIndex = 0
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER //标志如果是多选要加上OFN_ALLOWMULTISELECT
BOOL bSel = GetOpenFileName(&ofn)
这样就可以打开选择文件对话瞎虚袭框了。可以选择需要的文件。szBuffer是存放的选择磨兄的文件路径。
BOOL __fastcall DoIdentify( HANDLE hPhysicalDriveIOCTL,PSENDCMDINPARAMS pSCIP,
PSENDCMDOUTPARAMS pSCOP,
BYTE btIDCmd,
BYTE btDriveNum,
PDWORD pdwBytesReturned)
{
pSCIP->cBufferSize = IDENTIFY_BUFFER_SIZE
pSCIP->irDriveRegs.bFeaturesReg = 0
pSCIP->irDriveRegs.bSectorCountReg = 1
pSCIP->irDriveRegs.bSectorNumberReg = 1
pSCIP->irDriveRegs.bCylLowReg = 0
pSCIP->irDriveRegs.bCylHighReg = 0
pSCIP->irDriveRegs.bDriveHeadReg = (btDriveNum &1) ? 0xB0 : 0xA0
pSCIP->irDriveRegs.bCommandReg = btIDCmd
pSCIP->bDriveNumber = btDriveNum
pSCIP->cBufferSize = IDENTIFY_BUFFER_SIZE
return DeviceIoControl(hPhysicalDriveIOCTL,
SMART_RCV_DRIVE_DATA,
(LPVOID)pSCIP,
sizeof(SENDCMDINPARAMS) - 1,
(LPVOID)pSCOP,
sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,
pdwBytesReturned, NULL)
}
char *__fastcall ConvertToString(DWORD dwDiskData[256], int nFirstIndex, int nLastIndex)
{
static char szResBuf[1024]
char ss[256]
int nIndex = 0
int nPosition = 0
for(nIndex = nFirstIndexnIndex <= nLastIndexnIndex++)
{
ss[nPosition] = (char)(dwDiskData[nIndex] / 256)
nPosition++
// Get low BYTE for 2nd character
ss[nPosition] = (char)(dwDiskData[nIndex] % 256)
nPosition++
}
// End the stringss[nPosition] = '\0'
int i, index=0
for(i=0i<nPositioni++)
{
if(ss[i]==0 || ss[i]==32)continue
szResBuf[index]=ss[i]
index++
}
szResBuf[index]=0
return szResBuf
}
int GetID()//主函数
{
//创建设备对象,得到设备句柄,设备为硬盘。
CString sFilePath
sFilePath.Format("\\\\.\\PHYSICALDRIVE%d", driver)
HANDLE hFile=::CreateFile(sFilePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
0, NULL)
DWORD dwBytesReturned
GETVERSIONINPARAMS gvopVersionParams
DeviceIoControl(hFile, //向设备对象发送SMART_GET_VERSION设备请求,获取硬盘属性
SMART_GET_VERSION,
NULL,
0,
&gvopVersionParams,
sizeof(gvopVersionParams),
&dwBytesReturned, NULL);
if(gvopVersionParams.bIDEDeviceMap <= 0)return -2
//发送SMART_RCV_DRIVE_DATA设备请求,获取硬盘详细信息。
// IDE or ATAPI IDENTIFY cmd
int btIDCmd = 0
SENDCMDINPARAMS InParams
int nDrive =0
btIDCmd = (gvopVersionParams.bIDEDeviceMap >>nDrive &0x10) ? IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY
// 输出参数
BYTE btIDOutCmd[sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1]
if(DoIdentify(hFile,
&InParams,
(PSENDCMDOUTPARAMS)btIDOutCmd,
(BYTE)btIDCmd,
(BYTE)nDrive, &dwBytesReturned) == FALSE)return -3
::CloseHandle(hFile)
DWORD dwDiskData[256] USHORT *pIDSector// 对应结构IDSECTOR,见头文件
pIDSector = (USHORT*)((SENDCMDOUTPARAMS*)btIDOutCmd)->bBuffer for(int i=0i <256i++)dwDiskData[i] = pIDSector[i]
// 取系列号
ZeroMemory(szSerialNumber, sizeof(szSerialNumber))
strcpy(szSerialNumber, ConvertToString(dwDiskData, 10, 19))
// 取模型号
ZeroMemory(szModelNumber, sizeof(szModelNumber))
strcpy(szModelNumber, ConvertToString(dwDiskData, 27, 46))
return 0}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)