1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 // PInvokePassingByOutNative.cpp : Defines the entry point for the DLL application.
9 #include "platformdefines.h"
12 //#####################################################################
13 //ByOut Array, ByRef SizeParamIndex
14 //#####################################################################
16 //BYTE 0 ==> 20 size Array
17 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayByte_AsByOut_AsSizeParamIndex(BYTE* arrSize, BYTE** ppActual)
19 return CheckAndChangeArrayByOut(ppActual, arrSize, (BYTE)1);
22 //CHAR 1 ==> CHAR.Max size Array
23 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArraySbyte_AsByOut_AsSizeParamIndex(CHAR* arrSize, CHAR** ppActual)
25 return CheckAndChangeArrayByOut(ppActual, arrSize, (CHAR)SCHAR_MAX);
28 //SHORT -1 ==> 20 size Array
29 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayShort_AsByOut_AsSizeParamIndex(/*out*/SHORT* arrSize, SHORT** ppActual)
31 short shortArray_Size = 16384;//SHRT_MAX+1/2
33 *ppActual = (SHORT*)CoreClrAlloc(sizeof(SHORT)*shortArray_Size);
35 *arrSize = shortArray_Size;
37 for(SHORT i = 0; i < shortArray_Size; ++i)
39 (*ppActual)[i] = shortArray_Size - 1 - i;
44 //SHORT 10 ==> -1 size Array
45 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayShortReturnNegative_AsByOut_AsSizeParamIndex(SHORT* arrSize, SHORT** ppActual)
47 *ppActual = (SHORT*)CoreClrAlloc(sizeof(SHORT)*CArray_Size);
50 for(SHORT i = 0; i < CArray_Size; ++i)
52 (*ppActual)[i] = CArray_Size - 1 - i;
57 //USHORT ? ==> ushort.Max ==> size Array
58 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayUshort_AsByOut_AsSizeParamIndex(USHORT** ppActual, USHORT* arrSize)
60 return CheckAndChangeArrayByOut(ppActual, arrSize, (USHORT)USHRT_MAX);
63 //Int32 ? ==> 20 size Array
64 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayInt_AsByOut_AsSizeParamIndex(LONG* arrSize,LONG** ppActual)
66 return CheckAndChangeArrayByOut(ppActual, arrSize, (LONG)0);
69 //ULONG 10 ==> 20 size Array
70 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayUInt_AsByOut_AsSizeParamIndex(ULONG* arrSize, ULONG** ppActual)
72 return CheckAndChangeArrayByOut(ppActual, arrSize, (ULONG)20);
75 //LONGLONG 10 ==> 20 size Array
76 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayLong_AsByOut_AsSizeParamIndex(LONGLONG* arrSize, LONGLONG** ppActual)
78 return CheckAndChangeArrayByOut(ppActual, arrSize, (LONGLONG)20);
81 //ULONGLONG 10 ==> 20 size Array
82 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayUlong_AsByOut_AsSizeParamIndex(ULONGLONG** ppActual,ULONGLONG* arrSize,ULONGLONG _unused)
84 return CheckAndChangeArrayByOut(ppActual, arrSize, (ULONGLONG)1000);
87 //String 10 size Array ==> BSTR 20 size Array
88 extern "C" DLL_EXPORT BOOL __stdcall MarshalCStyleArrayString_AsByOut_AsSizeParamIndex(BSTR** ppBSTR,short* arrSize)
90 *ppBSTR = (BSTR*)CoreClrAlloc(sizeof(BSTR)*CArray_Size);
91 for(int i = 0;i<CArray_Size;++i)
93 (*ppBSTR)[i] = ToBSTR(CArray_Size - 1 - i);
96 *arrSize = CArray_Size;