diff --git a/dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs b/dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs index 16d79a564..4bb653bbb 100644 --- a/dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs +++ b/dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs @@ -1175,6 +1175,9 @@ public List GetDataDirectoryFC(string dataReference) private static List WrapNativeLogQueryResult(IntPtr linkedList) { + if (linkedList == IntPtr.Zero) + return null; + List journalEntries = new List(); IntPtr element = LinkedList_getNext(linkedList); @@ -2238,22 +2241,27 @@ private void nativeGetDataSetDirectoryHandler(UInt32 invokeId, IntPtr parameter, GetDataSetDirectoryHandler handler = callbackInfo.Item1; object handlerParameter = callbackInfo.Item2; - IntPtr element = LinkedList_getNext(dataSetDirectory); - handle.Free(); - List newList = new List(); + List newList = null; - while (element != IntPtr.Zero) + if (dataSetDirectory != IntPtr.Zero) { - string dataObject = Marshal.PtrToStringAnsi(LinkedList_getData(element)); + newList = new List(); - newList.Add(dataObject); + IntPtr element = LinkedList_getNext(dataSetDirectory); - element = LinkedList_getNext(element); - } + while (element != IntPtr.Zero) + { + string dataObject = Marshal.PtrToStringAnsi(LinkedList_getData(element)); - LinkedList_destroy(dataSetDirectory); + newList.Add(dataObject); + + element = LinkedList_getNext(element); + } + + LinkedList_destroy(dataSetDirectory); + } handler.Invoke(invokeId, handlerParameter, (IedClientError)err, newList, isDeletable); } @@ -2428,11 +2436,9 @@ private void nativeReadDataSetHandler(UInt32 invokeId, IntPtr parameter, int err dataSet = new DataSet(nativeDataSet); } - handler(invokeId, handlerParameter, clientError, dataSet); } - public delegate void ReadDataSetHandler(UInt32 invokeId,object parameter,IedClientError err,DataSet dataSet); /// @@ -2566,7 +2572,6 @@ private void nativeGetNameListHandler(UInt32 invokeId, IntPtr parameter, int err { handler(invokeId, handlerParameter, clientError, null, moreFollows); } - } /// @@ -2632,7 +2637,6 @@ public UInt32 GetLogicalDeviceDataSetsAsync(string ldName, string continueAfter, return GetLogicalDeviceDataSetsAsync(null, ldName, continueAfter, handler, parameter); } - public UInt32 GetLogicalDeviceDataSetsAsync(List result, string ldName, string continueAfter, GetNameListHandler handler, object parameter) { int error;