[Closed] dotNet – OLE starts and stops right away
OK, this is a somewhat complicated setup, please bear with me:
I have a C# library (taken from http://sourceforge.net/projects/dotmat/ ) that calls a 3rd party math app (Matlab) through OLE. Whenever I try to do that with 3ds Max 2012, the OLE instance starts without errors but also stops right away. Doing the same thing in a standalone C# project works fine… and now I have run out of ideas how to get this working.
Here are a few more details:
The C# code that links to the 3rd party API is
public class MATInvoke
{
#region Engine Functions
[DllImport("libeng.dll")]
internal static extern IntPtr engOpen(string startcmd);
// ...
}
and the code to call this within the dotNet class is
public class EngMATAccess: IDisposable
{
public EngMATAccess() : this(4096)
{
}
public EngMATAccess(int buffersize)
{
engine = MATInvoke.engOpen(null);
buffer = IntPtr.Zero;
resultBuffer = false;
BufferSize = buffersize;
BufferingActive = true;
}
// ...
}
which I compile with Visual Studio 2010 into EngMATLib.dll for use in 3ds Max.
Now, within 3ds Max, I call this…
dotnet.loadassembly @"D:\EngMATLib\bin\x64\Release\EngMATLib.dll"
ml = dotnetobject "EngMATLib.EngMATAccess"
… which causes the MATInvoke.engOpen(null) function to be called, which then starts the OLE application but it exits immediately again, returning a NULL pointer.
When I try the same thing using C#
private void Form1_Load(object sender, System.EventArgs e)
{
mat = new EngMATAccess(4096);
}
things work just fine! I get a proper pointer, the OLE object is up and running and can be used just fine.
ANY ideas or suggestions what I could do to get this working would be HIGHLY appreciated!
Thanks
– MartinB
Is it the same result if you call it like this?
assembly = dotnet.loadassembly @"D:\EngMATLib\bin\x64\Release\EngMATLib.dll"
ml = assembly.createInstance "EngMATLib.EngMATAccess"
Sorry, that’s all I had
Maybe try to move the initialization out of the constructor and into an .Initialize() method
I think I found it (after a day of poking around…)!
It seems both applications (3ds Max and the OLE component) make use of the same dll (tbb.dll and tbbmalloc.dll) but use different versions! Calling the OLE from 3ds Max also inserted the search path to the 3ds Max folder and thus caused the older version of the DLL to be loaded, which then caused the OLE to quit but not to crash (for some reason)
I’ll dig some more, but that seems to be turning point.
Now the question is: Should I replace the 3ds Max dll’s with the newer versions, or should I try to fix the path (and if so, how)?
– MartinB