P
PLS
I'm having problem calling the Win32 function GlobalGetAtomName from C#.
I'm getting a debugger popup telling me that the called function has
unbalanced the stack.
I'm hoping someone here can see what I'm doing wrong.
Here is the function declaration, in a class call DDEFunctions:
[DllImport("kernel32.dll", SetLastError=true,
CharSet=CharSet.Unicode,
CallingConvention = CallingConvention.StdCall,
EntryPoint = "GlobalGetAtomNameW")]
public static extern int GlobalGetAtomName(ushort nAtom,
out String lpBuffer, int nSize);
And here is the code that calls it
public static String GetAtomString(ushort Atom)
{
if (Atom == 0)
return null;
int BufferLen;
String Buffer;
BufferLen = 514;
Buffer = new String('\0', BufferLen);
BufferLen = DDEFunctions.GlobalGetAtomName
( Atom, out Buffer, BufferLen);
if (BufferLen == 0)
{
System.Diagnostics.Trace.WriteLine("GetAtomString failed
with DLL error number " + Marshal.GetLastWin32Error().ToString());
return null;
}
else
{
Buffer = Buffer.Substring(1, BufferLen);
return Buffer;
}
}
Does anyone see the problem?
Thanks very much,
++PLS
I'm getting a debugger popup telling me that the called function has
unbalanced the stack.
I'm hoping someone here can see what I'm doing wrong.
Here is the function declaration, in a class call DDEFunctions:
[DllImport("kernel32.dll", SetLastError=true,
CharSet=CharSet.Unicode,
CallingConvention = CallingConvention.StdCall,
EntryPoint = "GlobalGetAtomNameW")]
public static extern int GlobalGetAtomName(ushort nAtom,
out String lpBuffer, int nSize);
And here is the code that calls it
public static String GetAtomString(ushort Atom)
{
if (Atom == 0)
return null;
int BufferLen;
String Buffer;
BufferLen = 514;
Buffer = new String('\0', BufferLen);
BufferLen = DDEFunctions.GlobalGetAtomName
( Atom, out Buffer, BufferLen);
if (BufferLen == 0)
{
System.Diagnostics.Trace.WriteLine("GetAtomString failed
with DLL error number " + Marshal.GetLastWin32Error().ToString());
return null;
}
else
{
Buffer = Buffer.Substring(1, BufferLen);
return Buffer;
}
}
Does anyone see the problem?
Thanks very much,
++PLS