Skip to content

Instantly share code, notes, and snippets.

@mavnn
Created August 8, 2013 13:20
Show Gist options
  • Select an option

  • Save mavnn/6184518 to your computer and use it in GitHub Desktop.

Select an option

Save mavnn/6184518 to your computer and use it in GitHub Desktop.
Add a dll directory from which to DllImport native code.
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
@mavnn
Copy link
Copy Markdown
Author

mavnn commented Aug 8, 2013

Code is being run on a Windows 8 machine, btw. I'm aware you need to apply a patch to use this api call on earlier versions of Windows.

@mavnn
Copy link
Copy Markdown
Author

mavnn commented Aug 8, 2013

Mystery solved here for those who are interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment