Managed Callback from WinAPI: Problem with unicode string
------------------------------------------------
Help, how do you post code on this forum?
------------------------------------------------
Im calling a native WinAPI method with a callback function that is implemented in C#. The callback works but the unicode strings passed to the callback are not properly converted. If i print them i only get the first letter of the string.
I have had the same problem on the C side when accidently treating a unicode string as an ANSI one.
The relevant snippet of code is shown below:
(details of the EnumPwrSchemes function can be found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/enumpwrschemes.asp)
[DllImport("PowrProf.dll")]
private static extern bool EnumPwrSchemes(callback_delegate lpfnPwrSchemesEnumProc, uint LPARAM);
private delegate bool callback_delegate(uint uiIndex, UInt32 dwName, String sName, UInt32 dwDesc, String sDesc, uint pp, uint lParam);
private bool callback(uint uiIndex, UInt32 dwName, String sName, UInt32 dwDesc, String sDesc, uint pp, uint lParam)
{
Console.WriteLine(dwName + " , " + sName + " : " + sDesc);