English 中文(简体)
P/Invoke for pointer to array of char
原标题:
  • 时间:2009-11-19 23:10:47
  •  标签:
  • pinvoke

I have a DLL that I need to P/Invoke the following method: DWORD Foo( int a, int *b, char *c );

Per the documentation, parameter c is an out parameter that must be a char array of size 16. A null terminated string is placed into it.

What is the P/Invoke definition for parameter c (I ve got the others fine)? How is the content of c read after the call?

最佳回答

I prefer to use StringBuilder for these things actually. It s far easier to deal with than char arrays or immutable strings. Just make sure you initialize it with enough capacity (16 in this case) for the DLL to fill. Typically it marshalls over just fine, but you may have to set the character set in your DLLImport declaration.

Here is a little more info on this: Marshaling between Managed and Unmanaged Code from MSDN magazine (Stringbuilder section)

问题回答

暂无回答




相关问题
Marshaling Delphi 5 OleVariant to C#

I m trying to use some legacy Delphi 5 DLLs from C# (2.0/3.5). Some of the exported functions are declared as such: function SimpleExport: OleVariant; stdcall; function BiDirectionalExport(X: ...

P/Invoke for pointer to array of char

I have a DLL that I need to P/Invoke the following method: DWORD Foo( int a, int *b, char *c ); Per the documentation, parameter c is an out parameter that must be a ...

How does the .NET Framework Class call Platform API?

We know that .NET framework class encapsulate the Win32 API, now I am wondering how the .NET framework class call Win32 API? Ways I know so far: Through P/Invoke VC++/CLI Both 1 and 2 Anybody ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How should I declare this C struct for interop?

I have to use a legacy C routine in the application I am developing. The code in here works, but I have to convert almost all the fields to char arrays in order to use it. There is a better way to do ...

热门标签