MarshalAsAttribute.SizeParamIndex フィールドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MarshalAsAttribute.SizeParamIndex フィールドの意味・解説 

MarshalAsAttribute.SizeParamIndex フィールド

COMsize_is のように、0 から始まる配列要素カウント格納しているパラメータ示します

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public SizeParamIndex As Short
Dim instance As MarshalAsAttribute
Dim value As Short

value = instance.SizeParamIndex

instance.SizeParamIndex = value
public short SizeParamIndex
public:
short SizeParamIndex
public short SizeParamIndex
public var SizeParamIndex : short
解説解説

このフィールドは、COM 対応マネージ オブジェクト構築する場合使用しますSizeParamIndex は、COM クライアントから呼び出されパラメータ1 つ配列マネージ メソッドでだけ有効です。マーシャラはアンマネージ配列サイズ決定できないため、この情報別のパラメータ渡されます。

サイズ格納するパラメータは、値渡しによる整数である必要があります。UnmanagedType.LPArray で SizeParamIndex と MarshalAsAttribute.SizeConst の両方指定した場合、これらの値の和がサイズ合計となります。このフィールドは、COM オブジェクト呼び出すマネージ コードには影響与えません。詳細については、配列対す既定マーシャリングトピック参照してください

使用例使用例
Option Strict Off

Imports System.Runtime.InteropServices
Imports SomeNamespace

Namespace SomeNamespace
    ' Force the layout of your fields to the C style struct layout.
    ' Without this, the .NET Framework will reorder your fields.
    
    <StructLayout(LayoutKind.Sequential)> _
    Structure Vertex
        Dim x As Decimal
        Dim y As Decimal
        Dim z As Decimal
    End Structure

    Class SomeClass
        ' Add [In] or [In, Out] attributes as approppriate.
        ' Marshal as a C style array of Vertex, where the second (SizeParamIndex
 is zero-based)
        '  parameter (size) contains the count of array elements.

        Declare Auto Sub
 SomeUnsafeMethod Lib "somelib.dll"
 ( _
                                      <MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=1)>
 data() As Vertex, _
                                      size As Long
 ) 

        Public Sub SomeMethod()
            Dim verts(3) As Vertex
            SomeUnsafeMethod( verts, verts.Length )
        End Sub

    End Class

End Namespace

Module Test
    Sub Main
        Dim AClass As New
 SomeClass

        AClass.SomeMethod
        End Sub
End Module
using System.Runtime.InteropServices;
using SomeNamespace;

namespace SomeNamespace
{
    // Force the layout of your fields to the C style struct layout.
    // Without this, the .NET Framework will reorder your fields.
    [StructLayout(LayoutKind.Sequential)]
    public struct Vertex
    {
        float    x;
    float    y;
        float    z;
    }

    class SomeClass
    {
        // Add [In] or [In, Out] attributes as approppriate.
        // Marshal as a C style array of Vertex, where the second (SizeParamIndex
 is zero-based)
        //  parameter (size) contains the count of array elements.
        [DllImport ("SomeDll.dll")]
        public static extern void
 SomeUnsafeMethod(
                                      [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)]
 Vertex[] data,
                                      long size );

        public void SomeMethod()
        {
            Vertex[] verts = new Vertex[3];
            SomeUnsafeMethod( verts, verts.Length );
        }

    }
}

class Test
{
    public static void Main()
    {
        SomeClass AClass = new SomeClass();

        AClass.SomeMethod();
    }
}
using namespace System;
using namespace System::Runtime::InteropServices;

// Force the layout of your fields to the C-style struct layout.
// Without this, the .NET Framework will reorder your fields.

[StructLayoutAttribute(LayoutKind::Sequential)]
value struct Vertex
{
public:
   float x;
   float y;
   float z;
};


// Add [In] or [In, Out] attributes as appropriate.
// Marshal as a C-style array of Vertex, where the second (SizeParamIndex
 is zero-based)
// parameter (size) contains the count of array elements.

[DllImport("SomeDLL.dll")]
extern void SomeUnsafeMethod( [MarshalAs(UnmanagedType::LPArray,SizeParamIndex=1)]array<Vertex>^data,
 long size );
int main()
{
   array<Vertex>^verts = gcnew array<Vertex>(3);
   SomeUnsafeMethod( verts, verts->Length );
}

package SomeNamespace; 
import System.Runtime.InteropServices.*;
import SomeNamespace.*; 

/** @attribute StructLayout(LayoutKind.Sequential)
 */
public class Vertex
{
    private float x;
    private float y;
    private float z;
} //Vertex

class SomeClass
{
    // Add [In] or [In, Out] attributes as approppriate.
    // Marshal as a C style array of Vertex, where the second
    // (SizeParamIndex is zero-based)
    //  parameter (size) contains the count of array elements.
    /** @attribute DllImport("SomeDll.dll")
     */
    public static native void
 SomeUnsafeMethod(
        /** @attribute MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)
         */
        Vertex data[], long size);

    public void SomeMethod()
    {
        Vertex verts[] = new Vertex[3];
        SomeUnsafeMethod(verts, verts.length);
    } //SomeMethod
} //SomeClass

class Test
{
    public static void main(String[]
 args)
    {
        SomeClass aClass = new SomeClass();
        aClass.SomeMethod();
    } //main
} //Test
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MarshalAsAttribute クラス
MarshalAsAttribute メンバ
System.Runtime.InteropServices 名前空間
SizeConst
LPArray


このページでは「.NET Framework クラス ライブラリ リファレンス」からMarshalAsAttribute.SizeParamIndex フィールドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からMarshalAsAttribute.SizeParamIndex フィールドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からMarshalAsAttribute.SizeParamIndex フィールド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「MarshalAsAttribute.SizeParamIndex フィールド」の関連用語

MarshalAsAttribute.SizeParamIndex フィールドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MarshalAsAttribute.SizeParamIndex フィールドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS