I've been trying to setup some interop with some win32 classes in various dlls using ComImport for a C# application I'm writing. What I don't understand is how you find the GUID for a class? I found some examples of imports that work but I'm not sure how the authors found the GUID for the classes. An example of importing IFileDialog and one of its methods is listed below.
[ComImport(), Guid("42F85136-DB7E-439C-85F1-E4075D135FC8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IFileDialog {
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[PreserveSig()]
uint Show([In, Optional] IntPtr hwndOwner); //IModalWindow
I'm using Visual Studio 2012 and I can see how to Add a reference to shell32.dll in the Microsoft Shell Controls and Automation on the COM tab but this doesn't seem to do anything for me. What am I missing here? Where do you find the GUID? Is there some way to get Visual Studio to generate the code listed above or do I need to find the GUID for each class and then write up the method import as listed above?