使用未公开函数编写磁盘格式化应用程序
来源:互联网 发布:华为网络高级工程师 编辑:程序博客网 时间:2024/04/29 02:52
FormatEx函数原型:
VOID FormatEx ( PWCHAR DriveRoot,
DWORD MediaFlag ,
PWCHAR Format,
PWCHAR Label,
BOOL QuickFormat,
DWORD ClusterSize,
PFMIFSCALLBACK Callback);
其中FMIFSCALLBACK是:
typedef BOOLEAN (__stdcall *PFMIFSCALLBACK)(
CALLBACKCOMMAND Command,
DWORD SubAction,
PVOID ActionInfo );
下面是具体工作:
先定义一个头文件Fmifs.h:
//======================================================================
//
// Fmifs.h
//
//======================================================================
//
// 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 );
//
// Format command in FMIFS
//
// media flags
#define FMIFS_HARDDISK 0xC
#define FMIFS_FLOPPY 0x8
typedef VOID (__stdcall *PFORMATEX)( PWCHAR DriveRoot,
DWORD MediaFlag,
PWCHAR Format,
PWCHAR Label,
BOOL QuickFormat,
DWORD ClusterSize,
PFMIFSCALLBACK Callback );
//
// Enable/Disable volume compression
//
typedef BOOLEAN (__stdcall *PENABLEVOLUMECOMPRESSION)(PWCHAR DriveRoot,
BOOL Enable );
//////////////////////////////////////////////////////////////////////////
下面是主文件:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include "fmifs.h"
#define _UNICODE 1
#include "tchar.h"
BOOL Error = FALSE;
BOOL QuickFormat = FALSE;
DWORD ClusterSize = 0;
BOOL CompressDrive = FALSE;
BOOL GotALabel = FALSE;
PWCHAR Label = L"";
PWCHAR Drive = NULL;
PWCHAR Format = L"FAT32";
WCHAR RootDirectory[MAX_PATH];
WCHAR LabelString[12];
PFORMATEX FormatEx;
PENABLEVOLUMECOMPRESSION EnableVolumeCompression;
typedef struct {
WCHAR SizeString[16];
DWORD ClusterSize;
} SIZEDEFINITION, *PSIZEDEFINITION;
SIZEDEFINITION LegalSizes[] = {
{ L"512", 512 },
{ L"1024", 1024 },
{ L"2048", 2048 },
{ L"4096", 4096 },
{ L"8192", 8192 },
{ L"16K", 16384 },
{ L"32K", 32768 },
{ L"64K", 65536 },
{ L"128K", 65536 * 2 },
{ L"256K", 65536 * 4 },
{ L"", 0 },
};
//----------------------------------------------------------------------
//
// FormatExCallback
//
// The file system library will call us back with commands that we
// can interpret. If we wanted to halt the chkdsk we could return FALSE.
//
//----------------------------------------------------------------------
BOOLEAN __stdcall FormatExCallback( CALLBACKCOMMAND Command, DWORD Modifier, PVOID Argument )
{
PDWORD percent;
PTEXTOUTPUT output;
PBOOLEAN status;
static createStructures = FALSE;
//
// We get other types of commands, but we don't have to pay attention to them
//
switch( Command ) {
case PROGRESS:
percent = (PDWORD) Argument;
_tprintf(L"%d percent completed./r", *percent);
break;
case OUTPUT:
output = (PTEXTOUTPUT) Argument;
fprintf(stdout, "%s", output->Output);
break;
case DONE:
status = (PBOOLEAN) Argument;
if( *status == FALSE ) {
_tprintf(L"FormatEx was unable to complete successfully./n/n");
Error = TRUE;
}
break;
}
return TRUE;
}
//----------------------------------------------------------------------
//
// LoadFMIFSEntryPoints
//
// Loads FMIFS.DLL and locates the entry point(s) we are going to use
//
//----------------------------------------------------------------------
BOOLEAN LoadFMIFSEntryPoints()
{
LoadLibrary( "fmifs.dll" );
if( !(FormatEx = (PFORMATEX) GetProcAddress( GetModuleHandle( "fmifs.dll"),
"FormatEx" )) ) {
return FALSE;
}
if( !(EnableVolumeCompression = (PENABLEVOLUMECOMPRESSION) GetProcAddress( GetModuleHandle( "fmifs.dll"),
"EnableVolumeCompression" )) ) {
return FALSE;
}
return TRUE;
}
int main( int argc, WCHAR *argv[] )
{
if( argv[1][1] != L':' ) return 0;
Drive = argv[1];
wcscpy( RootDirectory, Drive );
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;
//
// Get function pointers
//
if( !LoadFMIFSEntryPoints()) {
_tprintf(L"Could not located FMIFS entry points./n/n");
return -1;
}
FormatEx( RootDirectory, media, Format, Label, QuickFormat,
ClusterSize, FormatExCallback );
return 0;
}
- 使用未公开函数编写磁盘格式化应用程序
- 关于未公开函数ZwQuerySystemInformation的使用
- 未公开函数
- API未公开函数2
- API未公开函数3
- 未公开的函数 NtQuerySystemInformation
- 未公开的加密函数
- 如何利用winhex处理磁盘未格式化
- “驱动器中的磁盘未被格式化”解决办法
- 用VB6.0编写磁盘格式化程序
- API未公开函数解密1
- PB绝对有用的未公开函数
- 如何调用未公开的API函数
- Windows未公开函数揭密(3)
- 如何调用未公开的API函数
- PB绝对有用的未公开函数
- 浅谈Windows CE中的未公开函数
- MFC未公开的有用函数收集
- 地狱七十二小时
- CRect类(矩形类)
- MS Windows 驱动程序模型设计
- Hibernate生成映射文件及POJO时遇到的问题(转)
- 添加多个web站点的方法
- 使用未公开函数编写磁盘格式化应用程序
- 转:创业公司最常犯的几个错误
- Spring学习笔记一
- OUTLOOK任务管理使用方法
- 开源 IDE CodeBlocks 使用感受(2008-03-27 11:00 作者:lonelyforest 来源:csdn)
- 0520周二
- MethodMember.java
- 设置TOMCAT的JVM虚拟机内存大小
- Dxperience 7.1.3 简体中文本地化