473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Unmanaged TYpes in API

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.Ans i, 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*?
Nov 17 '05 #1
2 3582

"Howard Kaikow" <ka****@standards.com> wrote in message
news:Ob**************@TK2MSFTNGP09.phx.gbl...
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.Ans i, 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.

Nov 17 '05 #2
Thanx, I'll give it a try.

--
http://www.standards.com/; See Howard Kaikow's web site.
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:Ob**************@tk2msftngp13.phx.gbl...

"Howard Kaikow" <ka****@standards.com> wrote in message
news:Ob**************@TK2MSFTNGP09.phx.gbl...
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.Ans i, 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.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fedor Buyakov | last post by:
hello all i have a specific question according hiding unmanaged (native) types in metadata for assemblies generated by c++ with managed extensions. i understand what these types are nedeed in...
2
by: Paul Kenny | last post by:
Hi, I am trying to expose the functionality of an unmanaged C++ class to the other languages available in the .NET Framework. I have decided to do this by wrapping the unmanaged C++ class in a...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
2
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking afterwards with ILDASM at what is visible in those assemblies from a...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
4
by: William F. Kinsley | last post by:
My understanding is that when I re-compile a existing MFC application with the /clr switch, that the code generated is managed(with some exceptions) but that the data isn't, i.e. not garbage...
5
by: R. MacDonald | last post by:
Hello, all, I am currently working on a .Net (VB) application that invokes routines in unmanaged (Fortran) DLLs. The unmanaged routines then communicate with the .Net application by means of a...
3
by: Pixel.to.life | last post by:
Hi, Gurus, I recently attempted to build a .Net forms application, that links with old style unmanaged C++ static libs. Of course I had to recompile the static lib projects to link properly...
2
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.