我试了没问题啊,下面是头文件// d11.h : main header file for the D11 DLL //#if !defined(AFX_D11_H__3014A1E9_5936_4DE6_9496_524CBB980A06__INCLUDED_) #define AFX_D11_H__3014A1E9_5936_4DE6_9496_524CBB980A06__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 #define WM_DO_MESSAGE WM_USER+100 //////////////////////////////////////////////////////////////////////////////////////////////////// // CD11App // See d11.cpp for the implementation of this class //class CD11App : public CWinApp { public: CD11App(); // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CD11App) //}}AFX_VIRTUAL //{{AFX_MSG(CD11App) // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG afx_msg LRESULT OnDoMessage(WPARAM wParam,LPARAM lParam); DECLARE_MESSAGE_MAP() };
.cpp里BEGIN_MESSAGE_MAP(CD11App, CWinApp) //{{AFX_MSG_MAP(CD11App) // 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 ON_MESSAGE(WM_DO_MESSAGE,OnDoMessage) END_MESSAGE_MAP().......//// LRESULT CD11App::OnDoMessage(WPARAM wParam,LPARAM lParam) { // .....你的操作 return 0L; }
.h #define WM_DO_MESSAGE WM_USER + 10//自定义消息class CDllDemoApp : public CWinApp { public: CDllDemoApp();// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CDllDemoApp) //}}AFX_VIRTUAL //{{AFX_MSG(CDllDemoApp) // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG afx_msg LRESULT OnDoMessage(WPARAM wParam, LPARAM lParam);//声明自定义函数 DECLARE_MESSAGE_MAP() };.cppBEGIN_MESSAGE_MAP(CDllDemoApp, CWinApp) //{{AFX_MSG_MAP(CDllDemoApp) // 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 ON_MESSAGE(WM_DO_MESSAGE,OnDoMessage)//响应WM_DO_MESSAGE消息 END_MESSAGE_MAP()//自定义函数的实现 LRESULT CDllDemoApp::OnDoMessage(WPARAM wParam, LPARAM lParam) { return 0l; }
ON_MESSAGE(WM_TEST,OnTestCommand)
END_MESSAGE_MAP()
使用这个时总是出现类型错误。消息已经定义了#define WM_TEST WM_USER+100。
在.h中定义#define WM_TEST WM_USER+100。
在.cpp中添加
BEGIN_MESSAGE_MAP(CDLLApp, CWinApp)
ON_MESSAGE(WM_TEST,OnTestCommand)
END_MESSAGE_MAP()
和消息处理函数。
//#if !defined(AFX_D11_H__3014A1E9_5936_4DE6_9496_524CBB980A06__INCLUDED_)
#define AFX_D11_H__3014A1E9_5936_4DE6_9496_524CBB980A06__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
#define WM_DO_MESSAGE WM_USER+100 ////////////////////////////////////////////////////////////////////////////////////////////////////
// CD11App
// See d11.cpp for the implementation of this class
//class CD11App : public CWinApp
{
public:
CD11App();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CD11App)
//}}AFX_VIRTUAL //{{AFX_MSG(CD11App)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
afx_msg LRESULT OnDoMessage(WPARAM wParam,LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
//{{AFX_MSG_MAP(CD11App)
// 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
ON_MESSAGE(WM_DO_MESSAGE,OnDoMessage)
END_MESSAGE_MAP().......////
LRESULT CD11App::OnDoMessage(WPARAM wParam,LPARAM lParam)
{
// .....你的操作
return 0L;
}
在匹配目标类型的范围内没有具有该名称的函数
提示这个错误。你用的是什么类型的DLL,还有VC的版本。我用的vc2003.net
#define WM_DO_MESSAGE WM_USER + 10//自定义消息class CDllDemoApp : public CWinApp
{
public:
CDllDemoApp();// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDllDemoApp)
//}}AFX_VIRTUAL //{{AFX_MSG(CDllDemoApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
afx_msg LRESULT OnDoMessage(WPARAM wParam, LPARAM lParam);//声明自定义函数
DECLARE_MESSAGE_MAP()
};.cppBEGIN_MESSAGE_MAP(CDllDemoApp, CWinApp)
//{{AFX_MSG_MAP(CDllDemoApp)
// 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
ON_MESSAGE(WM_DO_MESSAGE,OnDoMessage)//响应WM_DO_MESSAGE消息
END_MESSAGE_MAP()//自定义函数的实现
LRESULT CDllDemoApp::OnDoMessage(WPARAM wParam, LPARAM lParam)
{
return 0l;
}