[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: IBugTraqProvider2

From: <postmaster_at_tigris.org>
Date: Tue, 30 Dec 2008 12:56:59 -0800 (PST)

The following c++ code can be used to check if the c# class implements the interface. In this case, I'm using the GUID of the ExampleCsPlugin.MyPlugin which is "{5870B3F1-8393-4c83-ACED-1D5E803A4F2B}".

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
        HRESULT hr = CoInitialize(NULL);

        IID bugTrack2Iid,bugTrack1Iid,pluginIid;
        if (FAILED(IIDFromString(L"{5870B3F1-8393-4c83-ACED-1D5E803A4F2B}", &pluginIid)))
        {
                return -1;
        }
        if (FAILED(IIDFromString(L"{C5C85E31-2F9B-4916-A7BA-8E27D481EE83}", &bugTrack2Iid)))
        {
                return -1;
        }
        if (FAILED(IIDFromString(L"{298B927C-7220-423C-B7B4-6E241F00CD93}", &bugTrack1Iid)))
        {
                return -1;
        }

        LPUNKNOWN pUnk;
        hr = CoCreateInstance(pluginIid, NULL, CLSCTX_ALL, IID_IUnknown, (VOID FAR **) &pUnk);
        if (FAILED(hr))
        {
                return -1;
        }
        LPUNKNOWN bugTrack1Ptr;
        pUnk->QueryInterface(bugTrack1Iid, (void**)&bugTrack1Ptr);
        if(bugTrack1Ptr != NULL)
        {
                printf("plugin implements IBugTraqProvider interface.\r\n");
        }

        LPUNKNOWN bugTrack2Ptr;
        pUnk->QueryInterface(bugTrack2Iid, (void**)&bugTrack2Ptr);
        if(bugTrack2Ptr != NULL)
        {
                printf("plugin implements IBugTraqProvider2 interface.\r\n");
        }
        return 0;
}

--------

If the class is registered properly, the screen will output a message indicating if the class extends the IBugTraqProvider interface, the IBugTraqProvider2 interface or both. Similar code can be written in C# using the below code.

-----------------------------------

        static void Main(string[] args)
        {
            Type type = Type.GetTypeFromCLSID(new Guid("BCDFA46A-6F03-48b7-BD9B-16F61E45C68B"));
            object comObj = Activator.CreateInstance(type);

            Console.WriteLine("Extends IBugTraqProvider : {0}", ExtendsComInterface(comObj, "298B927C-7220-423C-B7B4-6E241F00CD93"));
            Console.WriteLine("Extends IBugTraqProvider2: {0}", ExtendsComInterface(comObj, "C5C85E31-2F9B-4916-A7BA-8E27D481EE83"));
        }

        static bool ExtendsComInterface(object comObj, string interfaceId)
        {
            IntPtr pUnk = Marshal.GetIUnknownForObject(comObj);
            Guid iid = new Guid(interfaceId);
            IntPtr ppv;
            int retVal = Marshal.QueryInterface(pUnk, ref iid, out ppv);
            if (retVal != 0)
            {
                return false;
            }
            return (ppv != IntPtr.Zero);
        }

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=757&dsMessageId=996297

To unsubscribe from this discussion, e-mail: [dev-unsubscribe_at_tortoisesvn.tigris.org].
Received on 2008-12-30 21:57:25 CET

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.