Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than mpr, prefix the name with the module name and a period.
[DllImport("mpr.dll")]
public static extern uint WNetEnumResource(IntPtr hEnum, ref int lpcCount, IntPtr lpBuffer, ref uint lpBufferSize);
VB.NET Signature:
<DllImport("mpr.dll")> _
Public Shared Function WNetEnumResource(hEnum As IntPtr, ByRef lpcCount As Integer, lpBuffer As IntPtr, ByRef lpBufferSize As UInteger) As UInteger
End Function
User-Defined Types:
None.
Notes:
None.
Tips & Tricks:
Please add some!
C# Sample Code:
//Coded by Eugene E. Zhukovsky, 8.21.2002
// Added by Kill
//declare the DLL import functions
[DllImport("mpr.dll", CharSet=CharSet.Auto)]
public static extern int WNetEnumResource(
IntPtr hEnum,
ref int lpcCount,
IntPtr lpBuffer,
ref int lpBufferSize );
[DllImport("mpr.dll", CharSet=CharSet.Auto)]
public static extern int WNetOpenEnum(
RESOURCE_SCOPE dwScope,
RESOURCE_TYPE dwType,
RESOURCE_USAGE dwUsage,
[MarshalAs(UnmanagedType.AsAny)][In] Object lpNetResource,
out IntPtr lphEnum);
[DllImport("mpr.dll", CharSet=CharSet.Auto)]
public static extern int WNetCloseEnum( IntPtr hEnum );
//declare the structures to hold info
public struct NETRESOURCE
{
public RESOURCE_SCOPE dwScope;
public RESOURCE_TYPE dwType;
public RESOURCE_DISPLAYTYPE dwDisplayType;
public RESOURCE_USAGE dwUsage;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string lpLocalName;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string lpRemoteName;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string lpComment;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string lpProvider;
}
//the function we'll be calling
public static void WNETOE(Object o)
{
int iRet;
IntPtr ptrHandle = new IntPtr();
try
{
iRet =WNetOpenEnum(
RESOURCE_SCOPE.RESOURCE_GLOBALNET,
RESOURCE_TYPE.RESOURCETYPE_ANY,
RESOURCE_USAGE.RESOURCEUSAGE_ALL,
o,
out ptrHandle );
if( iRet != 0 )
{
return;
}
int entries;
int buffer = 16384;
IntPtr ptrBuffer = Marshal.AllocHGlobal( buffer );
NETRESOURCE nr;
for(;;)
{
entries = -1;
buffer = 16384;
iRet =WNetEnumResource( ptrHandle, ref entries, ptrBuffer, ref buffer );
if( (iRet != 0) || (entries < 1) )
{
break;
}
Int32 ptr = ptrBuffer.ToInt32();
for( int i = 0; i < entries; i++ )
{
nr = (NETRESOURCE)Marshal.PtrToStructure( new IntPtr(ptr), typeof(NETRESOURCE) );
if(RESOURCE_USAGE.RESOURCEUSAGE_CONTAINER == (nr.dwUsage
& RESOURCE_USAGE.RESOURCEUSAGE_CONTAINER))
{
//call recursively to get all entries in a container
WNETOE(nr);
}
ptr += Marshal.SizeOf( nr );
Console.WriteLine( " {0} : LocalName='{1}' RemoteName='{2}'",
nr.dwDisplayType.ToString(), nr.lpLocalName, nr.lpRemoteName );
}
}
Marshal.FreeHGlobal( ptrBuffer );
iRet =WNetCloseEnum( ptrHandle );
}
catch(Exception e)
{
}
}
//now call the function passing a null
WNETOE(null);
Public Structure NETRESOURCE
Public dwScope As RESOURCE_SCOPE
Public dwType As RESOURCE_TYPE
Public dwDisplayType As RESOURCE_DISPLAYTYPE
Public dwUsage As RESOURCE_USAGE
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpLocalName As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpRemoteName As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpComment As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpProvider As String
End Structure
#End Region
<DllImport("mpr.dll", CharSet:=CharSet.Auto)> _
Public Function WNetEnumResource(hEnum As IntPtr, ByRef lpcCount As Integer, lpBuffer As IntPtr, ByRef lpBufferSize As Integer) As Integer
End Function
<DllImport("mpr.dll", CharSet:=CharSet.Auto)> _
Public Function WNetOpenEnum(dwScope As RESOURCE_SCOPE, dwType As RESOURCE_TYPE, dwUsage As RESOURCE_USAGE, ByRef lpNetResource As NETRESOURCE, ByRef lphEnum As IntPtr) As Integer
End Function
<DllImport("mpr.dll", CharSet:=CharSet.Auto)> _
Public Function WNetCloseEnum(hEnum As IntPtr) As Integer
End Function
Sub Main()
WNETOE(Nothing)
End Sub
Public Sub WNETOE(ByRef o As NETRESOURCE)
Dim iRet As Integer
Dim ptrHandle As IntPtr = New IntPtr()
Try
iRet = WNetOpenEnum(RESOURCE_SCOPE.RESOURCE_GLOBALNET, RESOURCE_TYPE.RESOURCETYPE_ANY, RESOURCE_USAGE.RESOURCEUSAGE_CONTAINER, o, ptrHandle)
If iRet <> 0 Then Exit Sub
Dim entries As Integer
Dim buffer As Integer = 16384
Dim ptrBuffer As IntPtr = Marshal.AllocHGlobal(buffer)
Dim nr As NETRESOURCE
Do
entries = -1
buffer = 16384
iRet = WNetEnumResource(ptrHandle, entries, ptrBuffer, buffer)
If iRet <> 0 Or entries < 1 Then Exit Do
Dim ptr As Int32 = ptrBuffer.ToInt32
For count As Integer = 0 To entries - 1
nr = Marshal.PtrToStructure(New IntPtr(ptr), GetType(NETRESOURCE))
If (RESOURCE_USAGE.RESOURCEUSAGE_CONTAINER = RESOURCE_USAGE.RESOURCEUSAGE_CONTAINER And nr.dwUsage) Then
WNETOE(nr)
End If
ptr += Marshal.SizeOf(nr)
Console.WriteLine(String.Format("Path='{0}'", nr.lpRemoteName))
Next
Loop
Marshal.FreeHGlobal(ptrBuffer)
iRet = WNetCloseEnum(ptrHandle)
Catch ex As Exception
End Try
End Sub
End Module
Alternative Managed API:
TODO
Click to read this page
11/11/2013 3:39:31 AM - -12.170.217.217
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).