hey all

 I am trying to marshal strings from managed code to native code using
DllImport. Marshalling both wchar_t* and char* works under mono on a windows
box. 

But on mac os x wchart_t marshalling does not seem to work. The wchar_t* is
all junk. I have tried to search this forum and people have talked about it
and it seems to have been fixed.

Am I missing something ? I have experimented with CharSet.Unicode on
DllImport and it still doesnt work ?

What is the recommended way ?

Thanks
Raj



My cs files is something like this
____________________________________________
[DllImport("Test.dll", EntryPoint = "Global_PrintStringW")]
 public static extern void Global_PrintStringW(
[MarshalAs(UnmanagedType.LPWStr)]string arg1);

[DllImport("Test.dll", EntryPoint = "Global_PrintStringA")]
 public static extern void Global_PrintStringA(string arg1);


        private static void StringMarshallingTest()
        {
           
            string newString = "This is a cool string";

            Console.WriteLine("Global_PrintStringA Test ");
            Global_PrintStringA(newString);

            Console.WriteLine("Global_PrintStringW Test ");
            Global_PrintStringW(newString);
     
        }

My cpp file is something like this
________________________________

extern "C"
{
        EXPORT_API void Global_PrintStringW(const wchar_t * str)
        {
                std::wcout << "Global_PrintStringW called with " << str << 
std::endl;
        }

        EXPORT_API void Global_PrintStringA(const char* str)
        {
                std::wcout << "Global_PrintStringA called with " << str << 
std::endl;
        }
}



-- 
View this message in context: 
http://www.nabble.com/What-is-Correct-way-to-marshal-wchar_t---tp23855173p23855173.html
Sent from the Mono - General mailing list archive at Nabble.com.

_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to