C# LexActivator.dll path

Hi,

I’m trying to integrate the lexactivator.cs filein my C# project. This works great when I test it in visual studio. Eventually my C# project will be part of a project in 3dsMax (3d modeling software which implements .net) which in turn uses these libraries to perform tasks. Due to the way 3dsMax reads the c# libraries I’m unable to use hardcoded or relative filepaths to locate libraries. I need to specify the full filepath to the libraries.

This is an issue with the LexActivator class I need to include as it contains two path to dll’s: LexActivator.dll and LexActivator64.dll. These paths are constants, which means I can’t change them at runtime. If I turn them into static values I get a bunch of errors because these paths are used in attributes, which only accept constants. I’m at a loss how to proceed. Are you able to help me modify your library in such a way that I can specify the paths to the two dll’s at runtime for instance in a constructor?

You only need to ensure that dll is in the same folder as your final exe file and it should work without any issue.

That’s the first thing I tried but it didn’t work. I know this is due to the way 3dsMax loads these assemblies into memory and this is out of your control. But if there’s a way to declare these filepaths at run time instead of compile time I can work around it. But I’m afraid my C# skills are not there yet to mess around with the constants and dllimport statements.

The following posts has a solution for your problem:

In the static class Native just add the following function

static class Native
{
[DllImport(“kernel32.dll”, CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDllDirectory(string dllPath);

        [DllImport(DLL_FILE_NAME, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int SetProductFile(string filePath);
       ....

Then use Native.SetDllDirectory() to dynamically load the dll file before calling any LexActivator API function

Awesome! This works splendidly. Thank you very much!