Using ocx in a console application

I want to quickly test ocx. How to remove this ocx in a console application. I found some tutorials in CodeProject and but not completely.

+3
source share
3 answers

Of course ... it's pretty easy. Here is a fun app that I threw together. I assume you have Visual C ++.

Save in test.cpp and compile: cl.exe / EHsc test.cpp

To test your OCX, you need to either #import typelib or use the CLSID (or just hard CLSID) in the CoCreateInstance call. Using #import will also help identify any custom interfaces you may need.

#include "windows.h"
#include "shobjidl.h"
#include "atlbase.h"

//
// compile with:  cl /EHsc test.cpp
//

// A fun little program to demonstrate creating an OCX.
// (CLSID_TaskbarList in this case)
//

BOOL CALLBACK RemoveFromTaskbarProc( HWND hwnd, LPARAM lParam )
{
    ITaskbarList* ptbl = (ITaskbarList*)lParam;
    ptbl->DeleteTab(hwnd);  
    return TRUE;
}

void HideTaskWindows(ITaskbarList* ptbl)
{
    EnumWindows( RemoveFromTaskbarProc, (LPARAM) ptbl);
}

// ============

BOOL CALLBACK AddToTaskbarProc( HWND hwnd, LPARAM lParam )
{
    ITaskbarList* ptbl = (ITaskbarList*)lParam;
    ptbl->AddTab(hwnd); 

    return TRUE;// continue enumerating
}

void ShowTaskWindows(ITaskbarList* ptbl)
{
    if (!EnumWindows( AddToTaskbarProc, (LPARAM) ptbl))
        throw "Unable to enum windows in ShowTaskWindows";
}

// ============

int main(int, char**)
{
    CoInitialize(0);

    try {
        CComPtr<IUnknown> pUnk;

        if (FAILED(CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**) &pUnk)))
            throw "Unabled to create CLSID_TaskbarList";


        // Do something with the object...

        CComQIPtr<ITaskbarList> ptbl = pUnk;
        if (ptbl)
            ptbl->HrInit();

        HideTaskWindows(ptbl);
        MessageBox( GetDesktopWindow(), _T("Check out the task bar!"), _T("StackOverflow FTW"), MB_OK);
        ShowTaskWindows(ptbl);
    }
    catch( TCHAR * msg ) {
        MessageBox( GetDesktopWindow(), msg, _T("Error"), MB_OK);
    }       

    CoUninitialize();

    return 0;
}
+2

OCX ActiveX? (-, )?

, COM/ActiveX, - excel. (, , , )

  • Excel, , .
  • Alt+F11, Visual Basic ( Excel 2007 ""

, ...

  • Tools References
  • OCX/COM Browse..., , COM. , OCX .
  • Insert UserForm
  • Toolbox Additional Controls
  • OCX
  • OCX
  • Run .
  • OCX .

  • EXCEL, .

+3

@ORion . .

, @jschroedl .

ActiveX - . , . @jschroedl, IDIspatch Invoke.

GetIDsByName Invoke, VARIANTS Invoke.

Everything is fine and dandy. But as soon as you get to the events of your companion from there. A Windows application requires a fire to occur in the message. You do not have it on the console. I followed the path of implementing EventNotifier for events, just like you implement the CallBack interface in classic C ++ mode. But events do not reach your implemented interface.

I am sure that this cannot be done in a console application. But I really hope that someone there will have different events in the console application.

+1
source

Source: https://habr.com/ru/post/1696459/


All Articles