In Brief


  • There are a variety of situations where it is necessary for managed code to call into native code, such as for calling the Windows CE API.

  • While managed binaries are portable to all of the CPU types supported by the .NET Compact Framework, developers must be careful to use native binaries compatible with the hardware they are running on.

  • DLLs written in C++ sometimes use name mangling on the function names they expose, making it harder to call into such DLLs from managed code.

  • To call a native function from managed code, you first declare the native function in the class from which it will be called. Then the native function is treated as one of the class' methods .

  • Managed code throws exceptions if it cannot find the native DLL to call into, or if it cannot marshal the parameters passed between the managed and native code.

  • Fundamental data types 32 bits wide or less can be passed by value or reference. Larger fundamental types, such as long integers, must be passed by reference.

  • The DWORD type, commonly used in native code, is compatible with the UInt32 type in the .NET Compact Framework.

  • The managed IntPtr data type is compatible with handle types in the Windows CE operating system.

  • To pass a non-mutable string into native code, use the C# string ( String in Visual Basic) type. To pass a mutable string into native code, use a StringBuilder .

  • The .NET Compact Framework can automatically marshal simple structures, which are structures with no nested sub structures. All simple structures must be passed by reference.

  • It is possible to pass complex structures that contain nested structures into native code by reference, but custom marshalling code is required. Doing this is only possible with C# because Visual Basic does not allow access to pointers under any circumstances.

  • Calling the Windows CE operating system is no different from calling native code in any other DLL. Many user -callable functions in the Windows CE OS are in the core .dll library.

  • Odyssey Software offers a product called CFCom with which managed code can access COM components .



Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net