In the .Net Framework 4.0 some security changes have been made which will cause issues with legacy PInvoke's to the Windows API's in library files. I'm going to link to some blog posts of others that go into this in more detail but I'm going to share the fix that they provided. There are two options. The first is to set a flag that tells the assembly to run in legacy mode. The second (the one I choose) is to mark the methods with the [SecuritySafeCritial] flag.
<configuration> <runtime> <netfx40_legacysecuritypolicy enabled="true" /> </runtime> </configuration>