Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call from a C# applicaiton a C++ function taking a pointer to void?

Tags:

c#

char

dllimport

I have a dynamic library (.dll) written in C++ exporting a function I'd like to use in my C# applicaiton:

int SendText(void* pControl, char* sText);

How can I, given it takes a pointer to void?

like image 972
xaria Avatar asked May 17 '12 05:05

xaria


People also ask

How do you call a function?

You call the function by typing its name and putting a value in parentheses. This value is sent to the function's parameter. e.g. We call the function firstFunction(“string as it's shown.”);


1 Answers

for void* you can just use IntPtr ,
strings will work with the MarshalAs attribute:

[DllImport("MyDll.dll", CharSet = CharSet.Ansi)]
public static extern int SendText(IntPtr pControl, [MarshalAs(UnmanagedType.LPStr)] string sText);
like image 145
Nitin S Avatar answered Oct 01 '22 01:10

Nitin S