Discussion:
ExecutionEngineException for WNetGetNetworkInformation(....)
(too old to reply)
Kerem Gümrükcü
2009-12-14 17:07:07 UTC
Permalink
Raw Message
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
-----------------------
Kerem Gümrükcü
2009-12-14 18:15:24 UTC
Permalink
Raw Message
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
--
-----------------------
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
-----------------------
Post by 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
[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
-----------------------
Loading...