G
There are two types of COM: IUknown派 and IDisp (this is also a derivative from IUknown). code[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]IUnknownIf you are deriving from IUnknown, the call will be processed by the number one method you call from the beginning without using the method name. Therefore, the order of the interface declaration on C# becomes important. By the way, if you use IDisp , you can use the same as IUnknown as the first order, but you can also use the method name separately.The extension .IDL file of Visual Studio's C++ include file directory isインターフェースd by the COM interface. If you search, you can find IExtractImage and IShellFolder in the ShObjIdl.idl file. IShellFolder is different from the code in which the order is written. [call_as] )I think that I will not solve this alone, but I need to proceed one by one.If you search in the registry editor, for example IShellFolder {000214E6-0000-C000-000000000046}HKEY_CL HES_ROOT\Interface\{000214E6-0000-C000-000000000046}\ProxyStubClsid32(Default) = "{C90250F3-4D7D-4991-9B69-A5C5BC1C2AE6}"HKEY_CL HES_ROOT\CLSID\{C90250F3-4D7D-499-A5C5BC1C2AE6}\InProcServer32ThreadingModel = "Both" Both means that it can work with both STA and MTA threads. IExtractImage。[STAThread]We don’t solve any problems.The code is not checked because there is no declaration of SIZE.SHGetDesktopFolder()HRESULT SHGetDesktopFolder(_Out_ IShellFolder **ppshf);
C#[DllImport("shell32.dll")]
static extern int SHGetDesktopFolder(out IShellFolder ppshf);
can (This function does not handle strings, but CharSet.Auto in C# refers to ANSI, ANSI-JIS, so Unicode is better. )Normal http://referencesource.microsoft.com/ When referring to the COM interface, you can find what wasインターフェースd inside the .NET. However, IShellFolder does not work because there is a wrong declaration inside the .NET. (At least GetUIObjectOf() and GetDisplayNameOf() are broken. )I don't need much...[PreserveSig]UInt32 GetUIObjectOf(IntPtr hwndOwner, UInt32 cidl, ref IntPtr apidl, [In] ref d riid, ref UInt32 rgfReserved, ref IntPtr ppv); //←☆ This is not yet working properlystatic d IID_IExtractImage = new d("{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}");IntPtr res = IntPtr.Zero;shell.GetUIObjectOf(IntPtr.Zero, 1, ref ppidl, ref IID_IExtractImage, ref rgfRes, ref res);ieimg = (IExtractImage)Marshal.GetTypedObjectForIUnknown(res, typeof(IExtractImage));The added code (only cidl=1) has been activated. It seems to be another factor such as file association. Snake foot// 最後の引数がoutの場合、戻り値にできる
// COMポインターはIUknownなobject型にマーシャリング可能
// Guid構造体に限りUnmanagedType.LPStructが使える
[return: MarshalAs(UnmanagedType.IUnknown)]
object GetUIObjectOf(IntPtr hwndOwner, UInt32 cidl, ref IntPtr apidl, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, ref UInt32 rgfReserved);
// COMオブジェクトの型キャストはCOMのQueryInterfaceに相当する
// Type.GUIDでGuidAttributeの値が取得できる
// またrefでなくしたのでいったん変数に置く必要がなくなる
ieimg = (IExtractImage)shell.GetUIObjectOf(IntPtr.Zero, 1, ref ppidl, typeof(IExtractImage).GUID, ref rgfRes, ref res);
canIn the .NET Framework class library there is a little code that seems to be not aware of this technique.