⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wimt2.cpp

📁 调用wimgapi实现的一个将wim文件apply到目录的例子。
💻 CPP
字号:
// wimgt1.cpp : 定义控制台应用程序的入口点。
#define _WIN32_WINNT 0x0502
#define IN
#define INOUT

#include <stdio.h>
#include <Windows.h>
#include <tchar.h>
#include <wimgapi.h>


//Callback function:
//************************************
// Method:    SampleApplyCallback
// FullName:  SampleApplyCallback
// Access:    public 
// Returns:   DWORD
// WINAPI
// Qualifier:
// Parameter: IN DWORD msgId
// Parameter: 
//************************************
DWORD WINAPI SampleApplyCallback(
					IN      DWORD msgId,    // message ID
					IN      WPARAM param1,   // usually file name
					INOUT   LPARAM param2,   // usually error code
					IN      void  *unused
					)
{
	//first parameter: full file path for if WIM_MSG_PROCESS, message string for others
	TCHAR *message  = (TCHAR *) param1;
	TCHAR *filePath = (TCHAR *) param1;
	DWORD percent   = (DWORD)   param1;

	//second parameter: message back to caller if WIM_MSG_PROCESS, error code for others
	DWORD errorCode = param2;
	DWORD *msg_back = (DWORD *) param2;

	switch ( msgId )
	{
	case WIM_MSG_PROCESS:
		//_tprintf(TEXT("FilePath: %s\n"), filePath);
		break;

	case WIM_MSG_PROGRESS:
		//Show progress(By nick)
		printf("Percents:%3d%% has finished!\n", percent);
		break;

	case WIM_MSG_ERROR:
		//This message is sent upon failure error case
		printf("ERROR: %s [err = %d]\n", message, errorCode);
		break;

	case WIM_MSG_RETRY:
		//This message is sent when file is being reapplied because of
		//network timeout. Retry is done up to five times.
		printf("RETRY: %s [err = %d]\n", message, errorCode);
		break;

	case WIM_MSG_INFO:
		//This message is sent when informational message is available
		printf("INFO: %s [err = %d]\n", message, errorCode);
		break;

	case WIM_MSG_WARNING:
		//This message is sent when warning message is available
		printf("WARNING: %s [err = %d]\n", message, errorCode);
		break;
	}

	return WIM_MSG_SUCCESS;
}

int _tmain(int argc, _TCHAR* argv[])
{
	HANDLE hImage = NULL;
	HANDLE hWim = NULL;
	DWORD imgIndex = 1;
	WIM_INFO imginfo;
	ZeroMemory(&imginfo, sizeof(WIM_INFO));
	PTSTR pXML = NULL;
	DWORD dwSize = 0;

	FARPROC callback = (FARPROC) SampleApplyCallback;

	TCHAR *wimFile  = TEXT("d:\\test\\t.wim");  // target WIM file
	TCHAR *tmpDir   = TEXT("d:\\test\\tmp");          // temporary directory
	TCHAR *applyDir = TEXT("d:\\test\\dst");      // apply directory or drive

	//Register callback
	if (WIMRegisterMessageCallback( NULL, callback, NULL) == INVALID_CALLBACK_VALUE) {
			printf ("Cannot set callback\n");
			return 1;
	}

	hWim = WIMCreateFile( wimFile,
		GENERIC_READ,
		WIM_OPEN_EXISTING,
		WIM_FLAG_VERIFY,
		0,
		&dwSize);

	if (hWim == (HANDLE)NULL) {
		return -1;
	}

	//WIMGetImageInformation(hWim, (LPVOID*)&pXML, &dwSize);
	//imgIndex = imginfo.ImageCount;
	//_tprintf_s(_T("%s"), pXML);

	if (!WIMSetTemporaryPath (hWim, tmpDir)) {
		printf("cannot set temp path to work in\n");
		return -1;
	}
	
	hImage = (WIMLoadImage(hWim, imgIndex));
	if ( !hImage) {
		printf("Load Wim image Failed\n");
		return -2;
	}

	if ( WIMApplyImage(hImage, applyDir, WIM_FLAG_FILEINFO)) {
		//printf("Apply image to %s OK!\n", applyDir);
		_tprintf_s( _T("Apply image to %s OK!\n"), applyDir);
	}
	else {
		_tprintf_s( _T("Apply image to %s Failed!\n"), applyDir);
	}
	
	WIMCloseHandle(hImage);
	WIMCloseHandle(hWim);

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -