- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm having a problem with ippGetStatusString in Vista 64 using VS2008
My code looks like
[
DllImport("ippcoreem64t-5.3.dll", CharSet=CharSet.Ansi)][return: MarshalAs(UnmanagedType.LPStr)]
private static extern string ippGetStatusString( Int32 status);
When I call it
string errorString = ippGetStatusString(33);
The result a crash where the stack unwinds. A try around this code has NO effect.
However if I access the return value via an IntPtr, it all works. Does anyone have anyidea what I am doing wrong? I don't know if my mistake is the marshaling or the ippGetStatusString itself.
Thanks
Working code.
[
DllImport("ippcoreem64t-5.3.dll", CharSet=CharSet.Ansi)] private static extern IntPtr ippGetStatusString( Int32 status);
and access the string by
IntPtr resultPointer = ippGetStatusString(status);
// Search for the null character, find the size and marshal over
int i = 0;
while (true)
{
// Check for the null termination
if (Marshal.ReadByte(resultPointer, i) == 0)
{
Byte[] ba = new Byte;
Marshal.Copy(resultPointer, ba, 0, ba.Length);
return System.Text.ASCIIEncoding.ASCII.GetString(ba);
}
// No, go again
i = i + 1;
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In IPP C# sample we do use code like this:
[DllImport("ippcore-5.3.dll")]
public static extern string ippGetStatusString(IppStatus StsCode);
string s = ippGetStatusString(33);
It is also possible to do marshalling by yourself but in a little bit simplier way
[DllImport("ippcore-5.3.dll")]
public static extern sbyte* ippGetStatusString(IppStatus StsCode);
string s = new string(ippGetStatusString(33));
Regards,
Vladimir
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page