How to use an unmanaged DLL in the Microsoft Bot Framework?

Asked

Viewed 79 times

0

I want to make a bot for facebook using Microsoft’s 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. Which may 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);
  • It would be quite useful to include the stacktrace of the exception...

  • By the way, you can try the Rivescript, that has an interpreter made in C#

1 answer

0

Hello, try switching the signature of the:

[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 regarding the use of string in passing parameters when using DLL. I had a similar problem and fixed it this way. Also, when I need to handle some argument I use pointers, so type Intptr.

Remember that in relation to string there are other types that you can use instead of Ansibstr. This I used in a DLL made in Delphi, It may be that for 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 generally used.

Good luck!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.