Answered by:
Using C# ActiveX Control in MFC 6.0

Question
-
I have C# ActiveX and I need use it in MFC 6.0. I put my ActiveX in MFC form and when I'm trying to add new member variable message apears "The ActiveX is not registered properly, or its type library version number is incorrect ...."
As ActiveX i use example from http://www.codeproject.com/KB/cs/DotNetActiveX.aspx but I don't know how to change loadActiveX method in order to get and set control properties on a dialog form.
Thursday, July 1, 2010 9:32 AM
Answers
-
_hSelf = GetDlgItem(IDC_STATIC)->m_hWnd;
......
_hAtl = ::CreateWindowEx(
WS_EX_CLIENTEDGE,\
TEXT("AtlAxWin"),\
strActiveXName,\
WS_CHILD | WS_VISIBLE | /*WS_CLIPCHILDREN | */WS_EX_RTLREADING,\
0, 0, rcClient.right, rcClient.bottom,\
this->m_hWnd,\
NULL,\
NULL,\
NULL);IT WORKS :)
- Marked as answer by pawelde Monday, July 12, 2010 8:51 AM
Monday, July 12, 2010 8:51 AM
All replies
-
Hi pawelde,
> I put my ActiveX in MFC form
Do you use Dialog based MFC project? If so, you need to create class for that COM interface first then add variable for the class.
For example, when you add Microsoft Web Browser ActivteX control to the form and add variable for it. VS generate CExplorer1 (explorer1.h and explorer1.cpp) in the solution. Then create the instance in your dialog .h file. Now you need to imitate the process. First add an MFC Class from a Type Library.
http://msdn.microsoft.com/en-us/library/fe06teee.aspx
Then add a variable for the class in your dialog .h file with code.
Sincerely,
Kira Qian
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!Friday, July 2, 2010 6:47 AM -
Yes, I use dialog based MFC project and I have class generated from a Type Library.
MFC ClassWizard - Member Variables tab - Add Variable Button
message:
"The ActiveX is not registered properly, or its type library version number is incorrect ...."
Friday, July 2, 2010 1:08 PM -
I can reproduce the issue when using .NET built COM in MFC project. COM only exposes the interface in binary. So VC++ cannot construct its member. You need to create a class for the interface (use MFC class from TypeLib wizard) first then create member variable in code.
Sincerely,
Kira Qian
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!Monday, July 5, 2010 2:47 AM -
1. I created class form type library (files: dotnetactivex.h, dotnetactivex.cpp):
class ICSSExplorerInterface : public COleDispatchDriver
{
public:
ICSSExplorerInterface() {} // Calls COleDispatchDriver default constructor
ICSSExplorerInterface(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
ICSSExplorerInterface(const ICSSExplorerInterface& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}// Attributes
public:// Operations
public:
void setButtonCaption(LPCTSTR strNewCaption);
void setAdapterDllPtr(long i_AdapterDllPtr);
};2. I add #include "dotnetactivex.h" to my Dialog class.
3. VC++ 6.0 - When I'm trying to add new member variable message apears "The ActiveX is not registered properly, or its type library version number is incorrect ...."
4. I created dialog member variable in code, but I don't know how to assign variable with control
Monday, July 5, 2010 6:44 AM -
After you create a class for the typed library, you can add a member in your dialog’s .h file. Just imitate which VS do. A class’s member is not the pointer to the class. Then in your dialog .cpp file, you can call the member’s public function.
.h file
ICSSExplorerInterface dotNetCtrl;
.cpp file
dotNetCtrl.setButtonCaption();
Sincerely,
Kira Qian
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!Monday, July 5, 2010 7:38 AM -
On a form I have for example 2 ActiveX controls and 2 members. Which control is assigned with wich ID on a form ?
This is not a solution.
Tuesday, July 6, 2010 1:07 PM -
The DDX_Control function can associate the id with the variable. You can add this function call to the DoDataExchange function.
http://msdn.microsoft.com/en-us/library/z04ab59a%28VS.80%29.aspx
Sincerely,
Kira Qian
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!Wednesday, July 7, 2010 2:03 AM -
ICSSExplorerInterface class is not a kind of CWnd - compilation error.
void AFXAPI DDX_Control(
CDataExchange* pDX,
int nIDC,
CWnd& rControl
);Wednesday, July 7, 2010 6:38 AM -
Hi pawelde,
After further consulting I found MFC doesn’t support to load .NET COM by “Add ActiveX control”. So I come back to use the way on code project. Below is the whole sample for MFC dialog based application load .NET C# ActiveX control.
http://cid-ee362b84156dcc82.office.live.com/self.aspx/MSDN/Solution/%5E52010.7.8%5E6MFCDotNetAX.zip
If you have any question with my code, please feel free to tell me.
Sincerely,
Kira Qian
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!Thursday, July 8, 2010 9:02 AM -
Your example works fine but I have problem with setting control position on a form. I put static on a form and set _hSelf to GetDlgItem(IDC_STATIC)->m_hWnd
like this:
//_hSelf = this->m_hWnd;
_hSelf = GetDlgItem(IDC_STATIC)->m_hWnd;
loadActiveX(TEXT(
"DotNetActiveX.MyDotNetActiveX"));
When I click on OK button application hangs :(
Monday, July 12, 2010 8:09 AM -
loadActiveX function calls CreateWindowEx to create the ActiveX control. So you can change the parameter to define the position.
Sincerely,
Kira Qian
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!Monday, July 12, 2010 8:21 AM -
I need posision form resource not from code. Why application hangs when I click OK :(
Monday, July 12, 2010 8:36 AM -
_hSelf = GetDlgItem(IDC_STATIC)->m_hWnd;
......
_hAtl = ::CreateWindowEx(
WS_EX_CLIENTEDGE,\
TEXT("AtlAxWin"),\
strActiveXName,\
WS_CHILD | WS_VISIBLE | /*WS_CLIPCHILDREN | */WS_EX_RTLREADING,\
0, 0, rcClient.right, rcClient.bottom,\
this->m_hWnd,\
NULL,\
NULL,\
NULL);IT WORKS :)
- Marked as answer by pawelde Monday, July 12, 2010 8:51 AM
Monday, July 12, 2010 8:51 AM