ExecutionEngineException for WNetGetNetworkInformation(....)

K

Kerem Gümrükcü

Hi,

when i call the WNetGetNetworkInformation(...) inside my application,
i get a fatal ExecutionEngineException for it. The pinvoke signatures
are pretty correct translated (i translated them by hand, no tool!). See
here:

[DllImport("mpr.dll",
CharSet = CharSet.Unicode)]
internal static extern uint WNetGetNetworkInformation(
string NetworkProviderName,
ref NETINFOSTRUCT NetInfoStruct);

[StructLayout(LayoutKind.Sequential,
CharSet = CharSet.Unicode)]
public class NETINFOSTRUCT
{
public uint cbStructure;
public uint ProviderVersion;
public NETINFOSTRUCTStatus Status;
public NETINFOSTRUCTCharacteristics Characteristics;
public UIntPtr Handle;
public ushort NetType;
public uint PrintersFlags;
public uint DrivesFlags;
}

public enum NETINFOSTRUCTStatus : uint
{
NO_ERROR = 0,
ERROR_NO_NETWORK = 1222,
ERROR_BUSY = 170,
}

public enum NETINFOSTRUCTCharacteristics : uint
{
NETINFO_DLL16 = 0x00000001,
NETINFO_DISKRED = 0x00000004,
NETINFO_PRINTERRED = 0x00000008,
}

Doing a call like that raises the exception,...why?

//prepare buffer for usage
NETINFOSTRUCT nis = new NETINFOSTRUCT();
nis.cbStructure = (uint)
Marshal.SizeOf(typeof(NETINFOSTRUCT));

//get the provider information
if (WNetGetNetworkInformation("Microsoft Windows Network",
//standard provider
ref nis) == 0)
{
return nis;
}
else
{
return null;
}

And then it goes bye bye,...so, what can i do,...?
Can someone confirm that?

Thanks in advance,...

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
 
K

Kerem Gümrükcü

Hi,

i solved it by redefinig the PInvoke like this with explicit
In/Out attributes:

[DllImport("mpr.dll",
CharSet = CharSet.Unicode)]
internal static extern uint WNetGetNetworkInformation(
string NetworkProviderName,
[Out] [In] NETINFOSTRUCT NetInfoStruct);

Hope this helps someone someday,....

Regards

Kerem

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top