> Thanks Daniel,
>
[quoted text clipped - 8 lines]
>
> Or did I confuse something else?
You need to understand what the error message is telling you: You can't
call unmanaged functions, except via P/Invoke, in a "pure" or "safe" CLR
project. You have two choice:
1. Don't use /clr:pure or /clr:safe, just use /clr
2. Don't #include <windows.h> and go back to using DllImportAttribute one
import at a time.
If you take option 1, the resulting application will contain a mixture of
managed and unmanaged code and may not run in certain contexts (e.g. partial
trust environment). Winforms will work fine in a mixed-mode application -
it's entirely a function of the environment in which the application is
deployed whether this option will work for you.
If you take option 2, you're stuck with declaring the functions you need one
by one.
-cd
Ben Voigt - 07 May 2007 15:07 GMT
>> Thanks Daniel,
>>
[quoted text clipped - 25 lines]
> If you take option 2, you're stuck with declaring the functions you need
> one by one.
And still won't work in partial trust... because you need native code
permission to use P/Invoke. However you'll get a runtime exception instead
of an outright failure to load.
Best of both worlds... put such calls in a separate unsafe assembly, then
you can still fail gracefully if you don't have native code permission.
> -cd