zoukankan      html  css  js  c++  java
  • Marshaling Data with Platform Invoke 之二 Marshaling Strings (用时查阅)

    Marshaling Strings(需懂原理、知其大略,不要陷于细节。用时查阅)

    Platform invoke copies string parameters, converting them from the .NET Framework format (Unicode) to the unmanaged format (ANSI), if needed. Because managed strings are immutable, platform invoke does not copy them back from unmanaged memory to managed memory when the function returns.

    The following table lists marshaling options for strings, describes their usage, and provides a link to the corresponding .NET Framework sample.

    String

    Description

    Sample

    By value.

    Passes strings as In parameters.

    MsgBox

    As result.

    Returns strings from unmanaged code.

    Strings

    By reference.

    Passes strings as In/Out parameters using StringBuilder.

    Buffers

    In a structure by value.

    Passes strings in a structure that is an In parameter.

    Structs

    In a structure by reference (char*).

    Passes strings in a structure that is an In/Out parameter. The unmanaged function expects a pointer to a character buffer and the buffer size is a member of the structure.

    Strings

    In a structure by reference (char[]).

    Passes strings in a structure that is an In/Out parameter. The unmanaged function expects an embedded character buffer.

    OSInfo

    In a class by value (char*).

    Passes strings in a class (a class is an In/Out parameter). The unmanaged function expects a pointer to a character buffer.

    OpenFileDlg

    In a class by value (char[]).

    Passes strings in a class (a class is an In/Out parameter). The unmanaged function expects an embedded character buffer.

    OSInfo

    As an array of strings by value.

    Creates an array of strings that is passed by value.

    Arrays

    As an array of structures that contain strings by value.

    Creates an array of structures that contain strings and the array is passed by value.

    Arrays

  • 相关阅读:
    mysql事务
    mysql查询操作教程
    mysql建表约束
    mysql数据库增删改查
    node服务器响应静态资源
    windows下golang版本的升级
    Linux开机错误
    redis命令
    nginx内置变量
    nginx日志
  • 原文地址:https://www.cnblogs.com/MayGarden/p/1642945.html
Copyright © 2011-2022 走看看