Link to home
Start Free TrialLog in
Avatar of camster123
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.
Avatar of Karrtik Iyer
Karrtik Iyer
Flag of India image

what is the string s that you are passing as input to this function?
Avatar of camster123
camster123

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.
ASKER CERTIFIED SOLUTION
Avatar of Karrtik Iyer
Karrtik Iyer
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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