Dynamic CWND作为C++中没有DLL或.ocx文件的ActiveX控件?

Dynamic CWND作为C++中没有DLL或.ocx文件的ActiveX控件?,dynamic,mfc,activex,idispatch,cwnd,Dynamic,Mfc,Activex,Idispatch,Cwnd,亲爱的MFC/ActiveX/COM,我“继承”了最初使用Visual Studio 6创建的旧MFC应用程序的源代码 它在VS2010中构建并运行至今,但嵌入了一些ActiveX控件作为源代码,显然是由 Visual Studio wizard.h和.cpp文件,请参见下文; 但是,不能在自己的子项目中生成.dll或.ocx文件。 以下是其中一个控件的头文件的相关部分: #if !defined(AFX_CHARTFX_H__F8A080E0_0647_11D4_92B0_0000E886CD

亲爱的MFC/ActiveX/COM,我“继承”了最初使用Visual Studio 6创建的旧MFC应用程序的源代码 它在VS2010中构建并运行至今,但嵌入了一些ActiveX控件作为源代码,显然是由 Visual Studio wizard.h和.cpp文件,请参见下文; 但是,不能在自己的子项目中生成.dll或.ocx文件。 以下是其中一个控件的头文件的相关部分:

#if !defined(AFX_CHARTFX_H__F8A080E0_0647_11D4_92B0_0000E886CDCC__INCLUDED_)
#define AFX_CHARTFX_H__F8A080E0_0647_11D4_92B0_0000E886CDCC__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.

/////////////////////////////////////////////////////////////////////////////
// CChartfx wrapper class

class CChartfx : public CWnd
{
protected:
    DECLARE_DYNCREATE(CChartfx)
public:
    CLSID const& GetClsid()
    {
        static CLSID const clsid
            = { 0x8996b0a1, 0xd7be, 0x101b, { 0x86, 0x50, 0x0, 0xaa, 0x0, 0x3a, 0x55, 0x93 } };
        return clsid;
    }
    virtual BOOL Create(LPCTSTR lpszClassName,
        LPCTSTR lpszWindowName, DWORD dwStyle,
        const RECT& rect,
        CWnd* pParentWnd, UINT nID,
        CCreateContext* pContext = NULL)
    { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
        const RECT& rect, CWnd* pParentWnd, UINT nID,
        CFile* pPersist = NULL, BOOL bStorage = FALSE,
        BSTR bstrLicKey = NULL)
    { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
        pPersist, bStorage, bstrLicKey); }
    //rest of header file omitted
请注意,此类继承自CWnd,而不是某些 OCX类。但由于我在某个地方读到的所有MFC窗口都是COM组件,所以这是生成的 代码它应该在一段时间前就可以工作了。我还读到,这可能真的是一个移民缺口 发生在2005年之前。 还要注意DECLARE_DYNCREATE,因此我认为这是使用IDispatch接口的后期绑定。 所以MFC将为我们调用一个Create函数

上述控件通过聚合由包含的CDialog使用,该CDialog也是使用VS向导创建的:

//... analysedlg.h  - leading auto-generated stuff omitted
class CAnalyseDlg : public CDialog
{
  CChartfx m_chhrtfx;
  //... enum for resource ID, DoDataExchange, message map, other members…
}
该对话框又通过一个成员变量和 通过在菜单项事件处理程序中调用DoModal创建

因此,当我点击相应的菜单项时,我会得到一个m_hWnd NULL断言,当我点击 “重试”在弹出的对话框中,显示以下堆栈摘录:

mfc100d.dll!COleControlContainer::FillListSitesOrWnds(_AFX_OCC_DIALOG_INFO * pOccDlgInfo)  line 925 + 0x23 Bytes    C++
mfc100d.dll!COccManager::CreateDlgControls(CWnd * pWndParent, const char * lpszResourceName, _AFX_OCC_DIALOG_INFO * pOccDlgInfo)  line 410  C++
mfc100d.dll!CDialog::HandleInitDialog(unsigned int __formal, unsigned int __formal)  line 715 + 0x22 Bytes  C++
mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult)  line 2383 + 0x11 Bytes  C++
mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam)  line 2087 + 0x20 Bytes    C++
mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  line 257 + 0x1c Bytes  C++
mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  line 420    C++
mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  line 420 + 0x15 Bytes   C++
user32.dll!766162fa()   
[missing frames omitted by me]  
mfc100d.dll!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate, CWnd * pParentWnd, HINSTANCE__ * hInst)  line 366 + 0x2a Bytes    C++
mfc100d.dll!CDialog::DoModal()  line 630 + 0x20 Bytes   C++
在VS调试输出中,有以下几行:

CoCreateInstance of OLE control {8996B0A1-D7BE-101B-8650-00AA003A5593} failed.
>>> Result code: 0x80040154
>>> Is the control is properly registered?
Warning: Resource items and Win32 Z-order lists are out of sync. Tab order may be not defined well. 
显然,对CoCreateInstance的调用已经完成,并且在没有断言的情况下悄无声息地失败了 如果能有,那就太好了。有人知道这在哪里吗

我的中心问题是,在这种情况下,MFC通常会处理 注册控件,即使它不在.dll或.ocx项目中并且必须已运行 像过去这样。我在某个地方读到,使用DialogTemplate创建Dlgindirect是一种 在不需要.dll或.ocx文件的情况下创建ActiveX控件。在上面的堆栈中,这被称为, 也是,但不是ActiveX控件,而是对话

有人知道更多关于这个问题以及如何解决它吗? 如果我必须手动注册控件,例如使用regsvr32.exe或通过源代码, 有没有办法不使用.dll或.ocx文件?或者我必须重新打包中的ActiveX组件吗 他们自己的项目还有什么更基于组件/模块化的

我希望我的问题描述足够准确,我将非常感谢任何答案。
亲切问候。

我刚在使用旧ActiveX控件时遇到这个问题。显然,它是公寓线程化的,我试图用Conit\u多线程调用CoInitializeX。

。。。所有MFC窗口都是COM组件…-我对此表示怀疑。CWnd只是HWND句柄的包装器。那么您是否有ChartFx组件的源代码?>…所有MFC窗口都是COM组件…-我对此表示怀疑。CWnd只是HWND句柄的包装器。答:你是对的,我的这句话是错的。我误解了Paul DiLascia的以下文章:该页面上有两篇文章,在该页面上搜索“programming COM”以跳转到第一句。我找到了有关这些CWnds包装ActiveX控件的更多信息:“[…]使用MFC ActiveX控件类构建的控件是自注册的,因为当ControlWizard创建控件文件时,会自动添加控件可执行文件中的两个入口点DLLRegisterServer和DLLUnregisterServer。[..]'>那么您是否有ChartFx组件的源代码?答:正如我现在发现的,这只是MFC包装。在网上搜索CLSID后,我发现这个组件是一个ocx,可能是Delphi附带的:所以我会看看我们是否在其他机器上找到了它们。所以这可能会被关闭。我在一个Delphi安装中发现了ChartFx组件。这真的是丢失的一块,现在它工作了。