views:

1483

answers:

4

I want to quickly test an ocx. How do I drop that ocx in a console application. I have found some tutorials in CodeProject and but are incomplete.

+3  A: 

Isn't an OCX an ActiveX User Control? (something that you put onto a form for the user to interact with)?

The easiest way I know of to test COM/ActiveX stuff is to use excel. (Yes I know it sounds dumb, bear with me)

  1. Run Excel, create a new file if it hasn't done this for you
  2. Press Alt+F11 to launch the Visual Basic Editor (if you have excel 2007 it's on the 'Developer' ribbon tab thing

Now that you're in happy visual basic land...

  1. From the Tools menu, select References
  2. Select your OCX/COM object from the list, or click Browse... to find the file if it's not registered with COM - You may be able to skip this step if your OCX is already registered.
  3. From the Insert menu, select UserForm
  4. In the floating Toolbox window, right click and select Additional Controls
  5. Find your OCX in the list and tick it
  6. You can then drag your OCX from the toolbox onto the userform
  7. From the Run menu, run it.
  8. Test your OCX and play around with it.

  9. SAVE THE EXCEL FILE so you don't have to repeat these steps every time.

Orion Edwards
+1  A: 
jschroedl
+1  A: 

@orion thats so cool. Never thought of it that way.

Well @jschroedl thats was fun indeed.

Testing an activex in console app is fun. But I think its worth not trying down that path. You can call the methods or set and get the properties either through the way @jschroedl had explained or you can call the IDIspatch object through the Invoke function.

The first step is to GetIDsByName and call the function through Invoke and parameters to the function should be an array of VARIANTS in the Invoke formal parameter list.

All is fine and dandy. But once you get to events its downhill from there. Windows application requires a message pump to fire events. On a console you don't have one. I went down the path to implement a EventNotifier for the events just like you implement a CallBack interface in classic C++ way. But the events doesn't get to your implemented interface.

I am pretty sure this cannot be done on a console application. But I am really hoping someone out there will have a different take on events in a console application

rptony
A: 

@jschroedl: But what if Cocreateinstance returns S_OK while all subsequent method invocations (through _com_dispatch_method) all _end up in _com_error E_UNEXPECTED Catastrophic failure ?

I was able to instantiate and properly use my .ocx from a regular dialog based app;lication, but cant do so from console app. I am not using .NET anywhere, just COM. Any thoughts ?

Thank you

kellogs