调用 FormatEx 函数格式化磁盘的代码
2011-08-18 11:01
183 查看
http://hi.baidu.com/classfree/blog/item/ecc9dc8b8fd6831ec9fc7acf.html
// Output command typedef struct { DWORD Lines; PCHAR Output; } TEXTOUTPUT, *PTEXTOUTPUT; // Callback command types typedef enum { PROGRESS, DONEWITHSTRUCTURE, UNKNOWN2, UNKNOWN3, UNKNOWN4, UNKNOWN5, INSUFFICIENTRIGHTS, UNKNOWN7, UNKNOWN8, UNKNOWN9, UNKNOWNA, DONE, UNKNOWNC, UNKNOWND, OUTPUT, STRUCTUREPROGRESS } CALLBACKCOMMAND; // FMIFS callback definition typedef BOOLEAN (__stdcall *PFMIFSCALLBACK)( CALLBACKCOMMAND Command, DWORD SubAction, PVOID ActionInfo ); // Chkdsk command in FMIFS typedef VOID (__stdcall *PCHKDSK)( PWCHAR DriveRoot, PWCHAR Format, BOOL CorrectErrors, BOOL Verbose, BOOL CheckOnlyIfDirty, BOOL ScanDrive, PVOID Unused2, PVOID Unused3, PFMIFSCALLBACK Callback ); // media flags #define FMIFS_HARDDISK 0xC #define FMIFS_FLOPPY 0x8 // Format command in FMIFS typedef VOID (__stdcall *PFORMATEX)( PWCHAR DriveRoot, DWORD MediaFlag, PWCHAR Format, PWCHAR Label, BOOL QuickFormat, DWORD ClusterSize, PFMIFSCALLBACK Callback ); // FormatExCallback BOOLEAN __stdcall FormatExCallback( CALLBACKCOMMAND Command, DWORD Modifier, PVOID Argument ) { PDWORD percent; PTEXTOUTPUT output; PBOOLEAN status; switch( Command ) { case PROGRESS: //格式化进度 percent = (PDWORD) Argument; DebugString("格式化进度: %d \n", *percent); break; case OUTPUT: output = (PTEXTOUTPUT) Argument; fprintf(stdout, "%s", output->Output); break; case DONE: //格式化完成 status = (PBOOLEAN) Argument; if( *status == FALSE ) { DebugString("格式化未能成功完成(%d)\n", GetLastError()); MakePageFile(iMin, iMax, szPageFilePath); Error = TRUE; } else { DebugString("格式化完成!"); MakePageFile(iMin, iMax, szPageFilePath); } break; } return TRUE; } //获取fsifs.dll中的格式化函数指针 BOOLEAN LoadFMIFSEntryPoints() { ifsModule = LoadLibrary("fmifs.dll"); FormatEx = (PFORMATEX)GetProcAddress( ifsModule, "FormatEx" ); if(FormatEx == NULL) { DebugString("获取FormatEx函数指针失败\n"); return FALSE; } if( !(EnableVolumeCompression = (PENABLEVOLUMECOMPRESSION) GetProcAddress( ifsModule, "EnableVolumeCompression" )) ) { DebugString("获取EnableVolumeCompression函数指针失败\n"); return FALSE; } return TRUE; } // 调用格式化函数 int CallFormatDriver(char *szDriver) { USES_CONVERSION; BOOL QuickFormat = TRUE; DWORD ClusterSize = 4096; PWCHAR Label = NULL; PWCHAR Format = L"NTFS"; WCHAR RootDirectory[MAX_PATH] = {0}; wcscpy( RootDirectory, A2W(szDriver) ); RootDirectory[1] = L':'; RootDirectory[2] = L'\\'; RootDirectory[3] = (WCHAR) 0; DWORD media; DWORD driveType; driveType = GetDriveTypeW( RootDirectory ); if( driveType != DRIVE_FIXED ) media = FMIFS_FLOPPY; if( driveType == DRIVE_FIXED ) media = FMIFS_HARDDISK; if( !LoadFMIFSEntryPoints()) { return -1; } FormatEx( RootDirectory, media, Format, Label, QuickFormat, ClusterSize, FormatExCallback ); FreeLibrary(ifsModule); return 0; }
相关文章推荐
- Date对象格式化函数代码
- ...后台代码中如何调用 javascript 函数的问题! - ASP.NET专题(按钮事件中调用JS文件中函数)
- C代码分析器(二)单文件函数调用分析
- 在Qt代码里调用js中的函数
- jquery EasyUI的formatter格式化函数代码
- PB调用.NET代码的两个入口函数
- 怎么获取调用当前函数的代码位置
- wordpress作者的相关函数调用代码
- PHP格式化显示时间date()函数代码
- 反汇编代码分析--函数调用
- 用VC写Assembly代码(5) --函数调用(三)
- C编译器剖析_6.3.4 汇编代码生成_为函数调用与返回产生汇编代码
- MATLAB 函数导出c/c++代码被vs2010调用
- C# 调用Dll中非托管C++代码,函数参数的类型对照
- 如何从Silverlight 代码调用Javascript 函数
- 为什么MFC中有些函数要加一句调用自身的代码?
- sqlserver 执行正则表达式,调用c# 函数、代码
- C++反汇编代码分析--函数调用
- C++反汇编代码分析--函数调用
- 代码片段--参数相同函数调用机制