VB CreateObject method call in C ++

I am trying to call the Visual Basic CreateObject method from my C ++ code. In VB, I just type:

Dim obj As Object obj = CreateObject ("WScript.Network")

And that returns me an object from which I can call more methods. But how can I do this in C ++? I follow the MSDN documentation at http://msdn.microsoft.com/en-us/library/bb776046(v=VS.85).aspx , but these parameters are very unclear and I cannot understand them.

The first parameter is a reference to the CLSID, and I see from the registry that the CLSID for "WScript.Network" is {093FF999-1EA0-4079-9525-9614C3504B74}. But what is the difference between this parameter and the third, REFIID?

Thanks in advance!

+3
source share
2

, , CoCreateInstance http://msdn.microsoft.com/en-us/library/ms686615%28VS.85%29.aspx (: CComPtr < > , _com_ptr < > ..).

-, , IID - , CLSID - . COM- , ( VB , - , CLSID VB).

"" , VB, - IDispatch , IDispatch. "" ++ , , . (IID REFIID, ), .

, . , , , , .

+1

, . AddWindowsPrinterConnection . , , , HKEY_CURRENT_USER/Printers/LegacyPointAndPrint/DisableLegacyPointAndPrintAdminSecurityWarning 1 ( 0, , ).

CoInitialize(NULL);
{
    ATL::CComPtr<IDispatch> test;
    _variant_t printerConnection = "\\\\serverAddress\\printerName";
    _variant_t result;
    test.CoCreateInstance(L"WScript.Network");
    test.Invoke1(L"AddWindowsPrinterConnection", &printerConnection, &result);
}

CoUninitialize();
+2

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


All Articles