c++ - VC++ create Cdialog Class Assertion error -


i'm complete noob visual studio, it's stupid mistake.

i'm trying instantiate cdialog class, i'm making dll in end need had activex commands in window.

i'm tried several ways instantiate, getting assertion error.

so in calldllclass.h had:

#pragma once __declspec(dllexport) long init(); 

in class extend cdialog:

//{{afx_includes() //}}afx_includes  class cmyclass: public cdialog{  #include "resource.h"  public:     cmyclass(cwnd* pparent = null)     : cdialog(100, pparent){         //{{afx_data_init(cmyclass)         //}}afx_data_init        };  // standard constructor     virtual ~cmyclass(){};     long calc(); // dialog data     //{{afx_data(cmyclass)     //}}afx_data      // classwizard generated virtual function overrides     //{{afx_virtual(cmyclass)     protected:     //}}afx_virtual  protected:     // generated message map functions     //{{afx_msg(cmyclass)     //}}afx_msg     declare_message_map()     }; //{{afx_insert_location}} 

i created resource class:

#include "resource.h"  #define apstudio_readonly_symbols ///////////////////////////////////////////////////////////////////////////// // // generated textinclude 2 resource. // #include "afxres.h"  ///////////////////////////////////////////////////////////////////////////// #undef apstudio_readonly_symbols  ///////////////////////////////////////////////////////////////////////////// // english (u.s.) resources  #if !defined(afx_resource_dll) || defined(afx_targ_enu) #ifdef _win32 language lang_english, sublang_english_us #pragma code_page(1252) #endif //_win32  #ifdef apstudio_invoked ///////////////////////////////////////////////////////////////////////////// // // textinclude //  1 textinclude moveable pure  begin     "resource.h\0" end  2 textinclude moveable pure  begin     "#include ""afxres.h""\r\n"     "\0" end  3 textinclude moveable pure  begin     "#define _afx_no_splitter_resources\r\n"     "#define _afx_no_ole_resources\r\n"     "#define _afx_no_tracker_resources\r\n"     "#define _afx_no_property_resources\r\n"     "\r\n"     "#if !defined(afx_resource_dll) || defined(afx_targ_enu)\r\n"     "#ifdef _win32\r\n"     "language 9, 1\r\n"     "#pragma code_page(1252)\r\n"     "#endif //_win32\r\n"     "#include ""res\\simplevc6sampleevent.rc2""  // non-microsoft visual c++ edited resources\r\n"     "#include ""afxres.rc""         // standard components\r\n"     "#endif\r\n"     "\0" end  #endif    // apstudio_invoked     ///////////////////////////////////////////////////////////////////////////// // // dialog //  idd_aboutbox dialog discardable  0, 0, 0, 0 style ds_modalframe font 8, "ms sans serif" begin end     #endif    // english (u.s.) resources ///////////////////////////////////////////////////////////////////////////// 

and in cpp had:

// simpledialogdll.cpp : defines exported functions dll application. // #pragma once #include "stdafx.h" #include "myclass.h" #include "resource.h" #include "dll2export.h"   begin_message_map(cmyclass, cdialog)     //{{afx_msg_map(cmyclass)     //}}afx_msg end_message_map()   long init(){        afxenablecontrolcontainer();     coinitializeex(null,coinit_multithreaded);     afx_manage_state(afxgetstaticmodulestate());      cmyclass * obj = new cmyclass();      //obj->showwindow(sw_hide);     obj->showwindow(sw_show);      long res = obj->calc();     return (long) obj; }  long cmyclass::calc(){     return 1+1; } 

when obj->showwindow(sw_show); called debug assertion failed! winocc.cpp line 329

bool cwnd::showwindow(int ncmdshow) {     assert(::iswindow(m_hwnd) || (m_pctrlsite != null));      if (m_pctrlsite == null)         return ::showwindow(m_hwnd, ncmdshow);     else         return m_pctrlsite->showwindow(ncmdshow); } 

a little update put after showwindow returns 1400

   dword dw = getlasterror(); 

add answer sugenstion had init method

afxenablecontrolcontainer(); coinitializeex(null,coinit_multithreaded); afx_manage_state(afxgetstaticmodulestate( ));  cmyclass *obj = new cmyclass();  if(obj->create(100)){     obj->showwindow(sw_hide);     dword dw = getlasterror(); }else{     dword dw = getlasterror(); } 

now i'm having in obj->create(100)); objcore.cpp line: 40

@scottmcp-mvp right, modeless dialog boxes need call create method.

also, according msdn docs on constructor,

to construct modeless dialog box, use protected form of cdialog constructor. constructor protected because must derive own dialog-box class implement modeless dialog box. construction of modeless dialog box two-step process. first call constructor; call create member function create resource-based dialog box...

so declare class cmyclass() : cdialog() {...} , use following code display it:

cmyclass * obj = new cmyclass(); if (obj->create(100))     obj->showwindow(sw_show); else { << error >> } 

p.s.: don't forget delete variable @ end of program!


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -