CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    First steps in COM interop

    Hello folks,

    Long time no see, but I was sure that sooner or later I am going to have a problem I would need your help with

    One day I was reading some popular programming related blog, and I found a piece of code that would be very interesting for me: http://blogs.msdn.com/b/oldnewthing/.../10463035.aspx . What I am most interested with, is the last snippet:

    Code:
    #define STRICT
    #include <windows.h>
    #include <atlbase.h>
    #include <urlmon.h>
    #include <stdlib.h>
    
    int __cdecl wmain(int argc, wchar_t **argv)
    {
        if (argc < 2) return 0;
    
        CCoInitialize init;
    
        CComPtr<IZoneIdentifier> spzi;
        spzi.CoCreateInstance(CLSID_PersistentZoneIdentifier);
        spzi->Remove();
        CComQIPtr<IPersistFile>(spzi)->Save(argv[1], TRUE);
    
        return 0;
    }
    Now I'd like to use this functionality in my C# application. I know that C# and .NET platform are capable of COM interoperability, but it's area totally new to me. I tried to follow this tutorial: http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx but I failed at the very beginning, not being able to generate interop assembly from Urlmon.dll, where IZoneIDentifier is said to reside: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx. Error I get is:


    C:\progs\Microsoft Visual Studio 10.0 Express\Common7\Tools>"C:\Program Files\Mi
    crosoft SDKs\Windows\v6.0A\bin\TlbImp.exe" urlmon.dll
    Microsoft (R) .NET Framework Type Library to Assembly Converter 3.5.30729.1
    Copyright (C) Microsoft Corporation. All rights reserved.

    TlbImp : error TI0000 : The input file 'C:\Windows\system32\urlmon.dll' is not a
    valid type library.


    I am probably doing something wrong, but I have even no idea where to start. If you could guide me or point to some tutorial for COM dummies, I'd be grateful.

    I also found this implementation: https://github.com/citizenmatt/Unblo...ZoneIdentifier but it causes more questions than it answers (Where do GUIDs come from? How do I know what class members are there? etc.)

    I know that one can remove zone information by deleting alternative NTFS stream, but this seems to me as implementation detail rather and I'd like to use proper API which deals with zones themselves rather than with file system 'hidden' features.

    Cheers,
    Maciek
    B+!
    'There is no cat' - A. Einstein

    Use &#91;code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

  3. #3
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: First steps in COM interop

    Thanks for great link Arjay But like I said, I'd like to avoid a solution based on alternate NTFS streams because of two reasons:

    - It does not feel correct to me, as I believe that alternate data streams are just implementation detail of how zone information is stored. Much more I prefer any API which deals with zones directly
    - This example seems to be easy enough to learn something about COM

    If I won't succeed with my preferred approach, then I think I'd use alternate streams anyway. But for now, I'd be glad to hear something about how I could implement above code snippet in C#


    Thank you for your help,
    Maciek
    B+!
    'There is no cat' - A. Einstein

    Use &#91;code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: First steps in COM interop

    I didn't actually look but in the link I sent it refers to an extension library that was based off of c++ code from an msdn article. You moght be able to round up that code.

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