如何在DLL总自定义消息,使用WM_MESSAGE时提示类型转换错误?

解决方案 »

  1.   

    #define WM_MYMESSAGE WM_USER + 1001 和平常没什么区别
      

  2.   

    BEGIN_MESSAGE_MAP(CDLLApp, CWinApp)
    ON_MESSAGE(WM_TEST,OnTestCommand)
    END_MESSAGE_MAP()
    使用这个时总是出现类型错误。消息已经定义了#define WM_TEST WM_USER+100。
      

  3.   

    没有什么完整定义了,只有这些啊!
    在.h中定义#define WM_TEST WM_USER+100。
    在.cpp中添加
    BEGIN_MESSAGE_MAP(CDLLApp, CWinApp)
    ON_MESSAGE(WM_TEST,OnTestCommand)
    END_MESSAGE_MAP()
    和消息处理函数。
      

  4.   

    我试了没问题啊,下面是头文件// 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()
    };
      

  5.   

    .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;
    }
      

  6.   

    error C2440: “static_cast” : 无法从“LRESULT (__thiscall CDLLApp::* )(WPARAM,LPARAM)”转换为“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)”
            在匹配目标类型的范围内没有具有该名称的函数
    提示这个错误。你用的是什么类型的DLL,还有VC的版本。我用的vc2003.net
      

  7.   

    .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;
    }
      

  8.   

    好像在mfc shared dll里没有消息循环,你在CDllDemoApp里不大可能处理消息
      

  9.   

    看错误信息好象是你定义错地方了。hehe