Why System.NullReferenceException?
using System;
using System.Runtime.InteropServices;
using NETENG;
public class MainClass {
[DllImport("neteng.dll")]
public static extern bool NE_IsNetwork(string name);
[DllImport("neteng.dll")]
public static extern long NE_OpenNetwork(string name, NETENG.AccessModeEnum mode);
[DllImport("neteng.dll")]
public static extern bool NE_QueryElementByID(long net, NETENG.ElementTypeEnum eltype, NETENG.IDAttRec id, NETENG.HandleAttRec h);
[DllImport("user32.dll")]
public static extern int MessageBox(int hWnd, string pText, string pCaption, int uType);
public static void Main(string[] args) {
try {
string name = @"D:\tracking\shapes\roadcenter_mkt_only.nws";
bool isItNet = NE_IsNetwork(name);
string pCaption = "Example by Norman";
string pText = "";
if (isItNet == false) {
pText = name + " is not a network.";
} else {
pText = name + " is a network.";
}
MessageBox(0, pText, pCaption, 0);
long net = NE_OpenNetwork(name, NETENG.AccessModeEnum.NE_READONLY);
if (net == 0) {
MessageBox(0, "Network " + name + " not found.", "Not Found", 0);
} else {
MessageBox(0, "Network " + name + " found.", "Found", 0);
}
NETENG.HandleAttRec h1 = new NETENG.HandleAttRec();//A STRUCT
h1.Handle = 0;
NETENG.IDAttRec id1 = new NETENG.IDAttRec();//A STRUCT
id1.UserID = 100;
id1.LayerKey = 1;
bool boolElement = NE_QueryElementByID(net, NETENG.ElementTypeEnum.NE_EDGE, id1, h1);
MessageBox(0, Convert.ToString(boolElement),"Test", 0);
}catch (Exception ex) {
MessageBox(0, Convert.ToString(ex),"Error", 0);
}
}
}
...when the code passes thru
bool boolElement = NE_QueryElementByID(net, NETENG.ElementTypeEnum.NE_EDGE, id1, h1);
...ive passed proper parameter types and values already but it returns a System.NullReferenceException. WHY?