6

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?

YSC
  • 38,212
  • 9
  • 96
  • 149
xaria
  • 842
  • 5
  • 24
  • 47

1 Answers1

13

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);
shf301
  • 31,086
  • 2
  • 52
  • 86
Nitin Sawant
  • 7,278
  • 9
  • 52
  • 98