Home > Back-end >  MFC using # import import ocx
MFC using # import import ocx

Time:09-19

Create an ocx, write a way:
 BSTR CAMFCocxTestCtrl: : ocxTest () 
{
Cstrings strResult;
//TODO: Add your dispatch handler code here
StrResult="asdffgh";

Return strResult. AllocSysString ();
}

Then create MFC a button:
 # import "AMFCocxTest. Ocx \ 
"No_namespace no_smart_pointers raw_interfaces_only \
Raw_native_types no_implementation named_guids

Void CMFCocx4Dlg: : OnButton1 ()
{
CoInitialize (NULL);
{
If (1)
{
_DAMFCocxTest * pOcx=0;
Retrieves the hr=CoCreateInstance (
CLSID_AMFCocxTest,//Com object identifiers
0,//a pointer to the interface IUnknown
CLSCTX_ALL,//running executable code context
DIID__DAMFCocxTest,//Com object interface identifier
Reinterpret_cast & lt; Void * * & gt; (& amp; POcx)//used to receiving address Com object interface pointer variable
);
Assert (SUCCEEDED (hr));
If (pOcx) {
POcx - & gt; OcxTest ();
POcx - & gt; Release ();
}
}
}
CoUninitialize();
}


Compile error: error C2039: 'ocxTest' : is not a member of '_DAMFCocxTest'
What reason is this?
  • Related