GetDriveGeometry(DISK_GEOMETRY *pdg)放Button2問題 |
答題得分者是:GrandRURU
|
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
[code cpp]
#include #pragma hdrstop #include #include #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; AnsiString dd1; bool GetDriveGeometry(DISK_GEOMETRY *pdg) { HANDLE hDevice; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results hDevice = CreateFile("\\\\.\\PhysicalDrive0", // drive to open 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive { return (FALSE); } bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform NULL, 0, // no input buffer pdg, sizeof(*pdg), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O CloseHandle(hDevice); //drive clos return (bResult); } //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { DISK_GEOMETRY pdg; // disk drive geometry structure BOOL bResult; // generic results flag ULONGLONG DiskSize; // size of the drive, in bytes long d1; bResult = GetDriveGeometry (&pdg); if (bResult){ Edit1->Text =pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder * (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector; d1 = DiskSize /(1024*1024); Edit5->Text = IntToStr(d1) " bytes "; }else{ Edit5->Text = "GetDriveGeometry failed. Error %ld.\n", GetLastError (); } } [/code] 把以GetDriveGeometry(DISK_GEOMETRY *pdg)裡面的內容放到Button2裡面~ 但是Button1裡面的 Edit1->Text =pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; 都無法顯示了 有誰能教我該怎麼辦呢?
------
May I ask you something ? |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
一、看不太懂你的問題,我依照你所提供的程式照key了一番,程式正常執行,沒有問題。Edit1~Edit5都有文字出現
二、你所說的button2是要放什麼東西咧? 三、下次在放程式碼的時候請盡量加上程式碼區塊喔!(「半形」的【code cpp】請在此區域輸入程式碼【/code】) 我把程式碼整理一下… [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "winioctl.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; AnsiString dd1; bool GetDriveGeometry(DISK_GEOMETRY *pdg) { HANDLE hDevice; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results hDevice = CreateFile("\\\\.\\PhysicalDrive0", // drive to open 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive { return (FALSE); } bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform NULL, 0, // no input buffer pdg, sizeof(*pdg), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O CloseHandle(hDevice); //drive clos return (bResult); } //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { DISK_GEOMETRY pdg; // disk drive geometry structure BOOL bResult; // generic results flag ULONGLONG DiskSize; // size of the drive, in bytes long d1; bResult = GetDriveGeometry (&pdg); if (bResult){ Edit1->Text = pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; // 每磁道的扇區數 Edit4->Text = pdg.BytesPerSector; // 每扇區的字節數 DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder * (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector; d1 = DiskSize /(1024*1024); Edit5->Text = IntToStr(d1) " bytes "; }else{ Edit5->Text = "GetDriveGeometry failed. Error %ld.\n", GetLastError (); } } //--------------------------------------------------------------------------- |
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
我是想把Butto2放著樣: [code cpp] HANDLE hDevice; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results hDevice = CreateFile("\\\\.\\PhysicalDrive0", // drive to open 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive { } bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform NULL, 0, // no input buffer pdg, sizeof(*pdg), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O CloseHandle(hDevice); //drive clos [/code] 如果著樣放Button1裡面的 Edit1->Text =pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; 都無法顯示 ~ 因為我想用ComboBox取代CreateFile裡面的\\\\.\\PhysicalDrive0的值 想把他改成ComboBox可以點選的比較方面 ~ 所以想把CreateFile跟DeviceIoControl放在不同的button裡面 但是如果我把分開DISK_GEOMETRY *pdg值就不知道該怎麼用了
------
May I ask you something ? |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
我改成著樣子執行起來便怪怪的呢!! QQ
[code cpp] #include #pragma hdrstop #include #include #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; DISK_GEOMETRY *pdg; HANDLE hDevice; // handle to the drive to be examined ****這這這 BOOL bResult; // results flag DWORD junk; // discard results bool GetDriveGeometry(DISK_GEOMETRY *pdg) { if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive { return (FALSE); } bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform NULL, 0, // no input buffer pdg, sizeof(*pdg), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O return (bResult); } //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn2Click(TObject *Sender) { DISK_GEOMETRY pdg; // disk drive geometry structure BOOL bResult; // generic results flag ULONGLONG DiskSize; // size of the drive, in bytes long d1; hDevice = ComboBox1->Text.c_str() ; //*********這這這 if (bResult){ Edit1->Text = pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder * (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector; d1 = DiskSize /(1024*1024); Edit5->Text = IntToStr(d1) " bytes "; } else { Edit5->Text = "GetDriveGeometry failed. Error %ld.\n", GetLastError (); } } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn1Click(TObject *Sender) { CloseHandle(hDevice); ShowMessage("Close"); // } //--------------------------------------------------------------------------- [/code]
------
May I ask you something ?
編輯記錄
MVP2000 重新編輯於 2007-12-18 00:25:04, 註解 無‧
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
為什麼不用全域變數來放"\\\\.\\PhysicalDrive0"的內容呢? 然後用你的button2來呼叫GetDriveGeometry(DISK_GEOMETRY *pdg),原來函式的"\\\\.\\PhysicalDrive0"再用所宣告的全域變數取代,這樣不就省事點了嗎? 另外,我發現全部相乘後,得到的值應該是MByte的樣子…(如果是我誤解,再麻煩糾正) |
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
全域變數釋放的位置嗎?
[code cpp] class TForm1 : public TForm { __published: // IDE-managed Components TBitBtn *BitBtn1; TBitBtn *BitBtn2; TEdit *Edit1; TEdit *Edit2; TEdit *Edit3; TEdit *Edit4; TEdit *Edit5; TComboBox *ComboBox1; void __fastcall BitBtn2Click(TObject *Sender); void __fastcall BitBtn1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); HANDLE hDevice; //放在著嗎? }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif [/code]
------
May I ask you something ? |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
位置對了,只是放的程式不太對,我相信你應該有看到這篇文章:
實戰DeviceIoControl 之一:通過API訪問設備驅動程序 而driver0、1...或是c:、d:等該設在哪邊可以在這篇找到相關資訊 加油!快完成嚕! ===================引 用 MVP2000 文 章=================== 全域變數釋放的位置嗎? [code cpp] class TForm1 : public TForm { __published: // IDE-managed Components TBitBtn *BitBtn1; TBitBtn *BitBtn2; TEdit *Edit1; TEdit *Edit2; TEdit *Edit3; TEdit *Edit4; TEdit *Edit5; TComboBox *ComboBox1; void __fastcall BitBtn2Click(TObject *Sender); void __fastcall BitBtn1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); HANDLE hDevice; //放在著嗎? }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif [/code] |
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
阿 中標 頭腦完全打結中 恩恩 那邊我也有看
那是要用typedef struct宣告在裡面嗎? [code cpp] const char *szDevName[]= { "\\\\.\\A:", "\\\\.\\B:", "\\\\.\\PhysicalDrive0", "\\\\.\\PhysicalDrive1", "\\\\.\\PhysicalDrive2", "\\\\.\\PhysicalDrive3", "\\\\.\\Cdrom0", "\\\\.\\Cdrom1", }; CEdit& Edit = GetEditCtrl(); Edit.SetWindowText(strMsg); // 打開設備 hDisk = ::CreateFile(filename, // 文件名 GENERIC_READ | GENERIC_WRITE, // 讀寫方式 FILE_SHARE_READ | FILE_SHARE_WRITE, // 共享方式 NULL, // 默認的安全描述符 OPEN_EXISTING, // 創建方式 0, // 不需設置文件屬性 NULL); // 不需參照模板文件 [/code]
------
May I ask you something ? |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
你不是要用combobox來處理嗎..........?
[code cpp] ComboBox1->Items->Add("\\\\.\\PhysicalDrive0"); . . . [/code] ===================引 用 MVP2000 文 章=================== 阿 中標 頭腦完全打結中 恩恩 那邊我也有看 那是要用typedef struct宣告在裡面嗎... |
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
恩 我要用ComboBox用 因為我看裡面的範例 我只看到面的結構 所以打結不知道 怎麼用 因為用HANDLE hDevice; 之後 Edit1->Text = pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; 都取不到值了 [code cpp] TForm1 *Form1; DISK_GEOMETRY *pdg; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn2Click(TObject *Sender) { DISK_GEOMETRY pdg; // disk drive geometry structure BOOL bResult; // generic results flag ULONGLONG DiskSize; // size of the drive, in bytes long d1; hDevice = ComboBox1->Text.c_str() ; if (bResult){ Edit1->Text = pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder * (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector; d1 = DiskSize /(1024*1024); Edit5->Text = IntToStr(d1) " bytes "; } else { Edit5->Text = "GetDriveGeometry failed. Error %ld.\n", GetLastError (); } } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn1Click(TObject *Sender) { ShowMessage("Close"); // } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn3Click(TObject *Sender) { bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform NULL, 0, // no input buffer pdg, sizeof(*pdg), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn4Click(TObject *Sender) { CloseHandle(hDevice); } //--------------------------------------------------------------------------- [/code]
------
May I ask you something ? |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
hDevice是要放很多東西的…
[code cpp] hDevice = CreateFile( Edit1->Text, // drive to open 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes [/code] 看出哪裡不一樣了嗎?
編輯記錄
GrandRURU 重新編輯於 2007-12-19 23:23:06, 註解 無‧
|
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
換記放CreateFile QQ 可是改了之後 可是我著樣子執行後還是有錯誤 是為什麼阿? (很不好意思 都一值麻煩你的說)
[code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include #include #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; DISK_GEOMETRY *pdg; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn2Click(TObject *Sender) { DISK_GEOMETRY pdg; // disk drive geometry structure BOOL bResult; // generic results flag ULONGLONG DiskSize; // size of the drive, in bytes long d1; hDevice = ComboBox1->Text.c_str() ; if (bResult){ Edit1->Text = pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder * (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector; d1 = DiskSize /(1024*1024); Edit5->Text = IntToStr(d1) " bytes "; } else { Edit5->Text = "GetDriveGeometry failed. Error %ld.\n", GetLastError (); } } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn1Click(TObject *Sender) { CloseHandle(hDevice); ShowMessage("Close"); // } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn3Click(TObject *Sender) { bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform NULL, 0, // no input buffer pdg, sizeof(*pdg), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn4Click(TObject *Sender) { hDevice = CreateFile(ComboBox1->Text.c_str(), // drive to open 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes } //--------------------------------------------------------------------------- [/code]
------
May I ask you something ? |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
哈哈
我剛剛試過後才知道,ansistring轉char之後,還真的出不來哩,不知道是哪裡的問題。 所以我用了另一個折衷的方法 利用switch來偵測combobox->itemindex 以下是程式片斷 [code cpp] char *a; switch(ComboBox1->ItemIndex){ case 1: a = "\\\\.\\PhysicalDrive0"; case 2: a = "\\\\.\\PhysicalDrive1"; } [/code] 這樣combobox的items也可改為「硬盤1」、「硬盤2」之類的名字。 (我想,應該已經一堆高手在螢幕前笑翻天了吧,哈哈) |
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
抱歉我在耍白吃 ~ 竟然不知道自己在搞什麼(頭暈腦漲) 看下面
[code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include #include #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; DISK_GEOMETRY *pdg; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn2Click(TObject *Sender) { DISK_GEOMETRY pdg; BOOL bResult; ULONGLONG DiskSize; long d1; hDevice = ComboBox1->Text.c_str() ; ///<<<<<<<<<<<<<<<<著裡 if (bResult){ Edit1->Text = pdg.Cylinders.QuadPart; Edit2->Text = pdg.TracksPerCylinder; Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder * (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector; d1 = DiskSize /(1024*1024); Edit5->Text = IntToStr(d1) " bytes "; } else { Edit5->Text = "GetDriveGeometry failed. Error %ld.\n", GetLastError (); } } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn1Click(TObject *Sender) { CloseHandle(hDevice); ShowMessage("Close"); // } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn3Click(TObject *Sender) { bResult = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, pdg, sizeof(*pdg), &junk, // # bytes returned (LPOVERLAPPED) NULL); } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn4Click(TObject *Sender) { hDevice = CreateFile(ComboBox1->Text.c_str(), // drive to open <<<<<<<<<<<<<<<<<<著裡 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); } //--------------------------------------------------------------------------- [/code] 改完之後 只出現pdg.BytesPerSector的值 其他的值都沒有顯示 [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include #include #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; DISK_GEOMETRY *pdg; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn2Click(TObject *Sender) { DISK_GEOMETRY pdg; // disk drive geometry structure BOOL bResult; // generic results flag ULONGLONG DiskSize; // size of the drive, in bytes long d1; if (bResult){ Edit1->Text = pdg.Cylinders.QuadPart; //柱面數 Edit2->Text = pdg.TracksPerCylinder; //每柱面的磁道數 Edit3->Text = pdg.SectorsPerTrack ; Edit4->Text = pdg.BytesPerSector; DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder * (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector; d1 = DiskSize /(1024*1024); Edit5->Text = IntToStr(d1) " bytes "; } else { Edit5->Text = "GetDriveGeometry failed. Error %ld.\n", GetLastError (); } } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn1Click(TObject *Sender) { CloseHandle(hDevice); ShowMessage("Close"); // } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn4Click(TObject *Sender) { char *a; switch(ComboBox1->ItemIndex){ case 1: a = "\\\\.\\PhysicalDrive0"; case 2: a = "\\\\.\\PhysicalDrive1"; } hDevice = CreateFile(a, // drive to open 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform NULL, 0, // no input buffer pdg, sizeof(*pdg), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O } //--------------------------------------------------------------------------- [/code]
------
May I ask you something ? |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
先把程式改回原本的樣子,再將a取代"\\\\.\\PhysicalDrive0",之後再看你的需求來做修改。
另外,既然你的問題是將「GetDriveGeometry(DISK_GEOMETRY *pdg)放Button2」,那button2的onclick事件為何不放「bResult = GetDriveGeometry (&pdg)」呢?原來的函式內容放到button2的目的是什麼? |
MVP2000
一般會員 發表:13 回覆:16 積分:5 註冊:2007-04-03 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |