Click here to Skip to main content
15,883,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
INTRODUCTION:

I have created ActiveX control, using MFC ActiveX control wizard in Visual Studio 2019.
Consuming it in C# WinForms app works well, I face no problems and control works as intended.

I have tried to test the control by using it in MFC desktop app, by following these steps:
  • Right-clicking on Dialog Editor in Toolbox, I chose Choose items option.
  • Dialog box popped up, I clicked on COM Components tab and checked item with the name of my ActiveX control.
  • Control showed up in toolbox and I have successfully placed it in the resource editor.
  • Right clicking on the control, context menu appeared, I chose Add variable option

PROBLEM:

IDE created code for me, but it does not expose my methods from the control.
It seems that I can only use functionality provided by CWnd class.

QUESTION:

How can I generate missing code without previous versions of Visual Studio?

At this point I will take any advice because I am out of ideas and need this solved.
If additional info is required please leave a comment and I will provide it as soon as possible.

What I have tried:

  • I have Googled for a solution, and found out that option in the Class Wizard for generating the code for me is removed in this version.
  • This[^] advice does not help either, as I do not have access to Visual Studio 2017.
  • As I type this I am seeking a way to manually write the missing code, but still haven't found anything useful to me.
Posted
Updated 9-Jun-21 5:22am
Comments
[no name] 30-Oct-20 13:05pm    
What does this ActiveX control do? You said it works in C#. Wrap it in an interface, compile it to a DLL / com server, and access from MFC that way. And why ActiveX in the first place.

Microsoft has put back the ActiveX option in the Class Wizard in Visual Studio 2019 version 16.8 which is in Preview. The last time I worked with ActiveX was 15 years ago. ActiveX controls are easy to consume in VB6 and C# but not Visual C++. Please upload a simple project to Github to reproduce the problem. I'll see how to extract the COM interface from ActiveX for you.

Typelib and ActiveX now supported in MFC Wizards  | C++ Team Blog[^]
 
Share this answer
 
Comments
MyOldAccount 2-Nov-20 8:46am    
Thank you so much!

I apologize for answering only now (it was late at night when I saw your answer), here is the GitHub link:

https://github.com/AlwaysLearningNewStuff/CodeProjectQuestion
MyOldAccount 2-Nov-20 11:23am    
I have managed to solve the problem, but have awarded you 5 stars for the VS link.
Thank you.
I have managed to make it work.
For those who face the same issue, here is what I have done:

Wizard generates code similar to below:

Header file:

C++
#pragma once

// 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.

/////////////////////////////////////////////////////////////////////////////

#include "afxwin.h"

class YourClassName : public CWnd
{
protected:
	DECLARE_DYNCREATE(YourClassName )
public:
	CLSID const& GetClsid()
	{
		static CLSID const clsid
			= {0x3a614790,0xdc9e,0x4e5e,{0xb1,0xa3,0x91,0x97,0x84,0x57,0xc2,0x0a}};
		return clsid;
	}
	virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
						const RECT& rect, CWnd* pParentWnd, UINT nID, 
						CCreateContext* pContext = nullptr)
	{ 
		return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
	}

	BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
				UINT nID, CFile* pPersist = nullptr, BOOL bStorage = FALSE,
				BSTR bstrLicKey = nullptr)
	{ 
		return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
		pPersist, bStorage, bstrLicKey); 
	}

// Attributes
public:


// Operations
public:


};


In the //Operations part, define your missing functions, like below:

C++
// Operations
public:
	void Read();
	void Write();


CPP file:

Implement missing function like in the below example, and call InvokeHelper.

The hexadecimal argument is the ordinal of your missing function, you can find it in the ActiveX Control's IDL file.

C++
// 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.

#include "pch.h"
#include "YourClassName.h"

/////////////////////////////////////////////////////////////////////////////
// COCX

IMPLEMENT_DYNCREATE(YourClassName, CWnd)

/////////////////////////////////////////////////////////////////////////////
// YourClassName Properties

/////////////////////////////////////////////////////////////////////////////
// YourClassName Operations

void COCX::Read()
{
	InvokeHelper(0x02, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

void COCX::Write()
{
	InvokeHelper(0x01, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}


Hope this helps someone, thank you everyone for trying to help.
 
Share this answer
 
v2
I am facing the same issue. VS2019 16.9.3
Adding manually all the functions (200+) is not an option for me.
I have VS2015, will have a look at that...
 
Share this answer
 
Comments
Richard Deeming 9-Jun-21 11:29am    
Your question is not a "solution" to this already-solved question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900