// Use this when the unmanaged API expects the structure passed by-value, or
// or if you want to pass it by-reference as a pointer to a structure
struct NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
}
// Use this when you want to pass it by-value even though the unmanaged API expects
// a pointer to a structure. Being a class adds an extra level of indirection
[StructLayout(LayoutKind.Sequential)]
class NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
}
Without the Structlayout the WNetAddConnection2 does not work !!!
This is defined as a class rather than a structure, so it's only appropriate for passing (by-value) when a pointer to a structure is needed.