<p>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. </p>

[{'answer_id': 19021, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 2, 'selected': False, 'text': "<p>Isn't an OCX an ActiveX User Control? (something that you put onto a form for the user to interact with)?</p>\n\n<p>The easiest way I know of to test COM/ActiveX stuff is to use excel. (Yes I know it sounds dumb, bear with me)</p>\n\n<ol>\n<li>Run Excel, create a new file if it hasn't done this for you</li>\n<li>Press <code>Alt+F11</code> to launch the Visual Basic Editor (if you have excel 2007 it's on the 'Developer' ribbon tab thing</li>\n</ol>\n\n<p>Now that you're in happy visual basic land...</p>\n\n<ol>\n<li>From the <code>Tools</code> menu, select <code>References</code></li>\n<li>Select your OCX/COM object from the list, or click <code>Browse...</code> 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.</li>\n<li>From the <code>Insert</code> menu, select <code>UserForm</code></li>\n<li>In the floating <code>Toolbox</code> window, right click and select <code>Additional Controls</code></li>\n<li>Find your OCX in the list and tick it</li>\n<li>You can then drag your OCX from the toolbox onto the userform</li>\n<li>From the <code>Run</code> menu, run it.</li>\n<li><p>Test your OCX and play around with it.</p></li>\n<li><p>SAVE THE EXCEL FILE so you don't have to repeat these steps every time.</p></li>\n</ol>\n"}, {'answer_id': 21773, 'author': 'jschroedl', 'author_id': 2420, 'author_profile': 'https://Stackoverflow.com/users/2420', 'pm_score': 3, 'selected': True, 'text': '<p>Sure..it\'s pretty easy. Here\'s a fun app I threw together. I\'m assuming you have Visual C++.</p>\n\n<p>Save to test.cpp and compile: cl.exe /EHsc test.cpp</p>\n\n<p>To test with your OCX you\'ll need to either #import the typelib and use it\'s CLSID (or just hard-code the CLSID) in the CoCreateInstance call. Using #import will also help define any custom interfaces you might need.</p>\n\n<pre>\n#include "windows.h"\n#include "shobjidl.h"\n#include "atlbase.h"\n\n//\n// compile with:  cl /EHsc test.cpp\n//\n\n// A fun little program to demonstrate creating an OCX.\n// (CLSID_TaskbarList in this case)\n//\n\nBOOL CALLBACK RemoveFromTaskbarProc( HWND hwnd, LPARAM lParam )\n{\n    ITaskbarList* ptbl = (ITaskbarList*)lParam;\n    ptbl->DeleteTab(hwnd);  \n    return TRUE;\n}\n\nvoid HideTaskWindows(ITaskbarList* ptbl)\n{\n    EnumWindows( RemoveFromTaskbarProc, (LPARAM) ptbl);\n}\n\n// ============\n\nBOOL CALLBACK AddToTaskbarProc( HWND hwnd, LPARAM lParam )\n{\n    ITaskbarList* ptbl = (ITaskbarList*)lParam;\n    ptbl->AddTab(hwnd); \n\n    return TRUE;// continue enumerating\n}\n\nvoid ShowTaskWindows(ITaskbarList* ptbl)\n{\n    if (!EnumWindows( AddToTaskbarProc, (LPARAM) ptbl))\n        throw "Unable to enum windows in ShowTaskWindows";\n}\n\n// ============\n\nint main(int, char**)\n{\n    CoInitialize(0);\n\n    try {\n        CComPtr&lt;IUnknown&gt; pUnk;\n\n        if (FAILED(CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**) &pUnk)))\n            throw "Unabled to create CLSID_TaskbarList";\n\n\n        // Do something with the object...\n\n        CComQIPtr&lt;ITaskbarList&gt; ptbl = pUnk;\n        if (ptbl)\n            ptbl->HrInit();\n\n        HideTaskWindows(ptbl);\n        MessageBox( GetDesktopWindow(), _T("Check out the task bar!"), _T("StackOverflow FTW"), MB_OK);\n        ShowTaskWindows(ptbl);\n    }\n    catch( TCHAR * msg ) {\n        MessageBox( GetDesktopWindow(), msg, _T("Error"), MB_OK);\n    }       \n\n    CoUninitialize();\n\n    return 0;\n}\n</pre>\n'}, {'answer_id': 24283, 'author': 'rptony', 'author_id': 1781, 'author_profile': 'https://Stackoverflow.com/users/1781', 'pm_score': 1, 'selected': False, 'text': "<p>@orion thats so cool. Never thought of it that way.</p>\n\n<p>Well @jschroedl thats was fun indeed. </p>\n\n<p>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. </p>\n\n<p>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.</p>\n\n<p>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. </p>\n\n<p>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</p>\n"}]
['https://Stackoverflow.com/questions/17928', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1781/']