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.
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)
- Run Excel, create a new file if it hasn't done this for you
- 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...
- From the
Tools
menu, selectReferences
- 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. - From the
Insert
menu, selectUserForm
- In the floating
Toolbox
window, right click and selectAdditional Controls
- Find your OCX in the list and tick it
- You can then drag your OCX from the toolbox onto the userform
- From the
Run
menu, run it. Test your OCX and play around with it.
SAVE THE EXCEL FILE so you don't have to repeat these steps every time.
@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
@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