为什么这个简单的代码停止了? [英] why this simple code stops?

查看:153
本文介绍了为什么这个简单的代码停止了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用msdn中的示例编写一个小程序来提取wim文件.

我只有一个大问题...当我想使用

DWORD WINAPI ApplyCallback(DWORD msgId,WPARAM param1,LPARAM param2,

I am writing a little program to extract wim files using the example, ihave seen in msdn.

I only have a big problem...when i want use the WIM_MSG_FILEINFO message in callback function, the program hangs after 5 seconds at same point, on the same file. If i remove the line or i comment it all goes ok. Can somebody correct my code? :( i am crazing

DWORD WINAPI ApplyCallback(DWORD msgId,WPARAM param1,LPARAM param2,

void *未使用)

{

void *unused)

{

//第一个参数:的完整文件路径如果是WIM_MSG_PROCESS,则为其他人的消息字符串

TCHAR * message =(TCHAR *)param1;

TCHAR *message = (TCHAR *) param1;

WCHAR * filePath =(WCHAR *)param1;

WCHAR *filePath = (WCHAR *) param1;

DWORD百分比=(DWORD)param1;

DWORD percent = (DWORD) param1;

//第二个参数:发回呼叫者的消息如果为WIM_MSG_PROCESS,则为其他人的错误代码

DWORD errorCode = param2;

DWORD errorCode = param2;

DWORD * msg_back =(DWORD *)param2;

DWORD *msg_back = (DWORD *) param2;

CString strTemp;

CString strTemp;

开关 (msgId)

{

switch ( msgId )

{

案例 WIM_MSG_FILEINFO:

strTemp =(LPCWSTR)filePath;

case WIM_MSG_FILEINFO:

strTemp = (LPCWSTR)filePath;

Label-> SetWindowText(strTemp);

Label->SetWindowText(strTemp);

break ;

}

break;

}

返回 WIM_MSG_SUCCESS;

}

return WIM_MSG_SUCCESS;

}

无效

CWimApplyDlg :: OnBnClickedOk()

{

CWimApplyDlg::OnBnClickedOk()

{

HANDLE hWim = NULL,hImg = NULL;

HANDLE hWim = NULL, hImg = NULL;

//获取源,目标字符串和其他信息

WCHAR wimFile [MAX_PATH] = L

WCHAR wimFile[MAX_PATH] = L

" C:\\ boot.wim" ; ;

FARPROC回调=(FARPROC)ApplyCallback;

"C:\\boot.wim";

FARPROC callback = (FARPROC) ApplyCallback;

如果 (WIMRegisterMessageCallback(NULL,callback,NULL)== INVALID_CALLBACK_VALUE){

MessageBox(

if (WIMRegisterMessageCallback(NULL,callback,NULL ) == INVALID_CALLBACK_VALUE) {

MessageBox(

" Non posso settare il callback"

"Non posso settare il callback","Errore",MB_OK | MB_ICONEXCLAMATION);

 

返回 ;

}

return;

}

//创建WIM文件

DWORD已创建;

DWORD created;

hWim = WIMCreateFile(wimFile,WIM_GENERIC_READ,WIM_OPEN_EXISTING,WIM_FLAG_VERIFY,0和已创建);

hWim = WIMCreateFile(wimFile, WIM_GENERIC_READ, WIM_OPEN_EXISTING,WIM_FLAG_VERIFY, 0, &created);

如果 (!hWim){

MessageBox(

if (!hWim) {

MessageBox(

无法通过文件WIM"

"Impossibile trovare il file WIM", "Errore", MB_OK | MB_ICONEXCLAMATION);

WIMCloseHandle(hWim);

返回 ;

}

return;

}

WCHAR tempDir [MAX_PATH] = L

WCHAR tempDir[MAX_PATH] = L

" C:\\ Mounted_wim" ;

"C:\\mounted_wim";

 

如果 (!WIMSetTemporaryPath(hWim,tempDir)){

MessageBox(

if (!WIMSetTemporaryPath(hWim, tempDir)) {

MessageBox(

不可能的冒牌货" 错误" ,MB_OK | MB_ICONEXCLAMATION);

WIMCloseHandle(hWim);

"Impossibile impostare la cartella di lavoro","Errore",MB_OK | MB_ICONEXCLAMATION);

WIMCloseHandle(hWim);

返回 ;

}

return;

}

hImg = WIMLoadImage(hWim,1);

hImg = WIMLoadImage ( hWim, 1 );

如果 (!hImg){

MessageBox(

if ( !hImg ) {

MessageBox(

"Non posso caricare l'immagine" 错误" ,MB_OK | MB_ICONEXCLAMATION);

WIMCloseHandle(hWim);

"Non posso caricare l'immagine", "Errore", MB_OK | MB_ICONEXCLAMATION);

WIMCloseHandle(hWim);

WIMCloseHandle(hImg);

WIMCloseHandle(hImg);

返回 ;

}

return;

}

如果 (!WIMApplyImage(hImg,L

if (!WIMApplyImage(hImg, L"Z:\\",WIM_FLAG_FILEINFO)) {

MessageBox(

应用图片失败"

"Applying image failed","Error", MB_OK | MB_ICONEXCLAMATION);

WIMCloseHandle(hWim);

WIMCloseHandle(hImg);

WIMCloseHandle(hImg);

返回 ;

}

return;

}

OnOK();

}

推荐答案

以前从未听说过WIM.这不是一个有据可查的API.猜测:如果回调是在另一个线程上进行的,则您的SetWindowText()调用将绑定为死锁.在主线程和回调中均调用GetCurrentThreadId()以进行验证.如果它们不同,则必须避免在回调中进行UI更新.
Haven't heard of WIM before.  This is not a well documented API.  Guessing: if the callback is made on another thread, your SetWindowText() call is bound to deadlock.  Call GetCurrentThreadId() in both the main thread and the callback to verify.  If they are different, you'll have to avoid making UI updates in the callback.


这篇关于为什么这个简单的代码停止了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆