none
wnetconnectiondialog1 API的问题 RRS feed

  • 问题

  • [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] private class CONNECTDLGSTRUCT { public int StructureSize; public IntPtr Owner; public IntPtr ConnectResource; public ConnectDialogFlags Flags; public int DeviceNumber; } [StructLayout(LayoutKind.Sequential)] private class NETRESOURCE { public int Scope; public int RType; public int Display; public int Usage; [MarshalAs(UnmanagedType.LPTStr, SizeConst = 200)] public string LocalName; [MarshalAs(UnmanagedType.LPTStr, SizeConst = 200)] public string RemoteName; [MarshalAs(UnmanagedType.LPTStr, SizeConst = 200)] public string Comment; [MarshalAs(UnmanagedType.LPTStr, SizeConst = 200)] public string Provider; } [DllImport("mpr.dll", CharSet = CharSet.Auto)] private static extern int WNetConnectionDialog1(CONNECTDLGSTRUCT connDlgStruct); public static bool MapDrive(IntPtr handle, string remotename) { NETRESOURCE nResource = new NETRESOURCE(); CONNECTDLGSTRUCT ConnectInfo = new CONNECTDLGSTRUCT(); nResource.Scope = 2; nResource.RType = 1; nResource.Display = 3; nResource.Usage = 1; nResource.LocalName = null; nResource.RemoteName = remotename; nResource.Comment = null; nResource.Provider = null; ConnectInfo.StructureSize = Marshal.SizeOf(ConnectInfo); ConnectInfo.Owner = handle; ConnectInfo.ConnectResource = Marshal.AllocHGlobal(Marshal.SizeOf(nResource)); Marshal.StructureToPtr(nResource, ConnectInfo.ConnectResource, true); ConnectInfo.Flags = ConnectDialogFlags.UseMru & ConnectDialogFlags.Persist; return WNetConnectionDialog1(ConnectInfo) == 0; }

     private enum ConnectDialogFlags : int
            {
                ReadOnlyPath = 0x00000001,
                //  Conn_point= 0x00000002,
                UseMru = 0x00000004,
                HideBox = 0x00000008,
                Persist = 0x00000010,
                NotPersist = 0x00000020,
            }

    使用这个函数有时候会导致vshost.exe已停止工作,程序是在w7 32bit编译的。

    生成的程序在w7 64bit运行,使用这个函数会导致这个程序死掉。

    是不是程序有问题?请高手帮忙看看,谢谢!


    • 已编辑 MarkXUke 2012年5月30日 2:52
    2012年5月30日 2:47

全部回复