I am upgrading a windows forms app. The app uses an active x control (ocx) file. We have gotten the ocx to compile and can register it. The main class in the C++ active x control project is a COleControlModule. When I go to add the control to the windows forms app like this
Me.Controls.Add(Me.ActiveXClass)
I get
Unable to cast COM object of type 'System.__ComObject' to class type
'System.Windows.Forms.Control'.
I know the active x class is a com object and I know that this COleControlModule class must not be compatible with a windows forms control. Is there anything I can do to make this work?
Any help is greatly appreciated.
This isn't working because a Runtime Callable Wrapper (RCW) is not a Windows Forms control. Only Windows Forms controls will work; to use an ActiveX control with the form, you must generate a Windows Forms wrapper for the ActiveX control. This is done with Aximp.exe, typically via adding the control to the Toolbox, as Hans suggested and then dragging an instance of the control to the form.
The steps are:
Select 'Choose Items, either from the Tools menu or by right-clicking the Tools tab
Select the COM Components tab
Select the ActiveX control either directly from the list or through the Browse button
From the Tools dialog, select the newly-added component with the mouse and drag it to the form.
A reference to the ActiveX control will be added to the project, as in this sample with the Adobe PDF reader:
<ItemGroup>
<COMReference Include="AcroPDFLib">
<Guid>{05BFD3F1-6319-4F30-B752-C7A22889BCC4}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="AxAcroPDFLib">
<Guid>{05BFD3F1-6319-4F30-B752-C7A22889BCC4}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>aximp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
</ItemGroup>
Note there are two entries, one to generate a Runtime Callable Wrapper (via tlbimp), and another to generate the AxImp wrapper (via aximp). These will be viewable in Solution View, under the project's references.
Related
I want to write a simple minesweeper as some practice. I created a dialog and I want to create a class to relate variables to the input for edit box. However when I right clicked the dialog, I cannot select "create a class".
Here is the screenshot. There wasn't any error so I don't know what to provide. If you need any extra information please let me know.
You can't add a class for a dialog of a Windows Desktop application. A Windows Desktop application uses only basic Win32 API which does not provide a class framework.
You have to choose the MFC application wizard, when creating a new project. From this wizard select "dialog based" to create the most basic application. It will automatically add a dialog with a corresponding class.
You only need to "Add Class" when adding more dialogs to the application.
Can ListControl be used in a dialog in a Non-MFC project? I am using visual c++ 2010.
The examples I have seen so far uses MFC, so it seems to me that ListControl is part of MFC. The code I am working on is not MFC based, however, Visual Studio still allows adding a ListControl to the dialog in the resource view, and generates rc code for the List Control. So my guess is that I should be able to use it. However, I could not use the standard method found online to add variable to the ListControl and use it.
How can I use the ListControl in this case? e.g. adding a column or write something to a cell? Some code example will certainly help.
The CListCtrl class is an MFC class. It can only be used from within an MFC project.
However, CListCtrl is simply a wrapper around the ListView common control, and a ListView control can be used in any Windows application—no MFC required.
The Resource Editor included with Visual C++ (confusingly) refers to a ListView control as a "List Control". You can insert one on your dialog, and all it will do is insert a ListView control.
If you're using MFC, you can choose to create a member variable corresponding to that control. The type of that member variable will be CListCtrl, because it is encapsulating access to a ListView control on your dialog.
If you are not using MFC, you can still use the ListView control, you'll just have to use the standard SDK mechanisms for accessing and manipulating it. For example, to insert an item into the ListView control on your dialog, you would obtain the control's window handle (GetDlgCtrlID) and send it a LVM_INSERTITEM message. The SDK documentation contains sample code listings, but they are a rather poor way to learn. The best resource for good old Windows SDK programming is still Charles Petzold's Programming Windows.
I have an older MFC project build in VS 2003 that I want to port to VS 2010. The project uses an ActiveX control for grids, namely, VSFlexGrid7 from Component One. The problem is, that this version of the ActiveX control does not work in Windows 7 (which is what I have). There is a newer version of the grid, namely, VSFlexGrid8 which should be compatible with Windows 7.
The solution would be to replace all the older controls with the newer ones.
My question is, what would be the steps in replacing the controls, without touching other parts of the project. What is the simplest method to accomplish this? Do I have to modify classes, resource IDs, etc.?
[Solution: Replace CLSIDs in the .RC file]
The ActiveX control is bound to the resource file via the guid that represents the control. If you were to look inside the .rc file you will see the control with the associated guid. In your case, it's probably best to completely remove the control from the dialog (using the resource editor) assuming that you can drag the newer version onto the same dialog. Once you've done that, you'll need to generate a new class wrapper for the control. The class wizard should be able to handle that for you. Once you've got a new class wrapper that represents the control, you'll need to replace the prior wrapper class in your source code.
Usually the control is created somewhere in your dialog code with CreateInstance.
If the interface is compatible (I assume it is) , you just have to change the name or GUID that is used in the CreateInstance Code.
I have a custom dialog which has an extension wid (CustomDialog.wid) and has a helper library to go with it written in C++. The helper library searches for SQL Servers in the network and fills the combobox in the custom dialog. It also saves the server name or IP address so that it may be used by custom actions later.
Can I use this custom dialog directly in WiX or do I need to create a WiX supported custom dialog?
You can convert them into WiX format by building a Visual Studio Setup and Deployment project and then using WiX's dark.exe to create a .wxs file. The output may or may not be completely useful but it's worth a try. You'd probably want to make the dialog size and layout are the same as any "built-in" WiX dialogs you might use in your new project.
I have an ActiveX component which contains a control (webbrowser control embedded in composite control dialog pane) for accessing certain URL. The ActiveX component accessing URL can be used in other MFC or VB projects. The usage is to register the ActiveX component (use regsvr32 cmd) and then insert the control in a dialog window by using "Insert ActiveX control".
Now I am planning to convert the ActiveX component to static library with the same browser window and web access functions. I wonder how to do it? In addition, how the browser window (in static library) can be used in other MFC projects. Is it through functions call? Is there a sample project available?
I used Microsoft .Net 2003 as development tool.
Thank you very much in advance.
I'm a little unclear about the extent to which you think you can put all of that in a static library.
This is probably not going to be as straightfoward as you think. The wizard and code in VS/MFC/ATL which allows you to insert an ActiveX control in a dialog is doing a lot of work for you. That said, it makes certain assumptions about the nature of the site for the ActiveX control, such as how the message pump works, who is the owner window, the threading model, and so on. In a dialog, these are knowns. In another context, they are not.
The right way to go about doing what you're doing is to leave it as an ActiveX control. Maybe if you stated what problem you are trying to solve by putting it into a static library, we could give other options.
The WebBrowser ActiveX control is really a wrapper for the shdocvw.dll library, in the system32 folder. shdocvw.dll is the heart and soul of IE (and, by extension, much of the Windows Explorer interface). It's all very heavily based on COM, which has its own rules for loading libraries and so on. So the site (any application which wants to use your ActiveX control) really needs to be friendly to ActiveX/COM anyway.