以前模块在服务里面跑什么问题,这次移到界面进程,提测的时候QA反馈在XP下死机,然后自己单步到ImmDisableIME的时候出问题。
搜了下, http://www.devsuperpage.com/search/Articles.aspx?G=10&ArtID=30180
测试代码:
// adfs.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windows.h>
#include <wchar.h>
#include <tchar.h>
#include <assert.h>
#include <process.h>
#include <stdio.h>
#pragma comment(lib, "imm32.lib")
#define EXTRA_THREAD_WINDOW_CLASS L"C668F583-87AA-11d5-AE65-00904F30013B"
HANDLE g_hEvent = 0;
HWND g_hExtraWnd = 0;
LRESULT CALLBACK ExtraWndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, message, wParam,
lParam);
}
void __cdecl ExtraThread(void* lParam)
{
WNDCLASS wc;
wchar_t szClassName[] = EXTRA_THREAD_WINDOW_CLASS;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)ExtraWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle( 0 );
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground= NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName= szClassName;
if(!RegisterClass(&wc))
{
return;
}
g_hExtraWnd = CreateWindow( szClassName,
L"",
WS_POPUP,
-100000,
-100000,
0,
0,
NULL,
NULL,
GetModuleHandle( 0 ),
NULL);
SetEvent( g_hEvent );
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
DispatchMessage(&msg);
}
}
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow)
{
_set_error_mode( _OUT_TO_MSGBOX );
g_hEvent = CreateEvent( 0, FALSE, FALSE, 0 );
if ( 0 == g_hEvent )
{
assert( !"Failed to create event;" );
return 0;
}
ULONG hThread;
hThread = _beginthread( ExtraThread, 0, 0);
if ( 0xFFFFFFFF == hThread)
{
assert( !"Failed to create thread" );
return 0;
}
// wait for thread to create the window
DWORD dwExtraThreadEvent = WaitForSingleObject( g_hEvent, 5000 );
if (WAIT_FAILED == dwExtraThreadEvent)
{
assert( !"Failed to wait for event." );
return 0;
}
else if (WAIT_TIMEOUT == dwExtraThreadEvent)
{
assert( !"Time out waiting for event." );
return 0;
}
else if ( 0 != g_hExtraWnd )
{
printf( "The window was created successfully.");
}
if ( FALSE == ImmDisableIME( -1 ) )
{
printf ( "failed to disable IME, gle: %d", GetLastError() );
assert( !"Failed to disable IME." );
}
return 0;
}