// MyClass.h: interface for the CMyClass class.
//
//
#if !defined(AFX_MYCLASS_H__EE9915A7_A14C_4FC5_94C7_E00704EA1D65__INCLUDED_)
#define AFX_MYCLASS_H__EE9915A7_A14C_4FC5_94C7_E00704EA1D65__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#pragma message("auto to link the Test2.lib")
#define MYDLL_API __declspec(dllimport)
#endif
extern "C" MYDLL_API void StartSendMessage(HWND hwnd);
class MYDLL_API CMyClass
{
public:
CString SayHello(CString strName);
CMyClass();
virtual ~CMyClass();
};
#endif // !defined(AFX_MYCLASS_H__EE9915A7_A14C_4FC5_94C7_E00704EA1D65__INCLUDED_)
// MyClass.cpp: implementation of the CMyClass class.
//
//
#include "stdafx.h"
#define MYDLL_EXPORTS
#include "Test2.h"
#include "MyClass.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//
// Construction/Destruction
//
extern CTest2App theApp;
CMyClass::CMyClass()
{
}
CMyClass::~CMyClass()
{
}
CString CMyClass::SayHello(CString strName)
{
return "Hello " + strName;
}
void StartSendMessage(HWND hwnd)
{
theApp.SendMessage(hwnd);
}
#define WM_MSG WM_USER + 102
void CTest2App::SendMessage(HWND hwnd)
{
::PostMessage(hwnd,WM_MSG,0,1);
}
应用程序:
#define WM_MSG WM_USER + 102
afx_msg void OnMyMsg(WPARAM wParam,LPARAM lParam);
ON_MESSAGE(WM_MSG,OnMyMsg)
void CTestDllDlg::OnButton2()
{
// TODO: Add your control notification handler code here
HWND hwnd;
hwnd = this->GetSafeHwnd();
StartSendMessage(hwnd);
}