moving vb6 to ATL - atl

I am trying to replace my old control(ActiveX control) which was build in VB6 to control build in ATL.(Microsoft Platforms). I have serialized the control(VB6) object using stream.This object has some properties which are configured by users. Now while deserializing the object i am able to load the new control(ATL) because both control have same Prog id and class id.But not getting correct property values.
need help...

You are unlikely (well, that would be a surprise) to have binary compatibility for VB6 controls and C++ ATL controls, and having the same ProgID and CLSID is insufficient. What you could possibly do to pass persistent state between the two is IPersistPropertyBag interface and property bag to carry the property values.

Related

MFC Saving Custom Header Column Widths

So I'm just learning MFC to see if I want to start using it over normal Win32 programming. I have a SDI MFC application setup. I have a view with members that create a CTreeCtrl and CHeaderCtrl. I have a CDwordArray setup as m_ColWidths that is currently in my View class, but using MFC, should this be in the document class instead since I'll want to save and restore it to keep the users widths when program exits? I guess even though it's only part of the view it's still data and use GetDocument() to reference them?
TIA!!
Application state should not be stored in the document. The purpose of the CDocument(-derived) class is:
A document represents the unit of data that the user typically opens with the File Open command and saves with the File Save command.
CDocument supports standard operations such as creating a document, loading it, and saving it. The framework manipulates documents using the interface defined by CDocument.
The designated entity to store application state (e.g. size and visibility of UI elements) is the CWinAppEx(-derived) implementation:
CWinAppEx handles the application state, saves the state to the registry, loads the state from the registry, [...].

Is it possible to use CPropertyPage created in DLL in a main application?

I have a dialog-based MFC application that hosts CPropertySheet.
The idea is to scan some folder for DLLs, load each of them dynamically (using LoadLibrary()), acquire a pointer to a function that would work like a CPropertyPage factory, use that function to create per-DLL CPropertyPage instances and insert them to CPropertySheet.
In other words, scan a folder for plugins, acquire the per-plugin property pages and insert them to CPropertySheet of the main application so each plugin would have it's own options GUI.
Plugins are implemented in a form of regular MFC dlls (not extension dlls). I'm aware that AFX_MANAGE_STATE(AfxGetStaticModuleState()) is to be employed.
Each CPropertyPage being created must be derived from an abstract interface (say, IPluginOptionsPropPage) so it would be possible to cast the pointer that factory function returns to IPluginOptionsPropPage.
This task is supposed to be a routine one, however, I could not found any sound examples.
Yes it can be done. You can try these steps
Load the property page library using ::LoadLibrary. The return handle is the handle for the resource.
m_hResInstance = ::LoadLibrary(strFile);
Before creating the instance of the property page, set the instance of the resource handle to the library's handle.
m_hCurrent = AfxGetResourceHandle();
AfxSetResourceHandle(hResInstance);
//Create your property sheet here.
Then reset the resource handle to the current process resource.
//Reset the previous
AfxSetResourceHandle(m_hCurrent);
This will enable you to load the resource of the property page, others like header and library or function pointer can be used as intended.

Deleting / Editing ATL COM DLL properties / methods

I have created a COM ATL DLL in VS2012.
Adding events and properties is very easy.
However, I see no easy way to edit or delete an event or a property.
VS2012 automatically creates a lot of code for the event or property when I use the Add Wizard, and I am not sure if I should really delete or change this automatically created code manually when I made a mistake and want to replace or delete something.
Is there a way to edit and delete them in a clean way?
Perhaps there is a property / event manager somewhere in VS2012, but I did not find it.
Thank you!
You edit declaration of the methods/properties of your interest on IDL, and then the project stops building until you respectively fix it by reflecting changes on your C++ implementation - that's it.
IDL changes along with implementation updated respectively builds you updated DLL.
Be aware that applications which are already built against earlier method/property set might be in trouble after the update. Related earlier questions you might be interested in (you might, however be not - which I sense is the case at the moment, if your question is about updates while you are developing, and not updates on released module):
COM: If I change the parent of an Interface do I need to create a new Interface?
Would adding a new function to the existing COM interface break its binary compatibility?
Why is it necessary to add new events to the *end* of an IDL interface?

Retrieving ActiveX classID from the system registry with C++

I am working on a windows application that has a shockwave flash player embedded in it.The C++ part should be able to call Flash movie methods and vice versa.Initial experiment was done using MFC.It works.But now I want to port it to Qt as it allows easier UI development.Qt has got QAxObject which holds the ActiveX control you assign to it via setCotrol() method which should get a classID of the ActiveX or its name.Because the classID is more reliable than a name and because I have not found an example where flash player ActiveX is accessed using a name ,now I want to know how to retrieve that classID from the system registry of the OS.I suppose that for every machine some specific activeX classID may vary (correct me if I am wrong on it) .If it is true then I need to access the registry ,find shockwave activeX classid and then pass it into QaxObject::setControl() method.How do I do that?
Forgot to mention that in MFC application the ActiveX control gets the requested ActiveX automatically once you select the ActiveX type from the list of available system controls.In Qt you have no such an option.
Reading this http://www.nirsoft.net/utils/acm.html I understand that the CLASSID is constant on any machine.Is it true ? If yes then please discard my question as there is no reason searching for the ActiveX key on specific machine by the ProgID if it is the same always.
Thanks.
It would be better to query from the registry by mime type. You can find details on where that is stored here:
http://msdn.microsoft.com/en-us/library/aa751976%28v=vs.85%29.aspx
You can look up the mimetype in the registry and get the CLSID from that. You can look it up by name as well; the locations of both registry keys are explained in that document.

How can save Application Settings in the Registry via MFC?

I have a MFC application created by the MFC Project Wizard. I wanted to save/read application settings in the registry and so asked this question to find a C++ Registry wrapper as the Windows API is very messy. However, I have now heard that the MFC provides a way to do this. Is this true? If so, how can I read/write values, see whether a key exists and get a list of all the keys?
MFC provides an easy way to read/write Windows registry.
In your project you'll have a global CMyProjectName theApp; object.
CMyProjectName inherits CWinApp class which provides the SetRegistryKey() method.
That method sets theApp to write in the registry instead of an "ini" file.
In the documentation check out
CWinApp::GetProfileInt
CWinApp::GetProfileString
CWinApp::WriteProfileInt
CWinApp::WriteProfileString
methods on how to read and write integers and strings in the registry.