CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: class id

  1. #1
    Join Date
    Apr 2011
    Posts
    18

    Arrow class id

    Hello,

    I am a COM starter, I don't know exactly what is the differentce between class id and interface id ?

    I read into a tlh file which has the followiing definition


    struct __declspec(uuid("0123456789xxxxx")) IInterface;
    struct UUID
    {
    short ric;
    short cut;
    };

    for example. I can't find where is the CLSID and IID of the interface to make a call of CocreateInstance.
    WHat is UUID struct above ?


    Thank you very much.

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: class id

    Coclass represents object type, and object may implement several interfaces. On the other hand, different classes may implement the same interface(s).

    This way, CLSID identifies class, and IID identifies interface. Interfaces are implemented by class objects, therefore CoCreateInstance needs CLSID. TLH file should already have smart pointers declared, so you won't need to call CoCreateInstance directly, but call pointer's CreateInstance instead.

    Code:
    // something like this
    IInterfacePtr pi;
    HRESULT hr = pi.CreateInstance(__uuidof(MyObject));  // or..
    HRESULT hr = pi.CreateInstance(TEXT("MyObject.Interface")); // "MyObject.Interface" is ProgID of the Interface implementation
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2011
    Posts
    18

    Re: class id

    Thanks alot,
    Why do MS provide many interfaces that donot not have CLSID. Are they used in the way you explained ? If I'd like to use any of them what should I do ?

    Second, I mind-storm up an idea to use an interface without an registered CLSID that I may need to create a COM interface deriving from it, then registered my object with GUID and IID so later I can use it as usual, easy way hah. Is this a feasible approach ? Will I stuck at calls of the base interface's methods ? I doubt Yes is the answer...

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: class id

    Quote Originally Posted by HarryCummings View Post
    Thanks alot,
    Why do MS provide many interfaces that donot not have CLSID. Are they used in the way you explained ? If I'd like to use any of them what should I do ?
    Well, first of all, CLSID identifies an object but not interface. To know whether some interface is implemented by the object you need to QueryInterface at runtime (or inspect object's type library at design time). Therefore, there's no use of interface without an object which implements it. And to use the interface you have to know what object you need to create first. And that would be your CLSID.

    In the light of this, could you rephrase your question about MS and interfaces.
    Second, I mind-storm up an idea to use an interface without an registered CLSID that I may need to create a COM interface deriving from it, then registered my object with GUID and IID so later I can use it as usual, easy way hah. Is this a feasible approach ? Will I stuck at calls of the base interface's methods ? I doubt Yes is the answer...
    In COM world you can inherit to interface declaration. But you cannot inherit to its implementation, and this way you have to provide your own implementation to every interface method (including all the interfaces from the inheritance chain) unless you aggregate with anscestor object. In case you're okay with this limitation, you're fine. And indeed, you need to have unique IDs for your new class and interface.
    Best regards,
    Igor

  5. #5
    Join Date
    Apr 2011
    Posts
    18

    Re: class id

    Thank you very much. I am not into strict argument when I am in need of help. But you know I am angry reading what you imply! Maybe it's my mental issue. but your post sparks other ideas I am not content with.
    Please ignore my mumbles! I am very sincere and ... that straight!

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: class id

    Well. What I can get from your post is that you need help, and you're angry at what I imply (I wish I would know what I implied while I was surely explicit and straight )... So maybe you explain in more plain and simple English what is your main idea you need some help with. I can see some mentionning of TLH stuff, but on the other hand all the thread makes me believe you're not very good with the very basic COM things. Or I was not able to understand your real problem. Anyway, it would be good to start from the beginning.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured