我遇到了这样一个问题,一个程序启动后,需要进入消息循环。此前做过一些操作。比如类里面的一些功能。但是,发现问题,如果这个EXE被Windows的任务管理器直接杀死的话,好像EXE里面的类的析构函数不会被调用。各位帮我看看,应该如何解决这个问题。// FWLOAD.cpp : Defines the entry point for the application.
//#include "stdafx.h"
#include <windows.h>
#include "CFwLoad.h"
CCFwLoad  g_fw_load; 
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
// 加载模块
  g_fw_load.LoadFrameWorks(lpCmdLine);
  return 0; 
}
//========================================
// 下面是类的实现代码CPP
 
#include "stdafx.h"
#include "CFWLoad.h"
#include "CCREPMGR_XPP.h"
#include "tfx_mini.h"#pragma comment(lib, "ccfrmw.lib")
 LRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, 
WPARAM wParam, LPARAM lParam)
{ TfxWriteToFile("fwload_log.txt", TfxIntToStr(message)); switch(message) 
{
case WM_DESTROY:
PostQuitMessage(0);
break;

  default:
return DefWindowProc(hWnd, message, wParam, lParam);
}

    return 0;
} CCFwLoad::CCFwLoad()
{
m_arrayModules.clear();
m_Modules_count = 0; InitializeFrameWorkEnvironment();
}CCFwLoad::~CCFwLoad()
// 此处,在进程被杀时,不能被自动调用。
// 导致了很多资源不能释放{ TfxWriteToFile("fwload_log.txt", "CCFwLoad::~CCFwLoad()");

SHORT iret = 0; // 先自动卸载已经加载的模块  for (int i = 0; i < m_Modules_count; i ++ )
{
string ls_framework_name = m_arrayModules[i];  iret = CCRepositoryMgr::UnloadFrameWork((char*)ls_framework_name.c_str()); if ( iret == 0 ) m_Modules_count --; }
// 退出后删除软件总线环境
DeleteFrameWorkEnvironment();
 
  m_arrayModules.clear();
m_Modules_count = 0;
}
SHORT CCFwLoad::LoadFrameWorks(char * asz_parm)
{ int li_count;
SHORT iret;
 
string ls_CmdLine = asz_parm;

ls_CmdLine = TfxTrim(ls_CmdLine);
if (ls_CmdLine == "" )
{
ls_CmdLine = TfxProfileString(CCREPMGR_INI, "list", "list",  "");
li_count = TfxSplitParm(ls_CmdLine, ";" , m_arrayModules);
}
else
li_count = TfxSplitWords(ls_CmdLine, m_arrayModules);  for (int i = 0; i < li_count; i ++ )
{
string ls_framework_name = m_arrayModules[i]; // FWLOAD 加载器针对同名模块,不能跨进程加载,但核心层支持跨进程加载
BOOL bret =  CCRepositoryMgr::IsLoaded((char*)ls_framework_name.c_str()); if (!bret )
{
iret = CCRepositoryMgr::LoadFrameWork((char*)ls_framework_name.c_str()); if ( iret == 0 ) m_Modules_count ++; }
}
// 若有模块加载成功, 则进入消息循环
if (m_Modules_count > 0 )
{
  string ls_wnd_name = FWLOAD_PATH + TfxIntToStr(GetCurrentProcessId());
string ls_class_name = FWLOAD_PATH;

HWND hWnd = TfxWorkWindow(ls_class_name.c_str(), 
&MyWndProc, ls_wnd_name.c_str());
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{  TranslateMessage(&msg); 
DispatchMessage(&msg); 
}
}
  return 0;
}