我想用VC獲取U盤ID,查了很多資料都是Delphi和VB的,似乎可以通過查注冊表或使用API獲取U盤ID,可是不知道具體該怎么做。希望有人能解釋下,謝謝了!
uj5u.com熱心網友回復:
木人理,木人理uj5u.com熱心網友回復:
還是木人理啊uj5u.com熱心網友回復:
把你找到delphi的代碼貼出來,給你翻譯一下,編程cb的uj5u.com熱心網友回復:
unit GetUSBID;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses USB;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Drv, Pid: string;
begin
Drv := ExtractFileDrive(ParamStr(0));
if GetDriveType(PChar(Drv + '\')) <> DRIVE_REMOVABLE then
Application.MessageBox('對不起,請把本程式放至到優盤上使用!', 'Error', MB_ICONHAND)
else if GetUSBDiskID(Drv, Pid) then ShowMessage(Pid);
end;
end.
uj5u.com熱心網友回復:
GetUSBDiskID這個是dll函式,有沒有這個函式的定義運行程式需要dll支持
uj5u.com熱心網友回復:
我是從CSDN下載資里下的,對delphi不了解,能把整個檔案發夾給你嗎?
uj5u.com熱心網友回復:
剛做了個例子,73B60084B0 就是pid吧,不過win7不行,xp可以獲取到uj5u.com熱心網友回復:
是,那老師你是使用什么方式獲取的呢,能細說下嗎?
uj5u.com熱心網友回復:
樓主發一個VB的吧 需要用uj5u.com熱心網友回復:
哦 我自己找到了一份如果樓主下載的里面有一個USBPhysic.dll要參考的話,那就一樣了 我能找到的網上實作方式都是用這個DLL (當然也有封裝成類的)
用Dependency Walker查出來它只匯出兩個函式 Init 和 GetUSBPhysicInfo
不過它呼叫了N多API
這是他呼叫的kernel32.dll的
CloseHandle
CreateFileA
DeleteCriticalSection
DeviceIoControl
EnterCriticalSection
ExitProcess
FlushFileBuffers
FreeEnvironmentStringsA
FreeEnvironmentStringsW
GetACP
GetCPInfo
GetCommandLineA
GetConsoleCP
GetConsoleMode
GetConsoleOutputCP
GetCurrentProcess
GetCurrentProcessId
GetCurrentThreadId
GetDriveTypeA
GetEnvironmentStrings
GetEnvironmentStringsW
GetFileType
GetLastError
GetLocaleInfoA
GetLogicalDriveStringsA
GetModuleFileNameA
GetModuleHandleA
GetOEMCP
GetProcAddress
GetProcessHeap
GetStartupInfoA
GetStdHandle
GetStringTypeA
GetStringTypeW
GetSystemTimeAsFileTime
GetTickCount
GetVersionExA
HeapAlloc
HeapCreate
HeapDestroy
HeapFree
HeapReAlloc
HeapSize
InitializeCriticalSection
InterlockedDecrement
InterlockedIncrement
IsDebuggerPresent
LCMapStringA
LCMapStringW
LeaveCriticalSection
LoadLibraryA
MultiByteToWideChar
QueryPerformanceCounter
RaiseException
RtlUnwind
SetErrorMode
SetFilePointer
SetHandleCount
SetLastError
SetStdHandle
SetUnhandledExceptionFilter
Sleep
TerminateProcess
TlsAlloc
TlsFree
TlsGetValue
TlsSetValue
UnhandledExceptionFilter
VirtualAlloc
VirtualFree
WideCharToMultiByte
WriteConsoleA
WriteConsoleW
WriteFile
由此推斷核心功能實作貌似不太簡單,還是老老實實用DLL吧
樓主的水平應該知道如何參考外部DLL中的匯出函式吧
Public Declare Function Init Lib "USBPhysic.dll" (ByVal sUser As String, ByVal sRegCode As String) As Long
Public Declare Function GetUSBPhysicInfo Lib "USBPhysic.dll" (ByVal diskIndex As Long, ByVal InfoType As Long, ByVal pHddInfo As String) As Long
我就不幫忙轉成C了。。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/97324.html
上一篇:Java 實作大矩陣的加法
