C# 调用IShellExtInit.Initialize获取选中文件问题

谢馥春 发布于 2013/06/17 14:59
阅读 437
收藏 0
下面这段代码在32位的机器上运行正常,m_hDrop能渠道正确的值,但是在64位win7系统上m_hDrop总是0,Any CPU 和 X64 两种编译方式都返回的是0

C# code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[StructLayout(LayoutKind.Sequential)]
    public struct FORMATETC
    {
        public CLIPFORMAT cfFormat;
        public uint ptd;
        public DVASPECT dwAspect;
        public int lindex;
        public TYMED tymed;
    }
 
[StructLayout(LayoutKind.Sequential)]
    public struct STGMEDIUM
    {
        public uint tymed;
        public uint hGlobal;
        public uint pUnkForRelease;
    }
 
int IShellExtInit.Initialize(IntPtr pidlFolder, IntPtr lpdobj, uint hKeyProgID)
        {
            try
            {
                m_dataObject = null;
                if (lpdobj != (IntPtr)0)
                {
                    m_dataObject = (ShellLib.IDataObject)Marshal.GetObjectForIUnknown(lpdobj);
                    FORMATETC fmt = new FORMATETC();
                    fmt.cfFormat = CLIPFORMAT.CF_HDROP;
                    fmt.ptd = 0;
                    fmt.dwAspect = DVASPECT.DVASPECT_CONTENT;
                    fmt.lindex = -1;
                    fmt.tymed = TYMED.TYMED_HGLOBAL;
                    STGMEDIUM medium = new STGMEDIUM();
                    m_dataObject.GetData(ref fmt, ref medium);
                    <span style="color: #FF0000;">m_hDrop</span> = medium.hGlobal;
                    MessageBox.Show(m_hDrop.ToString());
                }
            }
            catch (Exception)
            {
            }
            return S_OK;
        }


哪位大哥遇到过类似的问题或者能解决的帮个忙,谢谢了!
加载中
返回顶部
顶部