none
using Microsoft.VisualStudio.OLE.Interop especially PROPVARIANT.unionmember RRS feed

  • Question

  • I have tried a lot of different implementations to handle structured storage (most of them with P/Invoke).
    All these implementations had some errors or flaws I couldn't accept.

    At last I tried also the Microsoft.VisualStudio.OLE.Interop assembly which seems very promising.
    Remark: This namespace is only available after the installation of the Visual Studio 2010 SDK, which only can be installed with Visual Studio 2010 Professional (or higher).

    I managed to implement a lot. But I could not get all the values out of the PROPVARIANT.unionmember, which is an IntPtr.
    Strings and 4 byte data types seemed to have worked, but FILETIME or the according long value, I couldn't extract.

    I should be able to get any type of data (according to System.Runtime.InteropServices.VarEnum) when PROPVARIANT is used with ReadMultiple.
    Then I should also be able to set any type of data when PROPVARIANT is used with WriteMultiple.
    Furthermore the struct Microsoft.VisualStudio.OLE.Interop.PROPSPEC has the same kind of unionmember, which I think would be handled identically.

    Can somebody tell me, how to correctly get all kind of data out of the PROPVARIANT.unionmember and how to set data?

    Or, are there any a sample projects, tutorials or other hints, how I could learn how to use the PROPVARIANT.unionmember?


    • Edited by Tekener Wednesday, July 11, 2012 12:24 PM
    Wednesday, July 11, 2012 12:18 PM

Answers

  • There's a trial version which is to let you try before you buy, but you seems to have skipped that route. You probably want to check the return policy of the reseller.

    You do not have the legal right to redistribute the assembly but that does not prevent you to write your own code based on the C++ declaration with the help of P/Invoke Interop Assistant or reverse engineered code from the assembly. Since the C++ type declaration is documented and not changed in years, if you and Microsoft implement both of your pinvoke correctly the only difference between your pinvoke signature and Microsoft's would be the namespace. But the declaration in the assembly is only designed for Visual Studio which only comes with 32bit edition. I don't think it is tested for AnyCPU/X64 platforms. You can always ask here if you have problem with a particular API's pinvoke signature.

    The structure storage samples are not in recent versions of Visual Studio but in Windows SDK. And those samples are written in C++, if you want to use the APIs in C#, you need extract the API calls (find those functions with long and strange names) and replay the calls in C#. That's a lot of p-invoke to do, that is probably why people just write a mixed code C++/CLI wrapper and expose their own wrapper to .Net instead. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    • Marked as answer by Tekener Thursday, July 12, 2012 3:51 PM
    Thursday, July 12, 2012 3:13 PM

All replies

  • First of all unless your target users are Visual Studio users, I don't think you can not legally use the assembly. 

    See http://blogs.msdn.com/b/adamroot/archive/2008/04/11/interop-with-propvariants-in-net.aspx for a declaration of the PROPVARIANT structure and access methods.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    Wednesday, July 11, 2012 2:07 PM
  • Thank you for your answer.
    I already have tried the sources from the article Interop with PROPVARIANTs in .NET bevore.
    Unfortunately I couldn't get the sample project in VariantInterop.zip to run.
    I have this problem with many Visual Studio Projects that I try to upgrade to my current version.
    Normally I ignore this kind of articles, where the sources can not be built and run with my Visual Studio and switch to the next article.
    Every article about Structured Storage through PInvoke had some problem that I decided to give a trial to the next one.

    After many trials and extensive searches I ran across the article StgOpenStorageEx .Net C#.
    Until then, I always worked only with Visual Studio Express Versions.
    As the Visual Studio SDK can only be installed with a Visual Studio Professional (or higher) I decided to buy the Visual Studio 2010 Professional.
    I hoped, I can then leave behind all the unmature trials with PInvoke.
    After installing the Visual Studio SDK and downloading all the samples for it, I had to recognise that there was no useful documentation and no sample that handled Structured Storage.
    I also tried in vain to get an answer to my problem from the author of StgOpenStorageEx .Net C#.
    For this reason I thought it was a good idea to get support from a Microsoft Forum.
    Now you come and tell me, that I couldn't use the assembly legally.
    If this is the case I must just say, it was a bad decision to buy the Visual Studio Professional.
    It was bad to think the Professional Version would be more worth than the Express Version.
    If this ist the case, I would be forced again to try to get one of the PInvoke codes to run.
    I am disappointed.

    Thursday, July 12, 2012 1:50 PM
  • There's a trial version which is to let you try before you buy, but you seems to have skipped that route. You probably want to check the return policy of the reseller.

    You do not have the legal right to redistribute the assembly but that does not prevent you to write your own code based on the C++ declaration with the help of P/Invoke Interop Assistant or reverse engineered code from the assembly. Since the C++ type declaration is documented and not changed in years, if you and Microsoft implement both of your pinvoke correctly the only difference between your pinvoke signature and Microsoft's would be the namespace. But the declaration in the assembly is only designed for Visual Studio which only comes with 32bit edition. I don't think it is tested for AnyCPU/X64 platforms. You can always ask here if you have problem with a particular API's pinvoke signature.

    The structure storage samples are not in recent versions of Visual Studio but in Windows SDK. And those samples are written in C++, if you want to use the APIs in C#, you need extract the API calls (find those functions with long and strange names) and replay the calls in C#. That's a lot of p-invoke to do, that is probably why people just write a mixed code C++/CLI wrapper and expose their own wrapper to .Net instead. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    • Marked as answer by Tekener Thursday, July 12, 2012 3:51 PM
    Thursday, July 12, 2012 3:13 PM
  • Thank you for your patience and your valuable answers!
    I will try the P/Invoke again.

    Thursday, July 12, 2012 3:48 PM