Link to home
Start Free TrialLog in
Avatar of Weig
Weig

asked on

How to create Machine generated IDispatch wrapper class(es) created in VC++

Hi:

I am trying to develop an application which is MFC based C++ application, but also has VBScripting ability. I need to create some IDispatch wrapper classes which are used for MFC control. I saw some sample that use these classes. But I don't know how to generate them. Can anyone please give me some suggestions?
ASKER CERTIFIED SOLUTION
Avatar of martynjpearson
martynjpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Weig
Weig

ASKER

Hi, Thanks for the reply...

I tried your method, but the thing is that I want the class derived from CWnd, not COleDispatchDriver...I read some samples, all their classes are derived from CWnd too...Is there a way to change base class or are there some other way to generate this IDispatch wrapper class? Thanks alot...
You could create a class that derives from CWnd and the generated COleDispatchDriver derived class?

Not quite sure what you're trying to achieve, but if you're adding VBScript functionality to your app, the sample MFCAxs on MSDN might be of interest to you.

Sorry I can't be more helpful.
A thought sprung to mind - are you wanting to create the server side objects that can be controlled by automation, or the client side wrapper for an exposed interface. If you are doing the server side bit, when you create dialogs etc you can specify that the object is creatable by automation on the ClassWizard "new class" dialog.

Hope this helps.
Avatar of Weig

ASKER

Thanks Martynjpearson for your help...

The following derived class is what I am looking for to generate...
"
#if !defined(AFX_COMMANDBUTTON_H__571AB67C_C79E_4B48_9C2C_14D91A448B3C__INCLUDED_)
#define AFX_COMMANDBUTTON_H__571AB67C_C79E_4B48_9C2C_14D91A448B3C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// 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.

/////////////////////////////////////////////////////////////////////////////
// CCommandButton wrapper class

class CCommandButton : public CWnd
{
protected:
      DECLARE_DYNCREATE(CCommandButton)
public:
      CLSID const& GetClsid()
      {
            static CLSID const clsid
                  = { 0xd7053240, 0xce69, 0x11cd, { 0xa7, 0x77, 0x0, 0xdd, 0x1, 0x14, 0x3c, 0x57 } };
            return clsid;
      }
      virtual BOOL Create(LPCTSTR lpszClassName,
            LPCTSTR lpszWindowName, DWORD dwStyle,
            const RECT& rect,
            CWnd* pParentWnd, UINT nID,
            CCreateContext* pContext = NULL)
      { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

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

// Attributes
public:

// Operations
public:
      void SetAutoSize(BOOL bNewValue);
      BOOL GetAutoSize();
      void SetBackColor(long nNewValue);
      long GetBackColor();
      void SetBackStyle(long nNewValue);
      long GetBackStyle();
      void SetCaption(LPCTSTR lpszNewValue);
      CString GetCaption();
      void SetEnabled(BOOL bNewValue);
      BOOL GetEnabled();
      void SetRefFont(LPDISPATCH newValue);
      LPDISPATCH GetFont();
      void SetForeColor(long nNewValue);
      long GetForeColor();
      void SetTakeFocusOnClick(BOOL bNewValue);
      BOOL GetTakeFocusOnClick();
      void SetLocked(BOOL bNewValue);
      BOOL GetLocked();
      void SetMouseIcon(LPDISPATCH newValue);
      void SetRefMouseIcon(LPDISPATCH newValue);
      LPDISPATCH GetMouseIcon();
      void SetMousePointer(long nNewValue);
      long GetMousePointer();
      void SetPicture(LPDISPATCH newValue);
      void SetRefPicture(LPDISPATCH newValue);
      LPDISPATCH GetPicture();
      void SetPicturePosition(long nNewValue);
      long GetPicturePosition();
      void SetAccelerator(LPCTSTR lpszNewValue);
      CString GetAccelerator();
      void SetWordWrap(BOOL bNewValue);
      BOOL GetWordWrap();
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_COMMANDBUTTON_H__571AB67C_C79E_4B48_9C2C_14D91A448B3C__INCLUDED_)
"
the code is from one of the sample program...I want to know how to create this machine generated class...any other idea?Thanks alot
Hi - I'm afraid I'm at a bit of a loss quite how that gets generated - I've even had a play around trying to generate classes myself and can't get anything that looks like that!

As well as the MFCAxs sample above, there are a couple of articles on CodeProject here http://www.codeproject.com/com/#Automation that cover adding scripting capabilities to your app - maybe they might shed some more light on your problem.

Sorry I can't be more help.
That class is generated when you import an activex control. In VS 7.1 you can right click on a dialog resource and choose "Insert ActiveX Control".

Right click on the new control and choose "Add Variable". Once you have done that the files should be generated. Inserting in VS 6.0 should be similar, it may be on a main menu when you have a dialog editor open... I can't quite remember.

Hope this helps,
Scott.
Avatar of Weig

ASKER

Hi Scott, Thanks for the reply.

I have tried your method, but it did not give me the class I wanted. When I did right click on dialog resource and choose "Insert Active Control", all I got was a list of .ocx and .dll files. Don't know if there was something I did wrong. Just could not get the wrapper class. btw, I am using VS6.0...

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Weig

ASKER

Thanks Scott for working on it.
yes, I did get that dialog. But like I wrote, it gave me a list of .ocx and .dll files, I don't know what use of these files to generate the wrapper class I want...
OK, maybe we have a misunderstanding. Do you have an ActiveX control(dll or ocx)  that you want to import into MFC? If not, I don't think you can generate the wrapper classes you are looking for, as they are produced when you import an ActiveX control into a MFC application.
Avatar of Weig

ASKER

Oh, I think we did...No, I don't have any ActiveX control that I want to import into my project.
But from the sample program I download, it did not have any .ocx or .dll files in the project and it still has the wrapper class generated in the project. I don't know how...but it does have it...
Anyway, thank you very much for your help. I really appreciate it.

Wei
The ocx or dll does not have to be in the project, just registered on the system that produced the project(who ever wrote the sample). If you look at the line that looks like this in the generated header file:

static CLSID const clsid
              = { 0xd7053240, 0xce69, 0x11cd, { 0xa7, 0x77, 0x0, 0xdd, 0x1, 0x14, 0x3c, 0x57 } };
         return clsid;

in your sample project, you can search for that key in the registry under:

HKEY_CLASSES_ROOT/Clsid/

assuming you have the class registered as well. Importing the dll or ocx specfied in the classes InprocServer32 subkey should net you the same two files. Perhaps that will help you find a solution.

Sorry I could not be of more help.
scott.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split points between  martynjpearson & GuppyG

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer