Why the call of FormatMessage in PPC Emulator throw NotSupportedException?

D

Dolphin White

I have imported the API FormatMessage from the module coredll.dll, just like
the sample PocketSignature of MSDN. But when I use the method, it throws a
NotSupportedException. I have tested the sample PocketSignature, it has the
same problem. I have no a real Pocket PC device now, so I can only test the
program in the VS 2003’s Pocket 2002 Emulator. But I think the API
FormatMessage is a very basal API, the Emulator should have supported it.
Why it throw the exception?



The list is the snippet of the code:

[DllImport("coredll.dll", CharSet=CharSet.Auto)]

private static extern uint FormatMessage(uint dwFlags, string lpSource, int
dwMessageId, uint dwLanguageId, StringBuilder lpBuffer, int nSize,string []
Arguments);



public static string FormatMessage(int errorCode)

{

StringBuilder sb = new StringBuilder(500);

try

{

// get message for last error

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, null, errorCode, 0,sb,
sb.Capacity, null);

}

catch

{

// error calling FormatMessage

sb.Append("N/A.");

}

return sb.ToString();

}



Thanks!



Dolphin
 
D

Dolphin White

Very thanks!!

Alex Feinman said:
PInvoke in CF does not support passing arguments of complex types, such as
string[]. If you are not using that parameter, declare it as int or IntPtr.
For an example take a look at the source code of OpenNETCF.WinAPI at
www.opennetcf.org

Dolphin White said:
I have imported the API FormatMessage from the module coredll.dll, just like
the sample PocketSignature of MSDN. But when I use the method, it throws a
NotSupportedException. I have tested the sample PocketSignature, it has the
same problem. I have no a real Pocket PC device now, so I can only test the
program in the VS 2003's Pocket 2002 Emulator. But I think the API
FormatMessage is a very basal API, the Emulator should have supported it.
Why it throw the exception?



The list is the snippet of the code:

[DllImport("coredll.dll", CharSet=CharSet.Auto)]

private static extern uint FormatMessage(uint dwFlags, string lpSource, int
dwMessageId, uint dwLanguageId, StringBuilder lpBuffer, int nSize,string []
Arguments);



public static string FormatMessage(int errorCode)

{

StringBuilder sb = new StringBuilder(500);

try

{

// get message for last error

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, null, errorCode, 0,sb,
sb.Capacity, null);

}

catch

{

// error calling FormatMessage

sb.Append("N/A.");

}

return sb.ToString();

}



Thanks!



Dolphin
 

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