[quoted text, click to view] On Wed, 29 Sep 2004 12:08:44 +0200, Robert Jordan <robertj@gmx.net> wrote:
>Chuck Heatherly wrote:
>> On Wed, 29 Sep 2004 03:16:06 GMT, v-phuang@online.microsoft.com ("Peter Huang")
>> wrote:
>>
>>
>>>Hi Chuck,
>>>
>>>I agree with Rob's suggestion. We can use CharSet.Auto.
>>>CharSet.Auto
>>>Platform invoke chooses between ANSI and Unicode formats at run time, based
>>>on the target platform.
>>>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
>>>l/cpconcharsetobjectfield.asp
>>>
>>>Auto
>>>Supported by the .NET Compact Framework.
>>>Automatically marshal strings appropriately for the target operating
>>>system. The default is Unicode on Windows NT, Windows 2000, Windows XP, and
>>>the Windows Server 2003 family; the default is Ansi on Windows 98 and
>>>Windows Me.
>>>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
>>>frlrfsystemruntimeinteropservicescharsetclasstopic.asp
>>
>>
>> I don't understand how this answers my question though. I want to know how to
>> tell elsewhere in my code whether the ANSI or Unicode version of the function
>> was chosen.
>
>You can query Marshal.SystemDefaultCharSize. When it's 2,
>then the Unicode functions will be called, unless you
>overrode the P/Invoke DllImport declaration with CharSet.Ansi.
Rob, thanks for responding. I did see this field in MSDN, but it seems that
it's based on whether the operating system supports Unicode or not.
In my case with ODBC drivers, I think you can have a Unicode system with an ODBC
driver that only supports ANSI. For example, the MySQL ODBC Driver version 3.51
does not support Unicode, so the ANSI versions of the ODBC functions are called.
But Marshal.SystemDefaultCharSize returns 2 on that system.
Again, if there's no other way to determine what I'm looking for, I guess I can
just use the ExactSpelling attribute and trap for the EntryPointNotFound
exception.