我在控制台应用程序和 winforms 应用程序中使用以下声明。两者都是3.5框架。
    [DllImport("NetApi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    internal static extern NET_API_STATUS NetUseAdd(
        LPWSTR UncServerName,
        DWORD Level,
        ref USE_INFO_2 Buf,
        out DWORD ParmError);
控制台应用程序正常,winform应用程序错误:
在 DLL“NetApi32.dll”中找不到名为“NetUseAdd”的入口点
我已经在网上搜索并提出了以下声明。这 1 为 winform 应用程序提供了相同的错误。
    [DllImport("NetApi32.dll", 
        SetLastError = true, 
        CharSet = CharSet.Unicode
        )]
    public static extern uint NetUseAdd(
         string UncServerName,
         UInt32 Level,
         USE_INFO_2 Buf,
         out UInt32 ParmError
        );
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct USE_INFO_2
    {
        public string ui2_local;
        public string ui2_remote;
        public string ui2_password;
        public UInt32 ui2_status;
        public UInt32 ui2_asg_type;
        public UInt32 ui2_refcount;
        public UInt32 ui2_usecount;
        public string ui2_username;
        public string ui2_domainname;
    }
我已经运行了 dumpbin /export & NetUseAdd 在那里。
非常感谢所有帮助。