Unmanaged TYpes in API

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*?
 
W

Willy Denoyette [MVP]

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.
 
H

Howard Kaikow

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top