Hi all,
This is an API question
I'm trying to get the UNC Path from a mapped drive. I call it once and get the ERROR_MORE_DATA code, so I call it a second time and I get the ERROR_CONNECTION_UNAVAIL code, which says "The device is not currently connected but it is a remembered connection." I'm kind of lost on that because I can see that the device is connected.
Code:
[DllImport("mpr.dll")]
private static extern int WNetGetUniversalName (string lpLocalPath,
int dwInfoLevel, ref UNIVERSAL_NAME_INFO lpBuffer, ref int lpBufferSize);
[DllImport("mpr", CharSet=CharSet.Auto)]
protected static extern int WNetGetUniversalName (string lpLocalPath,
int dwInfoLevel, IntPtr lpBuffer, ref int lpBufferSize);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
private struct UNIVERSAL_NAME_INFO
{
[MarshalAs(UnmanagedType.LPTStr)]
public string lpUniversalName;
}
//
//Constants
//
protected const int NO_ERROR = 0;
protected const int ERROR_MORE_DATA = 234;
protected const int ERROR_NOT_CONNECTED = 2250;
protected const int UNIVERSAL_NAME_INFO_LEVEL = 1;
protected const int ERROR_CONNECTION_UNAVAIL = 1201;
UNIVERSAL_NAME_INFO rni = new UNIVERSAL_NAME_INFO();
int bufferSize = Marshal.SizeOf(rni);
int nRet = WNetGetUniversalName(mappedDrive, UNIVERSAL_NAME_INFO_LEVEL,ref rni, ref bufferSize);
if (ERROR_MORE_DATA == nRet)
{
IntPtr pBuffer = Marshal.AllocHGlobal(bufferSize);;
try
{
nRet = WNetGetUniversalName(mappedDrive, UNIVERSAL_NAME_INFO_LEVEL,pBuffer, ref bufferSize);
//
// RETURNS ERROR 1201 = ERROR_CONNECTION_UNAVAIL
Any ideas? I'm using Windows 2000