xaria
xaria

Reputation: 842

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

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?

Upvotes: 6

Views: 8894

Answers (1)

Nitin S
Nitin S

Reputation: 7591

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);

Upvotes: 13

Related Questions