I'm a complete noob with Visual Studio, it's probably a stupid mistake.
I'm only trying to instantiate a Cdialog class, I'm making a dll that in the end will need to had some activeX commands in the Window.
I'm tried several ways to instantiate, but I always getting an assertion error.
So in my calldllclass.h I had:
#pragma once
__declspec(dllexport) long init();
in my class that 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 an Resource Class:
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the 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 finally in my cpp I had:
// SIMPLEDIALOGDLL.cpp : Defines the exported functions for the 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); is called I get an 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 I put after showWindow it returns 1400
DWORD dw = GetLastError();
add answer sugenstion I had this to 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
CDialog::Create
anywhere. You need to create a dialog before you can show it. – Tony The Lion