Tại sao mã sau không hoạt động?Tại sao cuộc gọi này đến AddDllDirectory thất bại với "Tham số không chính xác"?
open System
open System.Runtime.InteropServices
open System.ComponentModel
[<DllImport("kernel32")>]
extern int AddDllDirectory(string NewDirectory)
[<EntryPoint>]
let main argv =
let result = AddDllDirectory("c:\\")
if result = 0 then
printfn "%A" <| Win32Exception(Marshal.GetLastWin32Error())
// Prints: "System.ComponentModel.Win32Exception (0x80004005): The parameter is incorrect"
System.Console.ReadLine() |> ignore
0 // return an integer exit code
Ah, đó là lý do tại sao tôi cần chỉ định loại chuỗi không được quản lý nếu tôi không đặt CharSet? Nó thậm chí mơ hồ bắt đầu có ý nghĩa. Có nói rằng, tôi nghĩ Unicode là mặc định? – mavnn
Không, ANSI là mặc định (http://msdn.microsoft.com/en-us/library/7b93s42f.aspx), điều này thật kỳ lạ vì bạn chỉ sử dụng nó ở nơi bạn hoàn toàn phải (ví dụ: GetProcAddress). –