我用hook在记事本下呼出窗口就弹出
Debug Assertion Failed!
Program:C:\WINDOWS\system32\notepad.exe
File:f:\rtm\vctools\vs7libs\ship\atlmfc\include\afxwin1.inl
Line:24
For information on how your program can cause an assertion
failure, seee the Visual C++ documentation on asserts.
(Press Retry to debug the application)请高手指点!谢谢!

解决方案 »

  1.   

    afxwin1.inl是文本文件,打开看看24行:_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
    { ASSERT(afxCurrentResourceHandle != NULL);
    return afxCurrentResourceHandle; }说明断言失败是由于afxCurrentResourceHandle为NULL看看用到AfxGetResourceHandle()的地方。
      

  2.   

    // Hook.cpp : 定义 DLL 的初始化例程。
    //#include "stdafx.h"
    #include <afxdllx.h>
    #include <afxwin.h>
    #include "TextDlg.h"
    #ifdef _MANAGED
    #error 请阅读 Hook.cpp 中的说明以使用 /clr 进行编译
    // 如果要向您的项目中添加 /clr,必须执行下列操作:
    // 1. 移除上述对 afxdllx.h 的包含
    // 2. 向没有使用 /clr 且已禁用预编译头的
    //    项目添加一个 .cpp 文件,其中含有下列文本:
    // #include <afxwin.h>
    // #include <afxdllx.h>
    #endif#ifdef _DEBUG
    #define new DEBUG_NEW
    #endif//--------------------------------------------------------------
    #pragma data_seg("GlbData")
    HINSTANCE glbInstance=NULL;
    HHOOK glbHook=NULL;
    HWND gamehWnd=NULL;
    #pragma data_seg()
    //---------------------------------------------------------------
    CTextDlg *wgdlg=NULL;
    HINSTANCE hDllInstance=NULL;
    //---------------------------------------------------------------static AFX_EXTENSION_MODULE HookDLL = { NULL, NULL };#ifdef _MANAGED
    #pragma managed(push, off)
    #endif
    extern "C" int APIENTRY
    DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
    {
    // 如果使用 lpReserved,请将此移除
    UNREFERENCED_PARAMETER(lpReserved); if (dwReason == DLL_PROCESS_ATTACH)
    {
    TRACE0("Hook.DLL 正在初始化!\n");

    // 扩展 DLL 一次性初始化
    if (!AfxInitExtensionModule(HookDLL, hInstance))
    return 0; // 将此 DLL 插入到资源链中
    // 注意: 如果此扩展 DLL 由
    //  MFC 规则 DLL (如 ActiveX 控件)隐式链接到,
    //  而不是由 MFC 应用程序链接到,则需要
    //  将此行从 DllMain 中移除并将其放置在一个
    //  从此扩展 DLL 导出的单独的函数中。使用此扩展 DLL 的
    //  规则 DLL 然后应显式
    //  调用该函数以初始化此扩展 DLL。否则,
    //  CDynLinkLibrary 对象不会附加到
    //  规则 DLL 的资源链,并将导致严重的
    //  问题。 new CDynLinkLibrary(HookDLL); hDllInstance=hInstance;
    glbInstance=hInstance; }
    else if (dwReason == DLL_PROCESS_DETACH)
    {
    TRACE0("Hook.DLL 正在终止!\n");
    if(wgdlg)
    {
    wgdlg->DestroyWindow();
    delete (wgdlg);
    } // 在调用析构函数之前终止该库
    AfxTermExtensionModule(HookDLL);
    }
    return 1;   // 确定
    }#ifdef _MANAGED
    #pragma managed(pop)
    #endif//-------------------------------------------------------------------------------------------
    //extern "C" LRESULT WINAPI KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
    LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
    {
    if((HIWORD(lParam) & KF_UP) == 0 && HC_ACTION == nCode)
    {
    if( wParam == 0X78 )//当按下F9键时,激活外挂。
    {
    //外挂实现代码。
    HWND hWnd;
    hWnd=GetForegroundWindow();
    CWnd *mWnd=CWnd::FromHandle(hWnd);
    char Info[255];
    GetClassNameA(hWnd,Info,255);
    AfxMessageBox((CString)Info);

    }
    //当激活F11键时,启动挡截API函数功能。
    else if( wParam == 0x7A )

    //AFX_MANAGE_STATE(AfxGetStaticModuleState()); if(wgdlg==NULL)
    {
    HINSTANCE hResource;
    wgdlg=new CTextDlg;

    CWnd *pParentWindow=CWnd::FromHandle(GetForegroundWindow());
    wgdlg->Create(CTextDlg::IDD,pParentWindow);
    wgdlg->ShowWindow(SW_SHOW);


    }
    else
    wgdlg->ShowWindow(wgdlg->IsWindowVisible() ? SW_HIDE : SW_SHOW);

    }
    //当按F12是执行
    else if(wParam=0x7B)
    {


    } };
    return CallNextHookEx(glbHook,nCode,wParam,lParam);
    }//-----------------------------------------------------------------------------------------------
    extern "C" __declspec(dllexport)
    HHOOK StartHook(DWORD dwThreadId)
    {
    if(!glbHook)
    {
    glbHook=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,hDllInstance,dwThreadId);//设置键盘钩子。
    }
    else 
    AfxMessageBox(_T("Hook is alreadly exist!"));
    if(!glbHook)
    {
    AfxMessageBox(_T("Set hook failed!"));
    return NULL;
    }
    else
    return glbHook;
    }
    extern "C" __declspec(dllexport)
    BOOL StopHook()
    {
    BOOL bResult=FALSE;
    if(glbHook)
    {
    bResult=UnhookWindowsHookEx(glbHook);//卸载键盘钩子。 if(!bResult)
    AfxMessageBox(_T("UnHook failed!"));
    glbHook=NULL;
    }
    return bResult;
    }//-----------------------------------------------------------------------------------------------
    这是我的程序,我好像没有用到AfxGetResourceHandle()!请大虾帮我分析分析!谢谢!
      

  3.   

    Dlgcore.cpp 中:
    BOOL CDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
    {
    ASSERT(HIWORD(lpszTemplateName) == 0 ||
    AfxIsValidString(lpszTemplateName)); m_lpszTemplateName = lpszTemplateName;  // used for help
    if (HIWORD(m_lpszTemplateName) == 0 && m_nIDHelp == 0)
    m_nIDHelp = LOWORD((DWORD)m_lpszTemplateName);#ifdef _DEBUG
    if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE))
    {
    ASSERT(FALSE);          // invalid dialog template name
    PostNcDestroy();        // cleanup if Create fails too soon
    return FALSE;
    }
    #endif //_DEBUG HINSTANCE hInst = AfxFindResourceHandle(lpszTemplateName, RT_DIALOG);
    HRSRC hResource = ::FindResource(hInst, lpszTemplateName, RT_DIALOG);
    HGLOBAL hTemplate = LoadResource(hInst, hResource);
    BOOL bResult = CreateIndirect(hTemplate, pParentWnd, hInst);
    FreeResource(hTemplate); return bResult;
    }而AFXWIN.H中:
    // Use AfxFindResourceHandle to find resource in chain of extension DLLs
    #ifndef _AFXDLL
    #define AfxFindResourceHandle(lpszResource, lpszType) AfxGetResourceHandle()
    #else
    HINSTANCE AFXAPI AfxFindResourceHandle(LPCTSTR lpszName, LPCTSTR lpszType);
    #endif