ActiveX addons

Posted on 2000-05-13
Last Modified: 2013-11-20
First let me tell what I must do. I have been asked to do one application that can program many kinds of hardware devices.
Some of them I know, others I do not. This mean that my application must be prepared for new devices.
Furthermore, the programming software for each device should be available for other applications.
Ok, after this I began studying controls (activeX controls).
It seems to me that if I could make each programming software one activex then the problem of using in other environments
will be solved. Further, if a new device appears then I will just have to do another activeX.
Of course, the activeX interfaces would have to be the same for everybody.
Here is my big problem. How can I do my application to accept addons whithout the .h files!?!
Ok, my question is a bit weird but I am new to this world.
I have been able to make some simpler activex controls. But I have many problems in using them. This is
because my application can only meet them on runtime.
I think that what I want is something like the MMC functionality. That is we can add things on runtime.

So, lets suppose that I have the following CString OCXFile. This has been filled by one user action to lets say
Lets suppose also that each of my addons will have the methode AboutBox.
How can I call this method by simpling knowing the name of the ocxFile!?
Maybe I am wrong but I am thinking like C++. That Is I Have on class purely virtual with the names of the methods.
My addons are all derived from this class. On creation of the addon is the selection of it.

From what I have read one way is to insert the activex in a dialog box.
But for me this is impossible because the application must stablish the contact on run.

Every comments and solutions will be mostly appreciated.
I am giving a significant amount of points because I am looking for good comments to guide me and not just lines
of code.

My thanks for reading this.

Question by:lsimaozinho
  • 7
  • 5

Expert Comment

ID: 2808003
There are two steps for using an activeX component:

1. The declaration of a DispatchDriver class. You get it, if you creates a new class from your component's type library (.tlb file) using the class wizard. You said all of your activeX will get the same structure. So you can take a type library of an arbitrary activeX you created. The declaration will works with all others.

2. Connect the DispatchDriver class with you activeX. It looks like similar to this:

IMyDispatchClass     m_Idsp;  //IMyDispatchClass is your DispatchDriver class

if( m_Idsp.CreateDispatch("<programmatic identifier>") )
      m_Idsp.MethodOfActiveX(...); //usage

The programmatic identifier refers to your activeX (such as "Excel.Application") and you can use all of your activeX by inserting of their programmatic identifier.

Author Comment

ID: 2808063
Thanks mb,
I will now try your comment.
But there are two doubts that I still have:
How can my application automatically register the activex? Or is it better to have it register with regsrv32.exe?
Also the programmatic identifier can be retrieved from the registry or from the file?

The programmatic identifier is related with the CLSID of the object in the activeX?


Author Comment

ID: 2808239
I am getting the following error when invoking AboutBox.
"Warning: constructing COleException, scode = E_UNEXPECTED ($8000FFFF).
First-chance exception in Teste.exe: 0xE06D7363: Microsoft C++ Exception.
Warning: Uncaught exception in WindowProc (returning 1)."

My activex is windowless. Must I do something before invoking methods that create windows!?

From my last comment:
I have been trying things and I Think I can register each activex in my application with LoadLibrary/Dllregister.
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.


Author Comment

ID: 2808403
For the problem that I am having with AboutBox call, I have found
the following:
The code :
// allow subclass to disable Invoke
if (!pThis->IsInvokeAllowed(dispid))
      return E_UNEXPECTED;
in STDMETHODIMP COleDispatchImpl::Invoke(
      DISPID dispid, REFIID riid, LCID lcid,
      WORD wFlags, DISPPARAMS* pDispParams, LPVARIANT pvarResult,
      LPEXCEPINFO pexcepinfo, UINT* puArgErr)


is returning E_UNEXPECTED because (and here is the code of IsInvokeAllowed)
BOOL COleControl::IsInvokeAllowed(DISPID)
      return m_bInitialized;

m_bInitialized is FALSE!

I have only found one place where m_bInitialize is made TRUE:
"HRESULT COleControl::LoadState(IStream* pstm)"

This is what I have discovered, but I still do not know why is properties initialization
being tested by the library when I invoke one method!
Also what must I do to make LoadState be called?
And finally, I feel that LoadState is for persistence.
What function must I call to serialize and give one IStream (or like it)?

Sorry about my confusion but has I sayed I am new to this :)


Expert Comment

ID: 2808550
I'll try answer to your comments.

I think you need regsvr32 to register an activeX, because there are registry entrys necessary.
The programmatic identifier refers to the activeX like the CLSID. It built from the activeX application name and it's automation class name. You can also use the CLSID, but it's easier to work with the programmatic identifier.

exception error:
The application, that calls an activeX need the function call AfxOleInit(); to initialisize OLE automation. A good place for it is the InitInstance() member of your CWinApp derived class.
I hope it can solve the problem.

Author Comment

ID: 2809091
Sorry mb but AfxOleInit() does not solve the problem!
My InitInstance function is now

and everything is the same!

I still have the error!
Now I am doing:
if( m_Idsp.CreateDispatch("SMB050.ProgCtrl.1") )
            catch (COleException * e)
                  TRACE("Erro : %d\n",e->m_sc);

and getting:
"Warning: constructing COleException, scode = E_UNEXPECTED ($8000FFFF).
First-chance exception in Teste.exe: 0xE06D7363: Microsoft C++ Exception.
Erro : -2147418113"

Expert Comment

ID: 2810131
How works your AboutBox() - function?

Author Comment

ID: 2811247
Here is the code generated from the wizard:

// CSMB050Ctrl::AboutBox - Display an "About" box to the user

void CSMB050Ctrl::AboutBox()
      CDialog dlgAbout(IDD_ABOUTBOX_SMB050);

Accepted Solution

_mb_ earned 500 total points
ID: 2813601
I dont't know, there's a problem to start a dialog. Did you try other functions?
You can make a test: run a message box ( AfxMessageBox("...."); or only return a value to check, if the function generally works.

Author Comment

ID: 2896789
First, sorry mb for this long delay.
The problem is that I am accessing internet from home and I have my work far.

I have solved with a different approach.
I have never understand the problem but I have just made a simple thing: Using the add to project - activex control from VStudio!

Author Comment

ID: 2896800
Comment accepted as answer

Expert Comment

ID: 2896823
Don't worry about the delay, I'm glad that you found a solution.

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 70
Named range not carried over 10 63
no14 challenge 14 67
My project did see openJDK that I installed. What could be the problem 7 143
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question