Changing charset of runtime so that kernel pinvoke resolved to unicode versions

Hi, I was experimenting with the File IO methods, and seem to notice that the .NET, by default, uses the non-unicode pinvokes of many of the win32 file io rountines. Is there any way to invoke the unicode version without writing my own pinvokes/dllimport


Answer this question

Changing charset of runtime so that kernel pinvoke resolved to unicode versions

  • Hiral Soni

    Both CreateDirectory and CopyFile. First, I was hoping by prepending "\\*\"  (in c# i'm using @"\\*\") it would automatically invoke the unicode version. But instead I got a illegal characters exception.

    So I removed those, but instead got a path too long exception (
    The specified path, file name, or both are too long. The fully qualified file na
    me must be less than 260 characters, and the directory name must be less than 24
    8 characters.)

    I was testing with this path
    D:\a\abcdefghijklmnopqrstuvwxyz0123456789\abcdefghijklmnopqrstuvwxyz0123456789\abcdefghijklmnopqrstuvwxyz0123456789\abcdefghijklmnopqrstuvwxyz0123456789\abcdefghijklmnopqrstuvwxyz0123456789\abcdefghijklmnopqrstuvwxyz0123456789\abcdefghijklmnopqrst

    And in the last folder itself, I got two empty text files, hello.txt, and text file named with a random chinese word I copied off the internet.

    Of course, the exception stack trace was, for the path too long,
       at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, DirectorySecurity dirSecurity)
       at System.IO.Directory.CreateDirectory(String path, DirectorySecurity directorySecurity)

    and for the illegal characters,
       at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
       at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
       at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
       at System.IO.Directory.CreateDirectory(String path, DirectorySecurity directorySecurity)

    Unless this is a limitation imposed by the .Net framework itself, and if it is, how does one work around it
     

  • Doug K

    Which file IO methods and which Win32 APIs are these What makes you think that the A version is called (assuming you're running on an NT system)



  • Unjedai

    >Unless this is a limitation imposed by the .Net framework itself

    Yes it is.


    >how does one work around it

    Call the underlying Win32 APIs directly.




  • Changing charset of runtime so that kernel pinvoke resolved to unicode versions