zoukankan      html  css  js  c++  java
  • Marshaling Data with Platform Invoke 之三 Marshaling Classes, Structures, and Unions(用时查阅)

    Marshaling Classes, Structures, and Unions

    Classes and structures are similar in the .NET Framework. Both can have fields, properties, and events. They can also have static and nonstatic methods. One notable difference is that structures are value types and classes are reference types.

    The following table lists marshaling options for classes, structures, and unions; describes their usage; and provides a link to the corresponding platform invoke sample.

    Type

    Description

    Sample

    Class by value.

    Passes a class with integer members as an In/Out parameter, like the managed case.

    SysTime

    Structure by value.

    Passes structures as In parameters.

    Structures

    Structure by reference.

    Passes structures as In/Out parameters.

    OSInfo

    Structure with nested structures (flattened).

    Passes a class that represents a structure with nested structures in the unmanaged function. The structure is flattened to one big structure in the managed prototype.

    FindFile

    Structure with nested structures (not flattened).

    Passes a structure with an embedded structure.

    Structures

    Structure with a pointer to another structure.

    Passes a structure that contains a pointer to a second structure as a member.

    Structures

    Array of structures with integers by value.

    Passes an array of structures that contain only integers as an In/Out parameter. Members of the array can be changed.

    Arrays

    Array of structures with integers and strings by reference.

    Passes an array of structures that contain integers and strings as an Out parameter. The called function allocates memory for the array.

    OutArrayOfStructs

    Unions with value types.

    Passes unions with value types (integer and double).

    Unions

    Unions with mixed types.

    Passes unions with mixed types (integer and string).

    Unions

    Null values in structure.

    Passes a null reference (Nothing in Visual Basic) instead of a reference to a value type.

    HandleRef

  • 相关阅读:
    PHP
    PHP
    密码修改机制
    PHP
    PHP
    PHP
    PHP
    Java并发编程:进程和线程的由来(转)
    Java获取文件大小的正确方法(转)
    J2EE开发中常用的缓存策略
  • 原文地址:https://www.cnblogs.com/MayGarden/p/1642989.html
Copyright © 2011-2022 走看看