I use the declaration below in a console app & a winforms app. Both are 3.5 framework.
[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);
The console app is OK, the winform app errors:
Unable to find an entry point named 'NetUseAdd' in DLL 'NetApi32.dll'
I have scoured the web & came up with the declaration below. This 1 gives the same error for the winform app.
[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;
}
I've run dumpbin /export & NetUseAdd is there.
All help is much appreciated.