Unmanaged TYpes in API

  • Thread starter Thread starter Howard Kaikow
  • Start date Start date
H

Howard Kaikow

The FormatMessage API is specified as:

DWORD FormatMessage(
DWORD dwFlags,
LPCVOID lpSource,
DWORD dwMessageId,
DWORD dwLanguageId,
LPTSTR lpBuffer,
DWORD nSize,
va_list* Arguments)

I am trying to convert this to C#. So far I've got:

[System.Runtime.InteropServices.DllImport("kernel32",
EntryPoint="FormatMessage", ExactSpelling=false,
CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern uint FormatMessage (
uint dwFlags,
lpcvoid lpSource,
uint dwMessageId, uint dwLanguageId,
[MarshalAs(UnmanagedType.LPTStr)]string lpBuffer,
uint nSize,
va_list* Arguments);

Did I do LPTSTR correctly?
What do I need to do for LPCVOID and va_list*?
 
Howard Kaikow said:
The FormatMessage API is specified as:

DWORD FormatMessage(
DWORD dwFlags,
LPCVOID lpSource,
DWORD dwMessageId,
DWORD dwLanguageId,
LPTSTR lpBuffer,
DWORD nSize,
va_list* Arguments)

I am trying to convert this to C#. So far I've got:

[System.Runtime.InteropServices.DllImport("kernel32",
EntryPoint="FormatMessage", ExactSpelling=false,
CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern uint FormatMessage (
uint dwFlags,
lpcvoid lpSource,
uint dwMessageId, uint dwLanguageId,
[MarshalAs(UnmanagedType.LPTStr)]string lpBuffer,
uint nSize,
va_list* Arguments);

Did I do LPTSTR correctly?
What do I need to do for LPCVOID and va_list*?
Try this...
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern int FormatMessage
(int dwFlags,
IntPtr lpSource,
int dwMessageId,
int dwLanguageId,
StringBuilder lpBuffer,
int nSize,
IntPtr va_list_arguments);

Willy.
 
Thanx, I'll give it a try.

--
http://www.standards.com/; See Howard Kaikow's web site.
Willy Denoyette said:
Howard Kaikow said:
The FormatMessage API is specified as:

DWORD FormatMessage(
DWORD dwFlags,
LPCVOID lpSource,
DWORD dwMessageId,
DWORD dwLanguageId,
LPTSTR lpBuffer,
DWORD nSize,
va_list* Arguments)

I am trying to convert this to C#. So far I've got:

[System.Runtime.InteropServices.DllImport("kernel32",
EntryPoint="FormatMessage", ExactSpelling=false,
CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern uint FormatMessage (
uint dwFlags,
lpcvoid lpSource,
uint dwMessageId, uint dwLanguageId,
[MarshalAs(UnmanagedType.LPTStr)]string lpBuffer,
uint nSize,
va_list* Arguments);

Did I do LPTSTR correctly?
What do I need to do for LPCVOID and va_list*?
Try this...
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern int FormatMessage
(int dwFlags,
IntPtr lpSource,
int dwMessageId,
int dwLanguageId,
StringBuilder lpBuffer,
int nSize,
IntPtr va_list_arguments);

Willy.
 
Back
Top