BSTR to c# string
-
Hi, I have a COM application that sends out _bstr_t to a .NET interop. The strings that I get for ASCII characters are fine in .NET,but I get junk values for unicode characters. Do I need to make any modifications to the string that I get in .NET to display peoper characters? Thanks in advance, Ashish Iddya
-
Hi, I have a COM application that sends out _bstr_t to a .NET interop. The strings that I get for ASCII characters are fine in .NET,but I get junk values for unicode characters. Do I need to make any modifications to the string that I get in .NET to display peoper characters? Thanks in advance, Ashish Iddya
have u changed the project settings to UNICODE in ur COM application???If not then try to change the settings in the preprocessor defition and Project options to Unicode.
-
have u changed the project settings to UNICODE in ur COM application???If not then try to change the settings in the preprocessor defition and Project options to Unicode.
Yup, have done that. The COM application seems to pass the characters correctly. I tried returning the unicode string back to COM from .NET, & it returned the correct string. .NET seems to handle the string differently, if I pass 5 unicode characters, I get 10 characters(all junk but there are 5 commas in them). Any ideas??!?
-
Hi, I have a COM application that sends out _bstr_t to a .NET interop. The strings that I get for ASCII characters are fine in .NET,but I get junk values for unicode characters. Do I need to make any modifications to the string that I get in .NET to display peoper characters? Thanks in advance, Ashish Iddya
You have to decorate these strings in your .net interop interface/class/struct with a MarshalAs(UnmanagedType.BStr) attribute.
-
You have to decorate these strings in your .net interop interface/class/struct with a MarshalAs(UnmanagedType.BStr) attribute.
Tried adding MarshalAs attribute. It didnt make any difference. Here is the code I am using.. public bool CreateFile([MarshalAs(UnmanagedType.BStr)]string file,string app) { FileStream fileStream = new FileStream(file,FileMode.OpenOrCreate); /* write some stuff in the file here*/ } Unfortunately, it is not creating a proper filename if the string is unicode. The above function works correctly if I execute it directly from .NET(without MarshalAs attribut) Any suggestion is welcome..This has me stumped for over a week now. Thanks Ashish Iddya