COMMUNICATING FROM NATIVE TO MANAGED CODE
The .NET Compact Framework provided with Windows Embedded Compact 7 offers several techniques to call managed code from native code. If you compare with the desktop .NET Framework, some techniques are missing, some are the same, and you can even find one which is unique to the Compact Framework.
The structural difference between native and managed environments creates a huge difference when you have to make a direct call to a function inside the other. Native code Dynamic Link Libraries were introduced in the early days of Windows 1.0 to 3.0 to save memory; the library code was not included in the executable; and several programs shared the whole content of a DLL at runtime. Things haven’t changed that much with 32-bit environments; the code inside a DLL is still shared between applications, but the data isn’t shared anymore. Because it is meant to be used by a linker and a loader, the interface of a DLL is extremely simple — imagine a table of direct pointers to binary code. The export table of a DLL doesn’t contain function prototypes, therefore no syntax check is possible during compilation or linking — everything depends on the prototype declared by the user of the DLL. For example you can compile and link a one parameter function call that ends up in a two parameter function code at runtime, thus creating an unstable situation. This extreme simplicity of the DLL interface combined with late binding provided unprecedented flexibility ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access