Table of Contents

Interface IMPR

Namespace
Steeltoe.Common.Net
Assembly
Steeltoe.Common.Net.dll

An interface to methods of mpr.dll used by WindowsNetworkFileShare

public interface IMPR

Methods

AddConnection(NetResource, string, string, int)

Makes a connection to a network resource and can redirect a local device to the network resource.

P/Invoke call to mpr.dll - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetaddconnection2a
int AddConnection(WindowsNetworkFileShare.NetResource netResource, string password, string username, int flags)

Parameters

netResource WindowsNetworkFileShare.NetResource

Network resource to interact with

password string

Password for making the network connection

username string

Username for making the network connection

flags int

A set of connection options - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetaddconnection2a#parameters

Returns

int

An integer representing the result - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetaddconnection2a#return-value

CancelConnection(string, int, bool)

Cancels an existing network connection, removes remembered network connections that are not currently connected.

P/Invoke call to mpr.dll - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetcancelconnection2a
int CancelConnection(string name, int flags, bool force)

Parameters

name string

Pointer to a constant null-terminated string that specifies the name of either the redirected local device or the remote network resource to disconnect from.

If this parameter specifies a redirected local device, the function cancels only the specified device redirection. If the parameter specifies a remote network resource, all connections without devices are canceled.
flags int

Connection type - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetcancelconnection2a#parameters

force bool

Specifies whether the disconnection should occur if there are open files or jobs on the connection. If this parameter is FALSE, the function fails if there are open files or jobs.

Returns

int

An integer representing the result - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetcancelconnection2a#return-value

GetLastError(out int, out StringBuilder, int, out StringBuilder, int)

Retrieves the most recent extended error code set by a WNet function

P/Invoke call to mpr.dll - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetgetlasterrora
int GetLastError(out int error, out StringBuilder errorBuf, int errorBufSize, out StringBuilder nameBuf, int nameBufSize)

Parameters

error int

The error code reported by the network provider.

errorBuf StringBuilder

String variable to receive the description of the error

errorBufSize int

Size of error buffer

nameBuf StringBuilder

String variable to receive the network provider raising the error

nameBufSize int

Size of name buffer

Returns

int

If the function succeeds, and it obtains the last error that the network provider reported, the return value is NO_ERROR.

If the caller supplies an invalid buffer, the return value is ERROR_INVALID_ADDRESS.

UseConnection(IntPtr, NetResource, string, string, int, string, string, string)

Makes a connection to a network resource. Can redirect a local device to a network resource.

P/Invoke call to mpr.dll - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetuseconnectiona
int UseConnection(IntPtr hwndOwner, WindowsNetworkFileShare.NetResource netResource, string password, string username, int flags, string lpAccessName, string lpBufferSize, string lpResult)

Parameters

hwndOwner IntPtr

Handle to a window that the provider of network resources can use as an owner window for dialog boxes

netResource WindowsNetworkFileShare.NetResource

Network resource to interact with

password string

A null-terminated string that specifies a password to be used in making the network connection

username string

A null-terminated string that specifies a user name for making the connection

flags int

Set of bit flags describing the connection

lpAccessName string

Pointer to a buffer that receives system requests on the connection

lpBufferSize string

Pointer to a variable that specifies the size of the lpAccessName buffer, in characters.

If the call fails because the buffer is not large enough, the function returns the required buffer size in this location
lpResult string

Pointer to a variable that receives additional information about the connection

Returns

int

An integer representing the result - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetuseconnectiona#return-value