Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to invoke a Form from a DLL Function

How to invoke a Form from a DLL Function

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    poda
    wrote on last edited by
    #1

    Hi friends, I have a export function in the DLL. When this function is to be called from other application, it has to show the form in which the DLL was built with. Can anyone help out? For example //DLLMain.cpp file extern "C" __declspec(dllexport) void MyDLLFunction(double* Data,int nData) { //what code should I write to show the form } //GraphDlg.cpp class CGraphDlg : public CDialog { // Construction public: CGraphDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CGraphDlg) enum { IDD = IDD_GRAPH_DLG }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CGraphDlg) public: virtual void OnFinalRelease(); protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; // Generated message map functions //{{AFX_MSG(CGraphDlg) virtual BOOL OnInitDialog(); afx_msg void OnPaint(); //}}AFX_MSG DECLARE_MESSAGE_MAP() };

    M 1 Reply Last reply
    0
    • P poda

      Hi friends, I have a export function in the DLL. When this function is to be called from other application, it has to show the form in which the DLL was built with. Can anyone help out? For example //DLLMain.cpp file extern "C" __declspec(dllexport) void MyDLLFunction(double* Data,int nData) { //what code should I write to show the form } //GraphDlg.cpp class CGraphDlg : public CDialog { // Construction public: CGraphDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CGraphDlg) enum { IDD = IDD_GRAPH_DLG }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CGraphDlg) public: virtual void OnFinalRelease(); protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; // Generated message map functions //{{AFX_MSG(CGraphDlg) virtual BOOL OnInitDialog(); afx_msg void OnPaint(); //}}AFX_MSG DECLARE_MESSAGE_MAP() };

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Show the dialog modal or modeless? To do it modally, something like: extern "C" __declspec(dllexport) void MyDLLFunction(double* Data,int nData) { CGraphDlg GraphDlg(NULL); if (IDOK == GraphDlg.DoModal()) { //user clicked "ok" - do something } } You may want to pass a parent window pointer to the dll function so the dialog will have a parent.

      P 1 Reply Last reply
      0
      • M Mark Salsbery

        Show the dialog modal or modeless? To do it modally, something like: extern "C" __declspec(dllexport) void MyDLLFunction(double* Data,int nData) { CGraphDlg GraphDlg(NULL); if (IDOK == GraphDlg.DoModal()) { //user clicked "ok" - do something } } You may want to pass a parent window pointer to the dll function so the dialog will have a parent.

        P Offline
        P Offline
        poda
        wrote on last edited by
        #3

        As this function is called repeatedly in the calling program, modalless dialog is needed. //MyDLL.cpp CGraphDlg *pDialog; BOOL CMyDLLApp::InitInstance() { pGraphDlg=new CGraphDlg; pGraphDlg->Create(IDD_GRAPH_DLG,NULL); return TRUE; } extern "C" __declspec(dllexport) void MyDLLFunction(double* Data,int nData) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); pDialog->ShowWindow(SW_SHOW); } But this code does not show the window. I get Assertion Error. The calling application is a C program. So cannot pass the window pointer to the dll function. Thanks for your answers.

        M 1 Reply Last reply
        0
        • P poda

          As this function is called repeatedly in the calling program, modalless dialog is needed. //MyDLL.cpp CGraphDlg *pDialog; BOOL CMyDLLApp::InitInstance() { pGraphDlg=new CGraphDlg; pGraphDlg->Create(IDD_GRAPH_DLG,NULL); return TRUE; } extern "C" __declspec(dllexport) void MyDLLFunction(double* Data,int nData) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); pDialog->ShowWindow(SW_SHOW); } But this code does not show the window. I get Assertion Error. The calling application is a C program. So cannot pass the window pointer to the dll function. Thanks for your answers.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          The assertion is probably because the dialog has not been created. Where do you call pDialog->Create()? Mark

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups