NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Authoring Styles for PInvoke

There are two general approaches you can adopt when declaring methods that match unmanaged functions:

  1. The first approach is used when the developer wants to call a method in an unmanaged DLL from his code. So, the developer declares that method (but doesn't supply an implementation for it) in such a way that the compiler will be able to put the information into metadata that the runtime needs to locate and correctly marshal the call to the DLL. This declaration includes, among other things, substituting types that the runtime understands for the method's types. The developer can call these methods from his code as if they were NGWS runtime methods.
  2. The second approach entails writing an NGWS class that is just a collection of declarations (like the one described above) for an API exported by an unmanaged DLL. A developer could provide this class for her own use, or she could use a class provided by another party. The developer that uses this type of class has the advantage of not having to declare and annotate the methods for the unmanaged DLL that she wants to call. All the developer has to do is call them as if they were regular NGWS runtime methods.

In both cases, the code that invokes such an annotated method need not be aware of the underlying implementation. The annotated method looks and behaves like a managed NGWS runtime method, but when the Execution Engine encounters the method, Platform Invocation Services makes the transition from managed to unmanaged code and invokes the unmanaged method.