Re: Problem calling function in DLL via NETLink: NET::netexcptn: A .NET exception occurred
- To: mathgroup at smc.vnet.net
- Subject: [mg66377] Re: Problem calling function in DLL via NETLink: NET::netexcptn: A .NET exception occurred
- From: Heiko Damerau <heiko.damerau.news at web.de>
- Date: Thu, 11 May 2006 02:14:58 -0400 (EDT)
- Organization: CERN - European Laboratory for Particle Physics
- References: <e3sgh9$lph$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Todd, Thanks a lot for your fast reply. I changed the type to "long" now but the problems remain the same. Sometimes, everything works and sometimes I get these "NET::netexcptn" messages. Furthermore, I found that the NET object was not not released after it was not needed anymore. So now I added ReleaseNETObject, but still without success with respect to the errors. To my mind, there seem to be a problem with memory allocation somewhere because there are even error windows from Visual C++ (e.g. 'Assertion failed, Program: ...hematica\5.2\AddOns\NETLink\InstallableNET.exe, File: GIOPServerWorker.cpp, Line: 1018, Expression: false') that pop up occasionally or error windows like 'Cannot access memory address 0x212....'. I did not have similar effects using Mathematica before. I am using version 5.2 of Mathematica for windows. Many thanks in advance for any kind of information to that problem. Best regards, Heiko Todd Gayley schrieb: > At 01:35 AM 5/9/2006, Heiko Damerau wrote: >> Hello, >> >> I am trying to call a function in an ordinary C++ DLL (should be >> well tested, not my code). The DLL function I am calling is declared as >> >> short SyncRPC FAR PASCAL SyncRPC(const char *locName, const char >> *locProperty, const char *locCycle, short ArraySize, void *Data, long >> DataSize, short DataFormat, short DataType) >> >> As I do not need the full flexibility when called from Mathematica, >> it is defined as >> >> DLLFunctionSyncRPC = DefineDLLFunction["SyncRPC", "rpcapi32.dll", >> "short", {"char*", "char*", "char*", "short", "byte[]", "byte", "short", >> "short"}]; >> >> and finally called by >> >> DLLFunctionSyncRPC[elementName, property, plsLine, optArraySize, >> netManagedDataArray, 0, 1, 0]; >> >> where elementName, property, plsLine are Mathematica strings, >> optArraySize is an ordinary mathematica number (integer) and >> netManagedDataArray is a .NET object declared as >> >> NETNew["System.Byte[]", 17optArraySize + 1]; >> >> to get the pointer to the result. Everything works fine but sometimes I >> get strange error messages: >> >> NET::netexcptn: A .NET exception occurred: >> System.NullReferenceException: Object reference not set to an instance >> of an object. at >> Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper612.SyncRPC(String , >> String , String , Int16 , Byte[] , Byte , Int16 , Int16 ) >> >> and my notebook is not executed as it should. Changing nothing and >> just running the Mathematica notebook a second time and the error >> disappears most of the time. The error appears especially, when I call >> the DLL function extremely often; but also with a fresh kernel the error >> normally comes after some 25 calls of the function in the DLL. >> >> It would be great if anyone could give me a hint what is wrong with >> my function calls, because most of the time everything works correctly. > > > Heiko, > > One problem is that the "byte" type (DataSize) in your DefineDLLFunction > should be "long." > > > Todd Gayley > Wolfram Research >