I need to develop a data driver DLL, so USES is the new DLL project, initial # import "XX. OCX component method, CoCreateInstance success, a call interface is abnormal, but considering the method may be OCX rely on MFC, so give up
Now the new is MFC DLL project, add a dialog box, class called ContainerDlg, the selected dialog - & gt; Right-click to choose insert ActiveX controls, after adding the control, to select the control - & gt; Right click select add variables, the compiler automatically generated control class CDctlctrl1, and in the parent dialog ContainerDlg automatically add a variable DCTL
The following is the parent dialog code the header file
//ContainerDlg dialog
The class ContainerDlg: public CDialog
{
DECLARE_DYNAMIC (ContainerDlg)
Public:
PParent ContainerDlg (CWnd *=NULL);//standard constructor
Virtual ~ ContainerDlg ();
//data dialog
# ifdef AFX_DESIGN_TIME
Enum {IDD=IDD_DIALOG1};
# endif
Protected:
Virtual void DoDataExchange (CDataExchange * symbol;//support DDX/DDV
DECLARE_MESSAGE_MAP ()
Public:
CDctlctrl1 DCTL;//object controls generated
};
The following is a control class code
class CDctlctrl1: public CWnd
{
Protected:
DECLARE_DYNCREATE (CDctlctrl1)
Public:
Clsids const& GetClsid ()
{
The static clsids const clsids
X11d1 x3fce x22842328={0, 0, 0, {x93 0 x9b, 0, 0 x0, 0 x20, 0 xaf, 0 x52, 0 x4f, 0 xa5}};
Return clsids;
}
Virtual BOOL Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, dwords dwStyle,
Const RECT& The rect, CWnd * pParentWnd, UINT nID,
CCreateContext * pContext=NULL)
{
Return CreateControl (GetClsid (), lpszWindowName dwStyle, the rect, pParentWnd, nID);
}
BOOL Create (LPCTSTR lpszWindowName dwords dwStyle, const RECT& The rect, CWnd * pParentWnd,
UINT nID, CFile * pPersist=NULL, BOOL bStorage=FALSE,
BSTR bstrLicKey=NULL)
{
Return CreateControl (GetClsid (), lpszWindowName dwStyle, the rect, pParentWnd, nID,
PPersist bStorage, bstrLicKey);
}
//feature
//think enumeration and interface code, only posted a
Long GetLastError ()
{
Long the result;
GetProperty (0 xa, VT_I4, (void *) & amp; The result);
return result;
}
Then I also defines a Driver action class Driver, the Driver defines the dialog containerdlg pointer object, and the constructor new,
Then the Driver class Openlink function interface to call control function, the following
BOOL Driver: : OpenLink ()
{
Cstrings STR="DDeserver";
Cstrings str1=containerdlg - & gt; DCTL. GetLinkTopic ();//function call can succeed, but the function returns an abnormal returns during the implementation of the
Return 0;
}
The following function is abnormal control interface code
cstrings GetLinkTopic ()
{
Cstrings result;
GetProperty (0 x3, VT_BSTR (void *) & amp; The result);//every time this place to Debug an Assertion Failed exception
return result;
}
This exception, of course, also may be the result of my development environment, because it is the first time use controls development, so I want to ask next my this loading OCX and call interface method itself if you have any questions? Which didn't make the result in abnormal?
CodePudding user response:
Is not enough to just new dialog object, ocx control has not been created,CodePudding user response:
The