How to use an unmanaged DLL in Microsoft Bot Framework?

0

I want to make a bot for facebook using the Microsoft Bot Framework (C #) and also use a tool called ChatScript, which is written in C ++.

I turned chatscript into a DLL and called it in a console application in C #, which worked.

When I try to do the same thing in a bot framework project, I get System.StackOverflow when I call the DLL. What can it be?

Note: chatscript.dll is inside the bin folder along with the Application.dll bot generated by the project.

public static int InitSystem(int argc, SWIGTYPE_p_p_char argv, string unchangedPath, string readonlyPath, string writablePath) {
int ret = ChatScriptPINVOKE.InitSystem__SWIG_0(argc, SWIGTYPE_p_p_char.getCPtr(argv), unchangedPath, readonlyPath, writablePath);
return ret;  }

[global::System.Runtime.InteropServices.DllImport("chatscript.dll", EntryPoint="CSharp_ChatScript_InitSystem__SWIG_0")]
public static extern int InitSystem__SWIG_0(int jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, string jarg3, string jarg4, string jarg5);
    
asked by anonymous 06.11.2016 / 22:13

1 answer

0

Hello, try switching the method signature from:

[global::System.Runtime.InteropServices.DllImport("chatscript.dll", EntryPoint="CSharp_ChatScript_InitSystem__SWIG_0")]
public static extern int InitSystem__SWIG_0(int jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, string jarg3, string jarg4, string jarg5);

To:

[global::System.Runtime.InteropServices.DllImport("chatscript.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint="CSharp_ChatScript_InitSystem__SWIG_0")]
public static extern int InitSystem__SWIG_0(int jarg1, IntPtr jarg2, [MarshalAs(UnmanagedType.AnsiBStr)] string jarg3, [MarshalAs(UnmanagedType.AnsiBStr)] string jarg4, [MarshalAs(UnmanagedType.AnsiBStr)] string jarg5);

There are some problems with using string in passing parameters when using DLL. I had a similar problem and corrected it that way. Also, when I need to handle some argument I use pointers, so the IntPtr type.

Remembering that there are other types of string that you can use instead of AnsiBStr. This one I used in a DLL made in Delphi, it might be that you need another type.

Something else that may be missing is the CallingConvention that in the case of DLLs built in C / C ++, Cdecl type is usually used.

Good luck!

    
24.01.2017 / 18:56