Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
¿Es posible forzar a .NET a usar la versión Unicode del método P/Invoke en su propio código?

Por ejemplo, si llamo al método System.IO.Directory.CreateDirectory , dentro del código .NET se llama al método Win32 API CreateDirectory de kernel32.dll.

En el código fuente de .NET, el método se declara de la siguiente manera:

 [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false)] internal static extern bool CreateDirectory( string path, Win32Native.SECURITY_ATTRIBUTES lpSecurityAttributes);

CharSet está establecido en CharSet.Auto. Parece que siempre se llama la versión Ansi.

Mi pregunta es si puedo obligar a .NET a usar la versión Unicode en lugar de la versión Ansi.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Parece que siempre se llama la versión Ansi.

¿Cómo sabes esto? ¿Está utilizando .NET core en Linux o algo así? https://docs.microsoft.com/en-us/dotnet/standard/native-interop/charset

En cualquier caso, en lugar de esto:

 [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false)]

Este:

 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]

Alternativamente, todas las API de Win32 son realmente macros que se asignan a una versión con sufijo A de una versión con sufijo W para ANSI y WIDE (unicode) respectivamente.

Así que llamar a CreateDirectoryW directamente debería funcionar:

 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)] internal static extern bool CreateDirectoryW( string path, Win32Native.SECURITY_ATTRIBUTES lpSecurityAttributes);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!