0

dll problem,help me:)
i create dll project ,the dll is Use MFC in a Static Library
i hope exe call ListCtrl class from dll
==================DLL====================
<<<<<<<<<<ListCtrl.h>>>>>>>>>>>>>>>

#pragma once
class AFX_EXT_CLASS ListCtrl :public CListCtrl
{
public:
    __declspec(dllexport) ListCtrl();
    __declspec(dllexport) ~ListCtrl();
public:
    DECLARE_MESSAGE_MAP();
public:
    afx_msg void OnNMClick(NMHDR *pNMHDR, LRESULT *pResult);
};

<<<<<<<<<<<ListCtrl.Cpp>>>>>>>>>>>

#include "Stdafx.h"
#include "ListCtrl.h"
ListCtrl::ListCtrl()
{}
ListCtrl::~ListCtrl()
{}
BEGIN_MESSAGE_MAP(ListCtrl,CListCtrl)
    ON_NOTIFY_REFLECT(NM_CLICK, &ListCtrl::OnNMClick)
END_MESSAGE_MAP()
void ListCtrl::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
{
    AfxMessageBox(_T("OK"));
    *pResult = 0;
}

=====================EXE============================

i Create Exe,the exe is Use MFC in a Static Library
<<<<<<<<<<<TestDlg.h>>>>>>>>>>>>
#pragma comment(lib,"Dll.lib")
#include "ListCtrl.h"
class TestDlg : public CDialog
{
 DECLARE_DYNAMIC(TestDlg)
public:
 TestDlg(CWnd* pParent = NULL);   // standard constructor
 virtual ~TestDlg();
 enum { IDD = IDD_DIALOG1 };
protected:
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 DECLARE_MESSAGE_MAP()
     ListCtrl m_ListCtrl;
};

<<<<<<<<<<<<<<<TestDlg.Cpp>>>>>>>>>>

#include "stdafx.h"
#include "Test.h"
#include "TestDlg.h"
IMPLEMENT_DYNAMIC(TestDlg, CDialog)
TestDlg::TestDlg(CWnd* pParent /*=NULL*/)
 : CDialog(TestDlg::IDD, pParent)
{}
TestDlg::~TestDlg()
{}
void TestDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
}
BEGIN_MESSAGE_MAP(TestDlg, CDialog)
    ON_BN_CLICKED(IDOK, &TestDlg::OnBnClickedOk)
END_MESSAGE_MAP()

======================
the exe project call ListCtrl from dll project
Mouse click the m_ListCtrl window,error
why????
help me,thank you :)

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Ancient Dragon
0

what was the error? please copy from window and paste to your post.
Since you are subclassing a standard MFC control your dll should be an "MFC Extension DLL". I have never successfully exported that type of class from a regular DLL.

Also, I suspect you did not import the class correctly into your application program. I use a macro and define it to be export when compiling the dll and import when compiling the application program. This will export the entire class, which is what I think you will need to do.

#ifdef MYDLL // call this whatever you want in your dll, do not define it in application program
#define DllExport  __declspec( dllexport )
#else
#define DllExport  __declspec( dllimport )
#endif

class DllExport AFX_EXT_CLASS ListCtrl :public CListCtrl
{
public:
    ListCtrl();
    ~ListCtrl();
public:
    DECLARE_MESSAGE_MAP();
public:
    afx_msg void OnNMClick(NMHDR *pNMHDR, LRESULT *pResult);
};
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.