using CMainFrame Object inside MFC Extension DLL
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: using CMainFrame Object inside MFC Extension DLL

  1. #1
    Join Date
    Aug 2004
    Location
    Pakistan
    Posts
    260

    using CMainFrame Object inside MFC Extension DLL

    hi,

    My project is divided into two different project one is coredll where i am putting different resources and second is the exe project where i have CMainFrame Cview and CDoc classes.

    Now i have a situation in which i need to use CMainFrame's user defined function , what would be a good way to communicate with it without using Send Message or post message. Can i get its CMainFram pointer ???

    One solution i guess i should put my cmainframe inside dll which i am not interested in doing that ....any other idea???

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,069

    Re: using CMainFrame Object inside MFC Extension DLL

    Pass the CMainFrame pointer to the DLL?

  3. #3
    Join Date
    Aug 2004
    Location
    Pakistan
    Posts
    260

    Re: using CMainFrame Object inside MFC Extension DLL

    problem is the dll doesnt know the declaration of CMainFrame and telling its header file and cpp file through directory makes more problem for me ..it seems like i am lost.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,360

    Re: using CMainFrame Object inside MFC Extension DLL

    Quote Originally Posted by Wolvorine View Post
    ...
    what would be a good way to communicate with it without using Send Message or post message. Can i get its CMainFram pointer ???
    And what is wrong for you with SendMessage/PostMessage?
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2004
    Location
    Pakistan
    Posts
    260

    Re: using CMainFrame Object inside MFC Extension DLL

    Quote Originally Posted by VictorN View Post
    And what is wrong for you with SendMessage/PostMessage?
    there is nothing wrong with it, i was just wondering if i can do without the send and post messages by using its own object. But i think there is no other way except send /post ...what you think??

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,360

    Re: using CMainFrame Object inside MFC Extension DLL

    I'd implement send/post a registered message.
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2011
    Location
    Australia
    Posts
    18

    Re: using CMainFrame Object inside MFC Extension DLL

    I did this way:

    1 - Define you function in dll (ny parameters)

    typedef void (CALLBACK* MYFUNCTION)(int i,float f);
    //////////////////////////////////////////////////////////////////////////
    2 - in dll .h file declare
    public:
    void SetMyFunc(MYFUNCTION pProc);
    private:
    MYFUNCTION m_pMyFunc;
    ///////////////////////////////////////////////////////////////////////////
    in dll .cpp file implement
    void CMyDllClass::SetMyFunc(MYFUNCTION pProc)
    {
    m_pMyFunc=pProc;
    }
    ///////////////////////////////////////////////////////////////////////////
    3 - now in MainFrame
    .h
    public:
    static void CALLBACK MyFunction(int i,float f);
    private:
    CMyDllClass m_DllClass;
    ///////////////////////////////////////////////////////////////////
    .cpp
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;
    m_DllClass.SetMyFunc(MyFunction);
    return 0;
    }
    void CMainFrame::MyFunction(int i,float f)
    {
    CMainFrame* pThisFrame=(CMainFrame*)::AfxGetMainWnd(); //?? or whatever you need
    }
    ////////////////////////////////////////////////////////////////////////
    4 - and last when you need to call function from dll just call

    m_pMyFunc(1,15.f); //for example

    and it will call function in MainFrame

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center