This article is very useful to understand how to call unmanaged function from C#.net. I have to do the same thing for my project but it seems little complex as it is passing user defined data type as an argument to the calling function. I will appreciate help with this.
Unmanaged C++ function which I am trying to call from C#.net app. is as below: (from the header file)
static void LibAction(const libString& actionXML, libString& returnXML, libError& libError);
libSting is a reference to the container class - wraps Standard Teplate Library String type. declared in the header file as below:
class LIBCLASSEXPORT LibString : public std::string
{
typedef std::string STL_STRING;
public:
// --- Constructors/Destructor ---
LibString() { ; }
LibString(const LibString& S);
LibString(const char* s);
LibString(char s);
LibString(istream&);
LibString(const STLSTRING & S) : STLSTRING(S) { ; }
virtual ~LibString();
libError is a reference to the container class which is used for the error handling.
How do I call this function from C# windows application.
Below is how I am trying to declare above function in my C# app.
[DllImport(@"C:\Test\dlls\Lib.dll", EntryPoint="LibAction")]
public static extern void LibAction(string actionXML, string returnXML, string libError);
Instead of string I should be passing ref to the libString. I am not sure how do I do that in C#.
Please help.
Enter your message below
Sign in or Join us (it's free).