camster123
asked on
C# .NET marshaling on Ubuntu Linux 14.04
Would anyone know why the following C# marshaiing code might return an erroneous return value?
var insertCommand = "INSERT INTO message ( text ) VALUES (\"HelloWorld\")";
public static IntPtr StringToHGlobalUTF8(string s, out int length)
{
if (s == null)
{
length = 0;
return IntPtr.Zero;
}
var bytes = Encoding.UTF8.GetBytes(s);
var ptr = Marshal.AllocHGlobal(bytes .Length + 1);
Marshal.Copy(bytes, 0, ptr, bytes.Length);
Marshal.WriteByte(ptr, bytes.Length, 0);
length = bytes.Length;
return ptr;
}
any help is greatly appreciated.
var insertCommand = "INSERT INTO message ( text ) VALUES (\"HelloWorld\")";
public static IntPtr StringToHGlobalUTF8(string
{
if (s == null)
{
length = 0;
return IntPtr.Zero;
}
var bytes = Encoding.UTF8.GetBytes(s);
var ptr = Marshal.AllocHGlobal(bytes
Marshal.Copy(bytes, 0, ptr, bytes.Length);
Marshal.WriteByte(ptr, bytes.Length, 0);
length = bytes.Length;
return ptr;
}
any help is greatly appreciated.
what is the string s that you are passing as input to this function?
ASKER
Karrtik Iyer, The strings s that i am passing as input to this function is: "INSERT INTO message ( text ) VALUES (\"HelloWorld\")";
Thank you for your help.
Thank you for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Karrtik Iyer, Your solution helped me enormously in getting my runtime environment correct.
I'm glad it helped, if you want I can share my VM image of my fedora os with mono develop installed given that I get a link from you to upload that amount of data.
Feel free to ask if you have any more questions.
Thanks,
Karrtik
Feel free to ask if you have any more questions.
Thanks,
Karrtik