summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJiang Zeng (Pactera Technologies Inc) <v-jiazen@microsoft.com>2018-08-08 02:19:42 -0700
committerJeremy Koritzinsky <jkoritzinsky@gmail.com>2018-10-31 17:24:05 -0700
commitaa0d4daf1491562a6c7e6ef18f719938a0e6e4bd (patch)
treed6629ca96effc64aa21873c047e4894e039758c1 /tests
parentb7d2cdd29a7c1a7ec63fb39d574a817011b9ed4a (diff)
downloadcoreclr-aa0d4daf1491562a6c7e6ef18f719938a0e6e4bd.tar.gz
coreclr-aa0d4daf1491562a6c7e6ef18f719938a0e6e4bd.tar.bz2
coreclr-aa0d4daf1491562a6c7e6ef18f719938a0e6e4bd.zip
Add PInvoke/Structures tests
Fix compile warnings Fix compile warnings Fix compile warnings Remove duplicate tests. Move ReversePinvoke tests under StructMarshalling. Clean up some compile errors. More string cleanup. More string fixes Clean up consts and typedefs. Fix typo. Change TP_slen return type to match xplatform.h Fix printf specifiers. Don't define wcslen in xplatform if it's been macro redefined (to platformdefines.h's TP_slen) Fix build breaks. Remove extension from DllImport so it will correctly resolve xplat. Fix printf specifiers again... Fix Windows x86 calling convention mismatch. Fix HRESULT size off-Windows
Diffstat (limited to 'tests')
-rw-r--r--tests/src/Common/Platform/platformdefines.cpp6
-rw-r--r--tests/src/Common/Platform/platformdefines.h6
-rw-r--r--tests/src/Interop/CMakeLists.txt2
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/Helper.cs1252
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/CMakeLists.txt13
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/DelegatePInvoke/DelegatePInvokeTest.csbin0 -> 103010 bytes
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/DelegatePInvoke/DelegatePInvokeTest.csproj40
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.cpp1606
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.h919
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ReversePInvokeManaged/ReversePInvokeTest.cs807
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ReversePInvokeManaged/ReversePInvokeTest.csproj40
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/CMakeLists.txt11
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/DelegatePInvoke/DelegatePInvokeTest.csbin0 -> 182048 bytes
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/DelegatePInvoke/DelegatePInvokeTest.csproj37
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest.csbin0 -> 182602 bytes
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest.csproj37
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.cpp3241
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.h881
-rw-r--r--tests/src/Interop/StructMarshalling/ReversePInvoke/Struct.cs279
-rw-r--r--tests/src/Interop/common/xplatform.h2
20 files changed, 9173 insertions, 6 deletions
diff --git a/tests/src/Common/Platform/platformdefines.cpp b/tests/src/Common/Platform/platformdefines.cpp
index 826e741e06..34cd360cfa 100644
--- a/tests/src/Common/Platform/platformdefines.cpp
+++ b/tests/src/Common/Platform/platformdefines.cpp
@@ -77,9 +77,9 @@ error_t TP_scat_s(LPWSTR strDestination, size_t sizeInWords, LPCWSTR strSource)
return TP_scpy_s(strEnd, sizeInWords - ((strEnd - strDestination) / sizeof(WCHAR)), strSource);
}
-int TP_slen(LPWSTR str)
+size_t TP_slen(LPCWSTR str)
{
- int len;
+ size_t len;
if (NULL == str) return 0;
@@ -113,7 +113,7 @@ int TP_scmp_s(LPCSTR str1, LPCSTR str2)
return (*str1 > *str2) ? 1 : -1;
}
-int TP_wcmp_s(LPWSTR str1, LPWSTR str2)
+int TP_wcmp_s(LPCWSTR str1, LPCWSTR str2)
{
// < 0 str1 less than str2
// 0 str1 identical to str2
diff --git a/tests/src/Common/Platform/platformdefines.h b/tests/src/Common/Platform/platformdefines.h
index aa96483124..64b9c8069f 100644
--- a/tests/src/Common/Platform/platformdefines.h
+++ b/tests/src/Common/Platform/platformdefines.h
@@ -36,7 +36,7 @@ typedef int BOOL;
typedef WCHAR *LPWSTR, *PWSTR;
typedef const WCHAR *LPCWSTR, *PCWSTR;
-typedef long HRESULT;
+typedef int HRESULT;
#define LONGLONG long long
#define ULONGLONG unsigned LONGLONG
typedef unsigned long ULONG, *PULONG;
@@ -125,9 +125,9 @@ typedef ULONG_PTR DWORD_PTR;
//
error_t TP_scpy_s(LPWSTR strDestination, size_t sizeInWords, LPCWSTR strSource);
error_t TP_scat_s(LPWSTR strDestination, size_t sizeInWords, LPCWSTR strSource);
-int TP_slen(LPWSTR str);
+size_t TP_slen(LPCWSTR str);
int TP_scmp_s(LPCSTR str1, LPCSTR str2);
-int TP_wcmp_s(LPWSTR str1, LPWSTR str2);
+int TP_wcmp_s(LPCWSTR str1, LPCWSTR str2);
error_t TP_getenv_s(size_t* pReturnValue, LPWSTR buffer, size_t sizeInWords, LPCWSTR varname);
error_t TP_putenv_s(LPTSTR name, LPTSTR value);
void TP_ZeroMemory(LPVOID buffer, size_t sizeInBytes);
diff --git a/tests/src/Interop/CMakeLists.txt b/tests/src/Interop/CMakeLists.txt
index 0a512c2315..4fe5cef71c 100644
--- a/tests/src/Interop/CMakeLists.txt
+++ b/tests/src/Interop/CMakeLists.txt
@@ -25,6 +25,8 @@ add_subdirectory(PrimitiveMarshalling/EnumMarshalling)
add_subdirectory(FuncPtrAsDelegateParam)
add_subdirectory(SimpleStruct)
add_subdirectory(StructMarshalling/PInvoke)
+add_subdirectory(StructMarshalling/ReversePInvoke/MarshalExpStruct)
+add_subdirectory(StructMarshalling/ReversePInvoke/MarshalSeqStruct)
add_subdirectory(BestFitMapping)
add_subdirectory(RefInt)
add_subdirectory(RefCharArray)
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/Helper.cs b/tests/src/Interop/StructMarshalling/ReversePInvoke/Helper.cs
new file mode 100644
index 0000000000..eadfab6a18
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/Helper.cs
@@ -0,0 +1,1252 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+using System.IO;
+using System.Text;
+using System.Globalization;
+using System.Collections;
+using System.IO.IsolatedStorage;
+using System.Security.Policy;
+
+public class Helper
+{
+
+ #region methods for InnerSequential struct
+
+ // Return new InnerSequential instance
+ public static InnerSequential NewInnerSequential(int f1, float f2, string f3)
+ {
+ InnerSequential inner_seq = new InnerSequential();
+ inner_seq.f1 = f1;
+ inner_seq.f2 = f2;
+ inner_seq.f3 = f3;
+ return inner_seq;
+ }
+
+ // Prints InnerSequential
+ public static void PrintInnerSequential(InnerSequential inner_seq, string name)
+ {
+ Console.WriteLine("\t{0}.f1 = {1}", name, inner_seq.f1);
+ Console.WriteLine("\t{0}.f2 = {1}", name, inner_seq.f2);
+ Console.WriteLine("\t{0}.f3 = {1}", name, inner_seq.f3);
+ }
+
+ public static bool ValidateInnerSequential(InnerSequential s1, InnerSequential s2, string methodName)
+ {
+ if (s1.f1 != s2.f1 || s1.f2 != s2.f2 || s1.f3 != s2.f3)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintInnerSequential(s1, s1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintInnerSequential(s2, s2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for INNER2 struct
+
+ // Return new INNER2 instance
+ public static INNER2 NewINNER2(int f1, float f2, string f3)
+ {
+ INNER2 inner = new INNER2();
+ inner.f1 = f1;
+ inner.f2 = f2;
+ inner.f3 = f3;
+ return inner;
+ }
+
+ // Prints INNER2
+ public static void PrintINNER2(INNER2 inner, string name)
+ {
+ Console.WriteLine("\t{0}.f1 = {1}", name, inner.f1);
+ Console.WriteLine("\t{0}.f2 = {1}", name, inner.f2);
+ Console.WriteLine("\t{0}.f3 = {1}", name, inner.f3);
+ }
+
+ public static bool ValidateINNER2(INNER2 inner1, INNER2 inner2, string methodName)
+ {
+ if (inner1.f1 != inner2.f1 || inner1.f2 != inner2.f2 || inner1.f3 != inner2.f3)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintINNER2(inner1, inner1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintINNER2(inner2, inner2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for InnerExplicit struct
+
+ // Return new InnerExplicit instance
+ public static InnerExplicit NewInnerExplicit(int f1, float f2, string f3)
+ {
+ InnerExplicit inner = new InnerExplicit();
+ inner.f1 = f1;
+ inner.f2 = f2;
+ inner.f3 = f3;
+ return inner;
+ }
+
+ // Prints InnerExplicit
+ public static void PrintInnerExplicit(InnerExplicit inner, string name)
+ {
+ Console.WriteLine("\t{0}.f1 = {1}", name, inner.f1);
+ Console.WriteLine("\t{0}.f2 = {1}", name, inner.f2);
+ Console.WriteLine("\t{0}.f3 = {1}", name, inner.f3);
+ }
+
+ public static bool ValidateInnerExplicit(InnerExplicit inner1, InnerExplicit inner2, string methodName)
+ {
+ if (inner1.f1 != inner2.f1 || inner1.f2 != inner2.f2 || inner1.f3 != inner2.f3)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintInnerExplicit(inner1, inner1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintInnerExplicit(inner2, inner2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for InnerArraySequential struct
+
+ // Returns new OUTER instance; the params are the fields of INNER;
+ // all the INNER elements have the same field values
+ public static InnerArraySequential NewInnerArraySequential(int f1, float f2, string f3)
+ {
+ InnerArraySequential outer = new InnerArraySequential();
+ outer.arr = new InnerSequential[Common.NumArrElements];
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ outer.arr[i].f1 = f1;
+ outer.arr[i].f2 = f2;
+ outer.arr[i].f3 = f3;
+ }
+ return outer;
+ }
+
+ // Prints InnerArraySequential
+ public static void PrintInnerArraySequential(InnerArraySequential outer, string name)
+ {
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1);
+ Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2);
+ Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3);
+ }
+ }
+
+ // Returns true if the two params have the same fields
+ public static bool ValidateInnerArraySequential(InnerArraySequential outer1, InnerArraySequential outer2, string methodName)
+ {
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ if (outer1.arr[i].f1 != outer2.arr[i].f1 ||
+ outer1.arr[i].f2 != outer2.arr[i].f2 ||
+ outer1.arr[i].f3 != outer2.arr[i].f3)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1);
+ Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer1.ToString(), i, outer1.arr[i].f2);
+ Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer1.ToString(), i, outer1.arr[i].f3);
+ Console.WriteLine("\tThe Expected is...");
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer2.ToString(), i, outer2.arr[i].f1);
+ Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer2.ToString(), i, outer2.arr[i].f2);
+ Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer2.ToString(), i, outer2.arr[i].f3);
+ return false;
+ }
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+
+ #endregion
+
+ #region methods for InnerArrayExplicit struct
+
+ // Returns new InnerArrayExplicit instance; the params are the fields of INNER;
+ // all the INNER elements have the same field values
+ public static InnerArrayExplicit NewInnerArrayExplicit(int f1, float f2, string f3, string f4)
+ {
+ InnerArrayExplicit outer = new InnerArrayExplicit();
+ outer.arr = new InnerSequential[Common.NumArrElements];
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ outer.arr[i].f1 = f1;
+ outer.arr[i].f2 = f2;
+ outer.arr[i].f3 = f3;
+ }
+ outer.f4 = f4;
+ return outer;
+ }
+
+ // Prints InnerArrayExplicit
+ public static void PrintInnerArrayExplicit(InnerArrayExplicit outer, string name)
+ {
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1);
+ Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2);
+ Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3);
+ }
+ Console.WriteLine("\t{0}.f4 = {1}", name, outer.f4);
+ }
+
+ // Returns true if the two params have the same fields
+ public static bool ValidateInnerArrayExplicit(InnerArrayExplicit outer1, InnerArrayExplicit InnerArrayExplicit, string methodName)
+ {
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ if (outer1.arr[i].f1 != InnerArrayExplicit.arr[i].f1)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual f1 field is...");
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1);
+ Console.WriteLine("\tThe Expected f1 field is...");
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f1);
+ return false;
+ }
+ }
+ if (outer1.f4 != InnerArrayExplicit.f4)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual f4 field is...");
+ Console.WriteLine("\t{0}.f4 = {1}", outer1.ToString(), outer1.f4);
+ Console.WriteLine("\tThe Expected f4 field is...");
+ Console.WriteLine("\t{0}.f4 = {1}", InnerArrayExplicit.ToString(), InnerArrayExplicit.f4);
+ return false;
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+
+ #endregion
+
+ #region methods for OUTER3 struct
+
+ // Returns new OUTER3 instance; the params are the fields of INNER;
+ // all the INNER elements have the same field values
+ public static OUTER3 NewOUTER3(int f1, float f2, string f3, string f4)
+ {
+ OUTER3 outer = new OUTER3();
+ outer.arr = new InnerSequential[Common.NumArrElements];
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ outer.arr[i].f1 = f1;
+ outer.arr[i].f2 = f2;
+ outer.arr[i].f3 = f3;
+ }
+ outer.f4 = f4;
+ return outer;
+ }
+
+ // Prints OUTER3
+ public static void PrintOUTER3(OUTER3 outer, string name)
+ {
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1);
+ Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2);
+ Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3);
+ }
+ Console.WriteLine("\t{0}.f4 = {1}", name, outer.f4);
+ }
+
+ // Returns true if the two params have the same fields
+ public static bool ValidateOUTER3(OUTER3 outer1, OUTER3 InnerArrayExplicit, string methodName)
+ {
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ if (outer1.arr[i].f1 != InnerArrayExplicit.arr[i].f1 ||
+ outer1.arr[i].f2 != InnerArrayExplicit.arr[i].f2 ||
+ outer1.arr[i].f3 != InnerArrayExplicit.arr[i].f3)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1);
+ Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer1.ToString(), i, outer1.arr[i].f2);
+ Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer1.ToString(), i, outer1.arr[i].f3);
+ Console.WriteLine("\tThe Expected is...");
+ Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f1);
+ Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f2);
+ Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f3);
+ return false;
+ }
+ }
+ if (outer1.f4 != InnerArrayExplicit.f4)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual f4 field is...");
+ Console.WriteLine("\t{0}.f4 = {1}", outer1.ToString(), outer1.f4);
+ Console.WriteLine("\tThe Expected f4 field is...");
+ Console.WriteLine("\t{0}.f4 = {1}", InnerArrayExplicit.ToString(), InnerArrayExplicit.f4);
+ return false;
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+
+ #endregion
+
+ #region methods for CharSetAnsiSequential struct
+
+ //return CharSetAnsiSequential struct instance
+ public static CharSetAnsiSequential NewCharSetAnsiSequential(string f1, char f2)
+ {
+ CharSetAnsiSequential str1 = new CharSetAnsiSequential();
+ str1.f1 = f1;
+ str1.f2 = f2;
+ return str1;
+ }
+
+ //print the struct CharSetAnsiSequential element
+ public static void PrintCharSetAnsiSequential(CharSetAnsiSequential str1, string name)
+ {
+ Console.WriteLine("\t{0}.f1 = {1}", name, str1.f1);
+ Console.WriteLine("\t{0}.f2 = {1}", name, str1.f2);
+ }
+
+ // Returns true if the two params have the same fields
+ public static bool ValidateCharSetAnsiSequential(CharSetAnsiSequential str1, CharSetAnsiSequential str2, string methodName)
+ {
+ if (str1.f1 != str2.f1 || str1.f2 != str2.f2)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintCharSetAnsiSequential(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintCharSetAnsiSequential(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for CharSetUnicodeSequential struct
+
+ //return the struct CharSetUnicodeSequential instance
+ public static CharSetUnicodeSequential NewCharSetUnicodeSequential(string f1, char f2)
+ {
+ CharSetUnicodeSequential str1 = new CharSetUnicodeSequential();
+ str1.f1 = f1;
+ str1.f2 = f2;
+ return str1;
+ }
+
+ //print the struct CharSetUnicodeSequential element
+ public static void PrintCharSetUnicodeSequential(CharSetUnicodeSequential str1, string name)
+ {
+ Console.WriteLine("\t{0}.f1 = {1}", name, str1.f1);
+ Console.WriteLine("\t{0}.f2 = {1}", name, str1.f2);
+ }
+
+ // Returns true if the two params have the same fields
+ public static bool ValidateCharSetUnicodeSequential(CharSetUnicodeSequential str1, CharSetUnicodeSequential str2, string methodName)
+ {
+ if (str1.f1 != str2.f1 || str1.f2 != str2.f2)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintCharSetUnicodeSequential(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintCharSetUnicodeSequential(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for NumberSequential struct
+
+ public static NumberSequential NewNumberSequential(int i32, uint ui32, short s1, ushort us1, Byte b, SByte sb,
+ Int16 i16, UInt16 ui16, Int64 i64, UInt64 ui64, Single sgl, Double d)
+ {
+ NumberSequential str1 = new NumberSequential();
+ str1.i32 = i32;
+ str1.ui32 = ui32;
+ str1.s1 = s1;
+ str1.us1 = us1;
+ str1.b = b;
+ str1.sb = sb;
+ str1.i16 = i16;
+ str1.ui16 = ui16;
+ str1.i64 = i64;
+ str1.ui64 = ui64;
+ str1.sgl = sgl;
+ str1.d = d;
+ return str1;
+ }
+
+ public static void PrintNumberSequential(NumberSequential str1, string name)
+ {
+ Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32);
+ Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32);
+ Console.WriteLine("\t{0}.s1 = {1}", name, str1.s1);
+ Console.WriteLine("\t{0}.us1 = {1}", name, str1.us1);
+ Console.WriteLine("\t{0}.b = {1}", name, str1.b);
+ Console.WriteLine("\t{0}.sb = {1}", name, str1.sb);
+ Console.WriteLine("\t{0}.i16 = {1}", name, str1.i16);
+ Console.WriteLine("\t{0}.ui16 = {1}", name, str1.ui16);
+ Console.WriteLine("\t{0}.i64 = {1}", name, str1.i64);
+ Console.WriteLine("\t{0}.ui64 = {1}", name, str1.ui64);
+ Console.WriteLine("\t{0}.sgl = {1}", name, str1.sgl);
+ Console.WriteLine("\t{0}.d = {1}", name, str1.d);
+ }
+
+ public static bool ValidateNumberSequential(NumberSequential str1, NumberSequential str2, string methodName)
+ {
+ if (str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.s1 != str2.s1 ||
+ str1.us1 != str2.us1 || str1.b != str2.b || str1.sb != str2.sb || str1.i16 != str2.i16 ||
+ str1.ui16 != str2.ui16 || str1.i64 != str2.i64 || str1.ui64 != str2.ui64 ||
+ str1.sgl != str2.sgl || str1.d != str2.d)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintNumberSequential(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintNumberSequential(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for S3 struct
+
+ public static void InitialArray(int[] iarr, int[] icarr)
+ {
+ for (int i = 0; i < iarr.Length; i++)
+ {
+ iarr[i] = i;
+ }
+
+ for (int i = 1; i < icarr.Length + 1; i++)
+ {
+ icarr[i - 1] = i;
+ }
+ }
+
+ public static S3 NewS3(bool flag, string str, int[] vals)
+ {
+ S3 str1 = new S3();
+ str1.flag = flag;
+ str1.str = str;
+ str1.vals = vals;
+ return str1;
+ }
+
+ public static void PrintS3(S3 str1, string name)
+ {
+ Console.WriteLine("\t{0}.flag = {1}", name, str1.flag);
+ Console.WriteLine("\t{0}.flag = {1}", name, str1.str);
+ for (int i = 0; i < str1.vals.Length; i++)
+ {
+ Console.WriteLine("\t{0}.vals[{1}] = {2}", name, i, str1.vals[i]);
+ }
+ }
+
+ public static bool ValidateS3(S3 str1, S3 str2, string methodName)
+ {
+ int iflag = 0;
+ if (str1.flag != str2.flag || str1.str != str2.str)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual flag field is...");
+ Console.WriteLine("\t{0}.flag = {1}", str1.ToString(), str1.flag);
+ Console.WriteLine("\t{0}.str = {1}", str1.ToString(), str1.str);
+ Console.WriteLine("\tThe Expected is...");
+ Console.WriteLine("\t{0}.flag = {1}", str2.ToString(), str2.flag);
+ Console.WriteLine("\t{0}.str = {1}", str2.ToString(), str2.str);
+ return false;
+ }
+ for (int i = 0; i < 256; i++)
+ {
+ if (str1.vals[i] != str2.vals[i])
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual vals field is...");
+ Console.WriteLine("\t{0}.vals[{1}] = {2}", str1.ToString(), i, str1.vals[i]);
+ Console.WriteLine("\tThe Expected vals field is...");
+ Console.WriteLine("\t{0}.vals[{1}] = {2}", str2.ToString(), i, str2.vals[i]);
+ iflag++;
+ }
+ }
+ if (iflag != 0)
+ {
+ return false;
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+
+ #endregion
+
+ #region methods for S5 struct
+
+ public static S5 NewS5(int age, string name, Enum1 ef)
+ {
+ S4 s4 = new S4();
+ s4.age = age;
+ s4.name = name;
+
+ S5 s5 = new S5();
+ s5.s4 = s4;
+ s5.ef = ef;
+
+ return s5;
+ }
+
+ public static void PrintS5(S5 str1, string name)
+ {
+ Console.WriteLine("\t{0}.s4.age = {1}", str1.s4.age);
+ Console.WriteLine("\t{0}.s4.name = {1}", str1.s4.name);
+ Console.WriteLine("\t{0}.ef = {1}", str1.ef.ToString());
+ }
+
+ public static bool ValidateS5(S5 str1, S5 str2, string methodName)
+ {
+ if (str1.s4.age != str2.s4.age || str1.s4.name != str2.s4.name)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual s4 field is...");
+ Console.WriteLine("\t{0}.s4.age = {1}", str1.ToString(), str1.s4.age);
+ Console.WriteLine("\t{0}.s4.name = {1}", str1.ToString(), str1.s4.name);
+ Console.WriteLine("\tThe Expected s4 field is...");
+ Console.WriteLine("\t{0}.s4.age = {1}", str2.ToString(), str2.s4.age);
+ Console.WriteLine("\t{0}.s4.name = {1}", str2.ToString(), str2.s4.name);
+ return false;
+ }
+ if (str1.ef != str2.ef)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual ef field is...");
+ Console.WriteLine("\t{0}.ef = {1}", str1.ToString(), str1.ef);
+ Console.WriteLine("\tThe Expected s4 field is...");
+ Console.WriteLine("\t{0}.ef = {1}", str2.ToString(), str2.ef);
+ return false;
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+
+ #endregion
+
+ #region methods for StringStructSequentialAnsi struct
+
+ public static StringStructSequentialAnsi NewStringStructSequentialAnsi(string first, string last)
+ {
+ StringStructSequentialAnsi s6 = new StringStructSequentialAnsi();
+ s6.first = first;
+ s6.last = last;
+
+ return s6;
+ }
+
+ public static void PrintStringStructSequentialAnsi(StringStructSequentialAnsi str1, string name)
+ {
+ Console.WriteLine("\t{0}.first = {1}", name, str1.first);
+ Console.WriteLine("\t{0}.last = {1}", name, str1.last);
+ }
+
+ public static bool ValidateStringStructSequentialAnsi(StringStructSequentialAnsi str1, StringStructSequentialAnsi str2, string methodName)
+ {
+ if (str1.first != str2.first || str1.last != str2.last)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintStringStructSequentialAnsi(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintStringStructSequentialAnsi(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for StringStructSequentialUnicode struct
+
+ public static StringStructSequentialUnicode NewStringStructSequentialUnicode(string first, string last)
+ {
+ StringStructSequentialUnicode s7 = new StringStructSequentialUnicode();
+ s7.first = first;
+ s7.last = last;
+
+ return s7;
+ }
+
+ public static void PrintStringStructSequentialUnicode(StringStructSequentialUnicode str1, string name)
+ {
+ Console.WriteLine("\t{0}.first = {1}", name, str1.first);
+ Console.WriteLine("\t{0}.last = {1}", name, str1.last);
+ }
+
+ public static bool ValidateStringStructSequentialUnicode(StringStructSequentialUnicode str1, StringStructSequentialUnicode str2, string methodName)
+ {
+ if (str1.first != str2.first || str1.last != str2.last)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintStringStructSequentialUnicode(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintStringStructSequentialUnicode(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for S8 struct
+
+ public static S8 NewS8(string name, bool gender, UInt16 jobNum, int i32, uint ui32, sbyte mySByte)
+ {
+ S8 s8 = new S8();
+ s8.name = name;
+ s8.gender = gender;
+ s8.i32 = i32;
+ s8.ui32 = ui32;
+ s8.jobNum = jobNum;
+ s8.mySByte = mySByte;
+ return s8;
+ }
+
+ public static void PrintS8(S8 str1, string name)
+ {
+ Console.WriteLine("\t{0}.name = {1}", name, str1.name);
+ Console.WriteLine("\t{0}.gender = {1}", name, str1.gender);
+ Console.WriteLine("\t{0}.jobNum = {1}", name, str1.jobNum);
+ Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32);
+ Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32);
+ Console.WriteLine("\t{0}.mySByte = {1}", name, str1.mySByte);
+ }
+
+ public static bool ValidateS8(S8 str1, S8 str2, string methodName)
+ {
+ if (str1.name != str2.name || str1.gender != str2.gender ||
+ str1.jobNum != str2.jobNum ||
+ str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.mySByte != str2.mySByte)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintS8(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintS8(str2, str2.ToString());
+ return false;
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+
+ }
+
+ #endregion
+
+ #region methods for S9 struct
+
+ public static S9 NewS9(int i32, TestDelegate1 testDel1)
+ {
+ S9 s9 = new S9();
+ s9.i32 = i32;
+ s9.myDelegate1 = testDel1;
+ return s9;
+ }
+
+ public static bool ValidateS9(S9 str1, S9 str2, string methodName)
+ {
+ if (str1.i32 != str2.i32 || str1.myDelegate1 != str2.myDelegate1)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ Console.WriteLine("\t{0}.i32 = {1}", str1.ToString(), str1.i32);
+ Console.WriteLine("\t{0}.myDelegate1 = {1}", str1.ToString(), str1.myDelegate1);
+ Console.WriteLine("\tThe Expected is...");
+ Console.WriteLine("\t{0}.i32 = {1}", str2.ToString(), str2.i32);
+ Console.WriteLine("\t{0}.myDelegate1 = {1}", str2.ToString(), str2.myDelegate1);
+ return false;
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+
+ #endregion
+
+ #region methods for IncludeOuterIntergerStructSequential struct
+
+ public static IncludeOuterIntergerStructSequential NewIncludeOuterIntergerStructSequential(int i321, int i322)
+ {
+ IncludeOuterIntergerStructSequential s10 = new IncludeOuterIntergerStructSequential();
+ s10.s.s_int.i = i321;
+ s10.s.i = i322;
+ return s10;
+ }
+
+ public static void PrintIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential str1, string name)
+ {
+ Console.WriteLine("\t{0}.s.s_int.i = {1}", name, str1.s.s_int.i);
+ Console.WriteLine("\t{0}.s.i = {1}", name, str1.s.i);
+ }
+
+ public static bool ValidateIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential str1, IncludeOuterIntergerStructSequential str2, string methodName)
+ {
+ if (str1.s.s_int.i != str2.s.s_int.i || str1.s.i != str2.s.i)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintIncludeOuterIntergerStructSequential(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintIncludeOuterIntergerStructSequential(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for S11 struct
+
+ unsafe public static void PrintS11(S11 str1, string name)
+ {
+ Console.WriteLine("\t{0}.i32 = {1}", name, (int)(str1.i32));
+ Console.WriteLine("\t{0}.i = {1}", name, str1.i);
+ }
+
+ unsafe public static S11 NewS11(int* i32, int i)
+ {
+ S11 s11 = new S11();
+ s11.i32 = i32;
+ s11.i = i;
+ return s11;
+ }
+
+ unsafe public static bool ValidateS11(S11 str1, S11 str2, string methodName)
+ {
+ if (str1.i32 != str2.i32 || str1.i != str2.i)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintS11(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintS11(str2, str2.ToString());
+ return false;
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+
+ #endregion
+
+ #region methods for U struct
+
+ public static U NewU(int i32, uint ui32, IntPtr iPtr, UIntPtr uiPtr, short s, ushort us, byte b, sbyte sb, long l, ulong ul, float f, double d)
+ {
+ U u = new U();
+ u.i32 = i32;
+ u.ui32 = ui32;
+ u.iPtr = iPtr;
+ u.uiPtr = uiPtr;
+ u.s = s;
+ u.us = us;
+ u.b = b;
+ u.sb = sb;
+ u.l = l;
+ u.ul = ul;
+ u.f = f;
+ u.d = d;
+
+ return u;
+ }
+
+ public static void PrintU(U str1, string name)
+ {
+ Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32);
+ Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32);
+ Console.WriteLine("\t{0}.iPtr = {1}", name, str1.iPtr);
+ Console.WriteLine("\t{0}.uiPtr = {1}", name, str1.uiPtr);
+ Console.WriteLine("\t{0}.s = {1}", name, str1.s);
+ Console.WriteLine("\t{0}.us = {1}", name, str1.us);
+ Console.WriteLine("\t{0}.b = {1}", name, str1.b);
+ Console.WriteLine("\t{0}.sb = {1}", name, str1.sb);
+ Console.WriteLine("\t{0}.l = {1}", name, str1.l);
+ Console.WriteLine("\t{0}.ul = {1}", name, str1.ul);
+ Console.WriteLine("\t{0}.f = {1}", name, str1.f);
+ Console.WriteLine("\t{0}.d = {1}", name, str1.d);
+ }
+
+ public static bool ValidateU(U str1, U str2, string methodName)
+ {
+ if (str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.iPtr != str2.iPtr ||
+ str1.uiPtr != str2.uiPtr || str1.s != str2.s || str1.us != str2.us ||
+ str1.b != str2.b || str1.sb != str2.sb || str1.l != str2.l || str1.ul != str2.ul ||
+ str1.f != str2.f || str1.d != str2.d)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintU(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintU(str2, str2.ToString());
+ return false;
+ }
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+
+ #endregion
+
+ #region methods for ByteStructPack2Explicit struct
+
+ public static ByteStructPack2Explicit NewByteStructPack2Explicit(byte b1, byte b2)
+ {
+ ByteStructPack2Explicit u1 = new ByteStructPack2Explicit();
+ u1.b1 = b1;
+ u1.b2 = b2;
+
+ return u1;
+ }
+
+ public static void PrintByteStructPack2Explicit(ByteStructPack2Explicit str1, string name)
+ {
+ Console.WriteLine("\t{0}.b1 = {1}", name, str1.b1);
+ Console.WriteLine("\t{0}.b2 = {1}", name, str1.b2);
+ }
+
+ public static bool ValidateByteStructPack2Explicit(ByteStructPack2Explicit str1, ByteStructPack2Explicit str2, string methodName)
+ {
+ if (str1.b1 != str2.b1 || str1.b2 != str2.b2)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintByteStructPack2Explicit(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintByteStructPack2Explicit(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for ShortStructPack4Explicit struct
+
+ public static ShortStructPack4Explicit NewShortStructPack4Explicit(short s1, short s2)
+ {
+ ShortStructPack4Explicit u2 = new ShortStructPack4Explicit();
+ u2.s1 = s1;
+ u2.s2 = s2;
+
+ return u2;
+ }
+
+ public static void PrintShortStructPack4Explicit(ShortStructPack4Explicit str1, string name)
+ {
+ Console.WriteLine("\t{0}.s1 = {1}", name, str1.s1);
+ Console.WriteLine("\t{0}.s2 = {1}", name, str1.s2);
+ }
+
+ public static bool ValidateShortStructPack4Explicit(ShortStructPack4Explicit str1, ShortStructPack4Explicit str2, string methodName)
+ {
+ if (str1.s1 != str2.s1 || str1.s2 != str2.s2)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintShortStructPack4Explicit(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintShortStructPack4Explicit(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for IntStructPack8Explicit struct
+
+ public static IntStructPack8Explicit NewIntStructPack8Explicit(int i1, int i2)
+ {
+ IntStructPack8Explicit u3 = new IntStructPack8Explicit();
+ u3.i1 = i1;
+ u3.i2 = i2;
+
+ return u3;
+ }
+
+ public static void PrintIntStructPack8Explicit(IntStructPack8Explicit str1, string name)
+ {
+ Console.WriteLine("\t{0}.i1 = {1}", name, str1.i1);
+ Console.WriteLine("\t{0}.i2 = {1}", name, str1.i2);
+ }
+
+ public static bool ValidateIntStructPack8Explicit(IntStructPack8Explicit str1, IntStructPack8Explicit str2, string methodName)
+ {
+ if (str1.i1 != str2.i1 || str1.i2 != str2.i2)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintIntStructPack8Explicit(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintIntStructPack8Explicit(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+ #region methods for LongStructPack16Explicit struct
+
+ public static LongStructPack16Explicit NewLongStructPack16Explicit(long l1, long l2)
+ {
+ LongStructPack16Explicit u4 = new LongStructPack16Explicit();
+ u4.l1 = l1;
+ u4.l2 = l2;
+
+ return u4;
+ }
+
+ public static void PrintLongStructPack16Explicit(LongStructPack16Explicit str1, string name)
+ {
+ Console.WriteLine("\t{0}.l1 = {1}", name, str1.l1);
+ Console.WriteLine("\t{0}.l2 = {1}", name, str1.l2);
+ }
+
+ public static bool ValidateLongStructPack16Explicit(LongStructPack16Explicit str1, LongStructPack16Explicit str2, string methodName)
+ {
+ if (str1.l1 != str2.l1 || str1.l2 != str2.l2)
+ {
+ Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
+ Console.WriteLine("\tThe Actual is...");
+ PrintLongStructPack16Explicit(str1, str1.ToString());
+ Console.WriteLine("\tThe Expected is...");
+ PrintLongStructPack16Explicit(str2, str2.ToString());
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("\tPASSED!");
+ return true;
+ }
+ }
+
+ #endregion
+
+}
+
+public static class TestFramework
+{
+ public static void LogInformation(string str)
+ {
+ Logging.WriteLine(str);
+ }
+ public static void LogError(string id, string msg)
+ {
+ Logging.WriteLine("ERROR!!!-" + id + ": " + msg);
+ }
+ public static void BeginScenario(string name)
+ {
+ Logging.WriteLine("Beginning scenario: " + name);
+ }
+}
+
+public static class Logging
+{
+ static TextWriter stdout = Console.Out;
+
+#if (!WIN_8_P)
+ static TextWriter loggingFile = null;
+#endif
+
+ public static void SetConsole(string fileName)
+ {
+#if (!WIN_8_P)
+ FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
+ loggingFile = new StreamWriter(fs, Encoding.Unicode);
+ Console.SetOut(loggingFile);
+#endif
+ }
+
+ public static void ResetConsole()
+ {
+#if (!WIN_8_P)
+ loggingFile.Close();
+#endif
+ Console.SetOut(stdout);
+ }
+
+ public static void WriteLine()
+ {
+ Console.WriteLine();
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(bool value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(char value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(char[] buffer)
+ {
+ Console.WriteLine(buffer);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(char[] buffer, int index, int count)
+ {
+ Console.WriteLine(new string(buffer, index, count));
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(decimal value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(double value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(float value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(int value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(uint value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(long value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(ulong value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(Object value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(String value)
+ {
+ Console.WriteLine(value);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(String format, Object arg0)
+ {
+ Console.WriteLine(format, arg0);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(String format, Object arg0, Object arg1)
+ {
+ Console.WriteLine(format, arg0, arg1);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(String format, Object arg0, Object arg1, Object arg2)
+ {
+ Console.WriteLine(format, arg0, arg1, arg2);
+ Console.Out.Flush();
+ }
+
+ public static void WriteLine(String format, params Object[] arg)
+ {
+ Console.WriteLine(format, arg);
+ Console.Out.Flush();
+ }
+
+ public static void Write(String format, Object arg0)
+ {
+ Console.Write(format, arg0);
+ Console.Out.Flush();
+ }
+
+ public static void Write(String format, Object arg0, Object arg1)
+ {
+ Console.Write(format, arg0, arg1);
+ Console.Out.Flush();
+ }
+
+ public static void Write(String format, Object arg0, Object arg1, Object arg2)
+ {
+ Console.Write(format, arg0, arg1, arg2);
+ Console.Out.Flush();
+ }
+
+ public static void Write(String format, params Object[] arg)
+ {
+ Console.Write(format, arg);
+ Console.Out.Flush();
+ }
+
+ public static void Write(bool value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(char value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(char[] buffer)
+ {
+ Console.Write(buffer);
+ Console.Out.Flush();
+ }
+
+#if (!WIN_8_P)
+ public static void Write(char[] buffer, int index, int count)
+ {
+ Console.Write(buffer, index, count);
+ Console.Out.Flush();
+ }
+#endif
+
+ public static void Write(double value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(decimal value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(float value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(int value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(uint value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(long value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(ulong value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(Object value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+ public static void Write(String value)
+ {
+ Console.Write(value);
+ Console.Out.Flush();
+ }
+
+}
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/CMakeLists.txt b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/CMakeLists.txt
new file mode 100644
index 0000000000..7278b94877
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/CMakeLists.txt
@@ -0,0 +1,13 @@
+
+cmake_minimum_required (VERSION 2.6)
+project (ReversePInvokeNative)
+include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake")
+include_directories(${INC_PLATFORM_DIR})
+set(SOURCES
+ ExpStructAsParamNative.cpp
+)
+# add the executable
+add_library (ReversePInvokeNative SHARED ${SOURCES})
+target_link_libraries(ReversePInvokeNative ${LINK_LIBRARIES_ADDITIONAL})
+# add the install targets
+install (TARGETS ReversePInvokeNative DESTINATION bin)
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/DelegatePInvoke/DelegatePInvokeTest.cs b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/DelegatePInvoke/DelegatePInvokeTest.cs
new file mode 100644
index 0000000000..a76dd892fc
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/DelegatePInvoke/DelegatePInvokeTest.cs
Binary files differ
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/DelegatePInvoke/DelegatePInvokeTest.csproj b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/DelegatePInvoke/DelegatePInvokeTest.csproj
new file mode 100644
index 0000000000..5bece63f96
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/DelegatePInvoke/DelegatePInvokeTest.csproj
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>DelegatePInvokeTest</AssemblyName>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\..\</SolutionDir>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <!-- Test unsupported outside of windows -->
+ <TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows>
+ <DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="DelegatePInvokeTest.cs" />
+ <Compile Include="..\..\Helper.cs" />
+ <Compile Include="..\..\Struct.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\CMakeLists.txt" />
+ </ItemGroup>
+ <Import Project="../../../../Interop.settings.targets" />
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.cpp b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.cpp
new file mode 100644
index 0000000000..ad1d0c83a5
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.cpp
@@ -0,0 +1,1606 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "ExpStructAsParamNative.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <xplatform.h>
+
+const char* NativeStr = "Native";
+const size_t size=strlen(NativeStr);
+
+#define PRINT_ERR_INFO() \
+ printf("\t%s : unexpected error \n",__FUNCTION__)
+
+//----------method called byref----------//
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefINNER2_Cdecl(INNER2* inner)
+{
+ if(!IsCorrectINNER2(inner))
+ {
+ PRINT_ERR_INFO();
+ PrintINNER2(inner,"inner");
+ return FALSE;
+ }
+ ChangeINNER2(inner);
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefINNER2_Stdcall(INNER2* inner)
+{
+ if(!IsCorrectINNER2(inner))
+ {
+ PRINT_ERR_INFO();
+ PrintINNER2(inner,"inner");
+ return FALSE;
+ }
+ ChangeINNER2(inner);
+ return TRUE;
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefInnerExplicit_Cdecl(InnerExplicit* inner)
+{
+ if(inner->f1 != 1 || memcmp(inner->f3, "some string",11*sizeof(char)) != 0)
+ {
+ PRINT_ERR_INFO();
+ PrintInnerExplicit(inner,"inner");
+ return FALSE;
+ }
+ ChangeInnerExplicit(inner);
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefInnerExplicit_Stdcall(InnerExplicit* inner)
+{
+ if(inner->f1 != 1 || memcmp(inner->f3, "some string",11*sizeof(char)) != 0)
+ {
+ PRINT_ERR_INFO();
+ PrintInnerExplicit(inner,"inner");
+ return FALSE;
+ }
+ ChangeInnerExplicit(inner);
+ return TRUE;
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Cdecl(InnerArrayExplicit* outer2)
+{
+ for(int i = 0;i<NumArrElements;i++)
+ {
+ if(outer2->arr[i].f1 != 1)
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+ }
+ if(memcmp(outer2->f4,"some string2",12) != 0)
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+ for(int i =0;i<NumArrElements;i++)
+ {
+ outer2->arr[i].f1 = 77;
+ }
+ const char* temp = "change string2";
+ size_t len = strlen(temp);
+ LPCSTR str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ strcpy_s((char*)str,len+1,temp);
+ outer2->f4 = str;
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Stdcall(InnerArrayExplicit* outer2)
+{
+ for(int i = 0;i<NumArrElements;i++)
+ {
+ if(outer2->arr[i].f1 != 1)
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+ }
+ if(memcmp(outer2->f4,"some string2",12) != 0)
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+ for(int i =0;i<NumArrElements;i++)
+ {
+ outer2->arr[i].f1 = 77;
+ }
+ const char* temp = "change string2";
+ size_t len = strlen(temp);
+ LPCSTR str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ strcpy_s((char*)str,len+1,temp);
+ outer2->f4 = str;
+ return TRUE;
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefOUTER3_Cdecl(OUTER3* outer3)
+{
+ if(!IsCorrectOUTER3(outer3))
+ {
+ PRINT_ERR_INFO();
+ PrintOUTER3(outer3,"OUTER3");
+ return FALSE;
+ }
+ ChangeOUTER3(outer3);
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefOUTER3_Stdcall(OUTER3* outer3)
+{
+ if(!IsCorrectOUTER3(outer3))
+ {
+ PRINT_ERR_INFO();
+ PrintOUTER3(outer3,"OUTER3");
+ return FALSE;
+ }
+ ChangeOUTER3(outer3);
+ return TRUE;
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefU_Cdecl(U* str1)
+{
+ if(!IsCorrectU(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintU(str1, "str1");
+ return FALSE;
+ }
+ ChangeU(str1);
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefU_Stdcall(U* str1)
+{
+ if(!IsCorrectU(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintU(str1, "str1");
+ return FALSE;
+ }
+ ChangeU(str1);
+ return TRUE;
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Cdecl(ByteStructPack2Explicit* str1)
+{
+ if(!IsCorrectByteStructPack2Explicit(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintByteStructPack2Explicit(str1, "str1");
+ return FALSE;
+ }
+ ChangeByteStructPack2Explicit(str1);
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Stdcall(ByteStructPack2Explicit* str1)
+{
+ if(!IsCorrectByteStructPack2Explicit(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintByteStructPack2Explicit(str1, "str1");
+ return FALSE;
+ }
+ ChangeByteStructPack2Explicit(str1);
+ return TRUE;
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Cdecl(ShortStructPack4Explicit* str1)
+{
+ if(!IsCorrectShortStructPack4Explicit(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintShortStructPack4Explicit(str1, "str1");
+ return FALSE;
+ }
+ ChangeShortStructPack4Explicit(str1);
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Stdcall(ShortStructPack4Explicit* str1)
+{
+ if(!IsCorrectShortStructPack4Explicit(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintShortStructPack4Explicit(str1, "str1");
+ return FALSE;
+ }
+ ChangeShortStructPack4Explicit(str1);
+ return TRUE;
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Cdecl(IntStructPack8Explicit* str1)
+{
+ if(!IsCorrectIntStructPack8Explicit(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintIntStructPack8Explicit(str1, "str1");
+ return FALSE;
+ }
+ ChangeIntStructPack8Explicit(str1);
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Stdcall(IntStructPack8Explicit* str1)
+{
+ if(!IsCorrectIntStructPack8Explicit(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintIntStructPack8Explicit(str1, "str1");
+ return FALSE;
+ }
+ ChangeIntStructPack8Explicit(str1);
+ return TRUE;
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Cdecl(LongStructPack16Explicit* str1)
+{
+ if(!IsCorrectLongStructPack16Explicit(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintLongStructPack16Explicit(str1, "str1");
+ return FALSE;
+ }
+ ChangeLongStructPack16Explicit(str1);
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Stdcall(LongStructPack16Explicit* str1)
+{
+ if(!IsCorrectLongStructPack16Explicit(str1))
+ {
+ PRINT_ERR_INFO();
+ PrintLongStructPack16Explicit(str1, "str1");
+ return FALSE;
+ }
+ ChangeLongStructPack16Explicit(str1);
+ return TRUE;
+}
+/////
+//---------------------------- ----------//
+
+
+//----------method called byval----------//
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValINNER2_Cdecl(INNER2 str1)
+{
+ return MarshalStructAsParam_AsExpByRefINNER2_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValINNER2_Stdcall(INNER2 str1)
+{
+ return MarshalStructAsParam_AsExpByRefINNER2_Stdcall(&str1);
+}
+/////
+
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValInnerExplicit_Cdecl(InnerExplicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefInnerExplicit_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValInnerExplicit_Stdcall(InnerExplicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefInnerExplicit_Stdcall(&str1);
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValInnerArrayExplicit_Cdecl(InnerArrayExplicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValInnerArrayExplicit_Stdcall(InnerArrayExplicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Stdcall(&str1);
+}
+/////
+
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValOUTER3_Cdecl(OUTER3 str1)
+{
+ return MarshalStructAsParam_AsExpByRefOUTER3_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValOUTER3_Stdcall(OUTER3 str1)
+{
+ return MarshalStructAsParam_AsExpByRefOUTER3_Stdcall( &str1);
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValU_Cdecl(U str1)
+{
+ return MarshalStructAsParam_AsExpByRefU_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValU_Stdcall(U str1)
+{
+ return MarshalStructAsParam_AsExpByRefU_Stdcall(&str1);
+}
+/////
+
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Cdecl(ByteStructPack2Explicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Stdcall(ByteStructPack2Explicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Stdcall(&str1);
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Cdecl(ShortStructPack4Explicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Stdcall(ShortStructPack4Explicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Stdcall(&str1);
+}
+/////
+
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Cdecl(IntStructPack8Explicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Stdcall(IntStructPack8Explicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Stdcall(&str1);
+}
+
+/////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Cdecl(LongStructPack16Explicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Cdecl(&str1);
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Stdcall(LongStructPack16Explicit str1)
+{
+ return MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Stdcall(&str1);
+}
+/////
+//---------------------------- ----------//
+
+
+//----------Delegate Pinvoke. PassByRef----------//
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_INNER2)(INNER2* inner);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_INNER2 _cdecl Get_MarshalStructAsParam_AsExpByRefINNER2_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefINNER2_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_INNER2)(INNER2* inner);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_INNER2 __stdcall Get_MarshalStructAsParam_AsExpByRefINNER2_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefINNER2_Stdcall;
+}
+/////
+
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_InnerExplicit)(InnerExplicit* ie);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_InnerExplicit _cdecl Get_MarshalStructAsParam_AsExpByRefInnerExplicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefInnerExplicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_InnerExplicit)(InnerExplicit* ie);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_InnerExplicit __stdcall Get_MarshalStructAsParam_AsExpByRefInnerExplicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefInnerExplicit_Stdcall;
+}
+
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_InnerArrayExplicit)(InnerArrayExplicit* iae);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_InnerArrayExplicit _cdecl Get_MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_InnerArrayExplicit)(InnerArrayExplicit* iae);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_InnerArrayExplicit __stdcall Get_MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Stdcall;
+}
+/////
+
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_OUTER3)(OUTER3* outer);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_OUTER3 _cdecl Get_MarshalStructAsParam_AsExpByRefOUTER3_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefOUTER3_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_OUTER3)(OUTER3* outer);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_OUTER3 __stdcall Get_MarshalStructAsParam_AsExpByRefOUTER3_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefOUTER3_Stdcall;
+}
+
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_U)(U* inner);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_U _cdecl Get_MarshalStructAsParam_AsExpByRefU_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefU_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_U)(U* inner);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_U __stdcall Get_MarshalStructAsParam_AsExpByRefU_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefU_Stdcall;
+}
+/////
+
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_ByteStructPack2Explicit)(ByteStructPack2Explicit* bspe);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_ByteStructPack2Explicit _cdecl Get_MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_ByteStructPack2Explicit)(ByteStructPack2Explicit* bspe);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_ByteStructPack2Explicit __stdcall Get_MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Stdcall;
+}
+
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_ShortStructPack4Explicit)(ShortStructPack4Explicit* sspe);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_ShortStructPack4Explicit _cdecl Get_MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_ShortStructPack4Explicit)(ShortStructPack4Explicit* sspe);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_ShortStructPack4Explicit __stdcall Get_MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Stdcall;
+}
+/////
+
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_IntStructPack8Explicit)(IntStructPack8Explicit* ispe);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_IntStructPack8Explicit _cdecl Get_MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_IntStructPack8Explicit)(IntStructPack8Explicit* ispe);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_IntStructPack8Explicit __stdcall Get_MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Stdcall;
+}
+
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByRefCdeclCaller_LongStructPack16Explicit)(LongStructPack16Explicit* ispe);
+extern "C" DLL_EXPORT DelegatePinvokeByRefCdeclCaller_LongStructPack16Explicit _cdecl Get_MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByRefStdcallCaller_LongStructPack16Explicit)(LongStructPack16Explicit* ispe);
+extern "C" DLL_EXPORT DelegatePinvokeByRefStdcallCaller_LongStructPack16Explicit __stdcall Get_MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Stdcall;
+}
+/////
+//---------------------------- ----------//
+
+
+//----------Delegate Pinvoke. PassByVal----------//
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_INNER2)(INNER2 inner);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_INNER2 _cdecl Get_MarshalStructAsParam_AsExpByValINNER2_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValINNER2_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_INNER2)(INNER2 inner);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_INNER2 __stdcall Get_MarshalStructAsParam_AsExpByValINNER2_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValINNER2_Stdcall;
+}
+/////
+
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_InnerExplicit)(InnerExplicit ie);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_InnerExplicit _cdecl Get_MarshalStructAsParam_AsExpByValInnerExplicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValInnerExplicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_InnerExplicit)(InnerExplicit ie);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_InnerExplicit __stdcall Get_MarshalStructAsParam_AsExpByValInnerExplicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValInnerExplicit_Stdcall;
+}
+
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_InnerArrayExplicit)(InnerArrayExplicit iae);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_InnerArrayExplicit _cdecl Get_MarshalStructAsParam_AsExpByValInnerArrayExplicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValInnerArrayExplicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_InnerArrayExplicit)(InnerArrayExplicit iae);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_InnerArrayExplicit __stdcall Get_MarshalStructAsParam_AsExpByValInnerArrayExplicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValInnerArrayExplicit_Stdcall;
+}
+/////
+
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_OUTER3)(OUTER3 outer);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_OUTER3 _cdecl Get_MarshalStructAsParam_AsExpByValOUTER3_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValOUTER3_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_OUTER3)(OUTER3 outer);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_OUTER3 __stdcall Get_MarshalStructAsParam_AsExpByValOUTER3_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValOUTER3_Stdcall;
+}
+
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_U)(U inner);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_U _cdecl Get_MarshalStructAsParam_AsExpByValU_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValU_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_U)(U inner);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_U __stdcall Get_MarshalStructAsParam_AsExpByValU_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValU_Stdcall;
+}
+/////
+
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_ByteStructPack2Explicit)(ByteStructPack2Explicit bspe);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_ByteStructPack2Explicit _cdecl Get_MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_ByteStructPack2Explicit)(ByteStructPack2Explicit bspe);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_ByteStructPack2Explicit __stdcall Get_MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Stdcall;
+}
+
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_ShortStructPack4Explicit)(ShortStructPack4Explicit sspe);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_ShortStructPack4Explicit _cdecl Get_MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_ShortStructPack4Explicit)(ShortStructPack4Explicit sspe);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_ShortStructPack4Explicit __stdcall Get_MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Stdcall;
+}
+/////
+
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_IntStructPack8Explicit)(IntStructPack8Explicit ispe);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_IntStructPack8Explicit _cdecl Get_MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_IntStructPack8Explicit)(IntStructPack8Explicit ispe);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_IntStructPack8Explicit __stdcall Get_MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Stdcall;
+}
+
+/////
+typedef BOOL(_cdecl *DelegatePinvokeByValCdeclCaller_LongStructPack16Explicit)(LongStructPack16Explicit ispe);
+extern "C" DLL_EXPORT DelegatePinvokeByValCdeclCaller_LongStructPack16Explicit _cdecl Get_MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Cdecl_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Cdecl;
+}
+
+typedef BOOL(__stdcall *DelegatePinvokeByValStdcallCaller_LongStructPack16Explicit)(LongStructPack16Explicit ispe);
+extern "C" DLL_EXPORT DelegatePinvokeByValStdcallCaller_LongStructPack16Explicit __stdcall Get_MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Stdcall_FuncPtr()
+{
+ return MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Stdcall;
+}
+/////
+//---------------------------- ----------//
+
+
+//----------Reverse Pinvoke. PassByRef----------//
+/////
+typedef BOOL (_cdecl *ByRefCdeclCaller_INNER2)(INNER2* inner2);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_INNER2(ByRefCdeclCaller_INNER2 caller)
+{
+ //init
+ INNER2 inner2;
+ inner2.f1 = 77;
+ inner2.f2 = 77.0;
+
+ char* pstr = GetNativeString();
+ inner2.f3 = pstr;
+
+ if(!caller(&inner2))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if(!IsCorrectINNER2(&inner2))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ //TP_CoreClrFree((void*)inner2.f3);
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_INNER2)(INNER2* inner2);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_INNER2(ByRefStdcallCaller_INNER2 caller)
+{
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+
+ //init
+ INNER2 inner2;
+ inner2.f1 = 77;
+ inner2.f2 = 77.0;
+
+ char* pstr = (char*)CoreClrAlloc(lsize + 1);
+ memset(pstr,0,lsize+1);
+ strncpy_s(pstr,lsize+1,lNativeStr,lsize);
+
+ inner2.f3 = pstr;
+
+ if(!caller(&inner2))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if(!IsCorrectINNER2(&inner2))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ //TP_CoreClrFree((void*)inner2.f3);
+ return TRUE;
+}
+/////
+
+typedef BOOL (_cdecl *ByRefCdeclCaller_InnerExplicit)(InnerExplicit* inner2);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_InnerExplicit(ByRefCdeclCaller_InnerExplicit caller)
+{
+
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+
+ //init
+ InnerExplicit ie;
+ ie.f1 = 77;
+
+ char* pstr = (char*)CoreClrAlloc(lsize + 1);
+ memset(pstr,0,lsize+1);
+ strncpy_s(pstr,lsize+1,lNativeStr,lsize);
+ ie.f3 = pstr;
+
+ if(!caller(&ie))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( ie.f1 != 1 || 0 != strcmp((char*)ie.f3, "some string") )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_InnerExplicit)(InnerExplicit* inner2);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_InnerExplicit(ByRefStdcallCaller_InnerExplicit caller)
+{
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+
+ //init
+ InnerExplicit ie;
+ ie.f1 = 77;
+
+ char* pstr = (char*)CoreClrAlloc(lsize + 1);
+ memset(pstr,0,lsize+1);
+ strncpy_s(pstr,lsize+1,lNativeStr,lsize);
+ ie.f3 = pstr;
+
+ if(!caller(&ie))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( ie.f1 != 1 || 0 != strcmp((char*)ie.f3, "some string") )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/////
+typedef BOOL (_cdecl *ByRefCdeclCaller_InnerArrayExplicit)(InnerArrayExplicit* iae);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_InnerArrayExplicit(ByRefCdeclCaller_InnerArrayExplicit caller)
+{
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+
+ //init
+ InnerArrayExplicit iae;
+ LPSTR str = NULL;
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ iae.arr[i].f1 = 77;
+ str = (LPSTR)CoreClrAlloc( lsize+1 );
+ memset(str,0,lsize+1);
+ strncpy_s((char*)str,lsize+1,lNativeStr,lsize);
+
+ iae.arr[i].f3 = str;
+ str = NULL;
+ }
+
+ str = (LPSTR)CoreClrAlloc( lsize+1 );
+ memset(str,0,lsize+1);
+ strncpy_s((char*)str,lsize+1,lNativeStr,lsize);
+ iae.f4 = str;
+
+ if(!caller(&iae))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ if( iae.arr[i].f1 != 1 || 0 != strcmp((char*)iae.arr[i].f3, "some string"))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+ }
+ if( 0 != strcmp((char*)iae.f4, "some string") )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_InnerArrayExplicit)(InnerArrayExplicit* iae);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_InnerArrayExplicit(ByRefStdcallCaller_InnerArrayExplicit caller)
+{
+ //init
+ InnerArrayExplicit iae;
+ LPSTR str = NULL;
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ iae.arr[i].f1 = 77;
+ str = GetNativeString();
+ iae.arr[i].f3 = str;
+ str = NULL;
+ }
+
+ str = GetNativeString();
+ iae.f4 = str;
+
+ if(!caller(&iae))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ if( iae.arr[i].f1 != 1 || 0 != strcmp((char*)iae.arr[i].f3, "some string"))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+ }
+ if( 0 != strcmp((char*)iae.f4, "some string") )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+
+typedef BOOL (_cdecl *ByRefCdeclCaller_OUTER3)(OUTER3* outer3);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_OUTER3(ByRefCdeclCaller_OUTER3 caller)
+{
+ //init
+ OUTER3 outer3;
+ LPSTR str = NULL;
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ outer3.arr[i].f1 = 77;
+ outer3.arr[i].f2 = 77.0;
+ str = GetNativeString();
+ outer3.arr[i].f3 = (LPCSTR)str;
+ str = NULL;
+ }
+
+ str = GetNativeString();
+ outer3.f4 = (LPCSTR)str;
+
+ if(!caller(&outer3))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectOUTER3( &outer3 ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_OUTER3)(OUTER3* outer3);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_OUTER3(ByRefStdcallCaller_OUTER3 caller)
+{
+
+ //init
+ OUTER3 outer3;
+ LPSTR str = NULL;
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ outer3.arr[i].f1 = 77;
+ outer3.arr[i].f2 = 77.0;
+ str = GetNativeString();
+ outer3.arr[i].f3 = (LPCSTR)str;
+ str = NULL;
+ }
+
+ str = GetNativeString();
+ outer3.f4 = (LPCSTR)str;
+
+ if(!caller(&outer3))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectOUTER3( &outer3 ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/////
+typedef BOOL (_cdecl *ByRefCdeclCaller_U)(U* u);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_U(ByRefCdeclCaller_U caller)
+{
+ U u;
+ u.d = 1.23;
+
+ if(!caller(&u))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectU( &u ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_U)(U* u);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_U(ByRefStdcallCaller_U caller)
+{
+ U u;
+ u.d = 1.23;
+
+ if(!caller(&u))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectU( &u ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+
+typedef BOOL (_cdecl *ByRefCdeclCaller_ByteStructPack2Explicit)(ByteStructPack2Explicit* bspe);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_ByteStructPack2Explicit(ByRefCdeclCaller_ByteStructPack2Explicit caller)
+{
+ ByteStructPack2Explicit bspe;
+ bspe.b1 = 64;
+ bspe.b2 = 64;
+
+ if(!caller(&bspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectByteStructPack2Explicit( &bspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_ByteStructPack2Explicit)(ByteStructPack2Explicit* bspe);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_ByteStructPack2Explicit(ByRefStdcallCaller_ByteStructPack2Explicit caller)
+{
+ ByteStructPack2Explicit bspe;
+ bspe.b1 = 64;
+ bspe.b2 = 64;
+
+ if(!caller(&bspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectByteStructPack2Explicit( &bspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/////
+typedef BOOL (_cdecl *ByRefCdeclCaller_ShortStructPack4Explicit)(ShortStructPack4Explicit* sspe);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_ShortStructPack4Explicit(ByRefCdeclCaller_ShortStructPack4Explicit caller)
+{
+ ShortStructPack4Explicit sspe;
+ sspe.s1 = 64;
+ sspe.s2 = 64;
+
+ if(!caller(&sspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectShortStructPack4Explicit( &sspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_ShortStructPack4Explicit)(ShortStructPack4Explicit* sspe);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_ShortStructPack4Explicit(ByRefStdcallCaller_ShortStructPack4Explicit caller)
+{
+ ShortStructPack4Explicit sspe;
+ sspe.s1 = 64;
+ sspe.s2 = 64;
+
+ if(!caller(&sspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectShortStructPack4Explicit( &sspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+
+typedef BOOL (_cdecl *ByRefCdeclCaller_IntStructPack8Explicit)(IntStructPack8Explicit* ispe);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_IntStructPack8Explicit(ByRefCdeclCaller_IntStructPack8Explicit caller)
+{
+ IntStructPack8Explicit ispe;
+ ispe.i1 = 64;
+ ispe.i2 = 64;
+
+ if(!caller(&ispe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectIntStructPack8Explicit( &ispe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_IntStructPack8Explicit)(IntStructPack8Explicit* ispe);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_IntStructPack8Explicit(ByRefStdcallCaller_IntStructPack8Explicit caller)
+{
+ IntStructPack8Explicit ispe;
+ ispe.i1 = 64;
+ ispe.i2 = 64;
+
+ if(!caller(&ispe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectIntStructPack8Explicit( &ispe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/////
+typedef BOOL (_cdecl *ByRefCdeclCaller_LongStructPack16Explicit)(LongStructPack16Explicit* lspe);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_LongStructPack16Explicit(ByRefCdeclCaller_LongStructPack16Explicit caller)
+{
+ LongStructPack16Explicit lspe;
+ lspe.l1 = 64;
+ lspe.l2 = 64;
+
+ if(!caller(&lspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectLongStructPack16Explicit( &lspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByRefStdcallCaller_LongStructPack16Explicit)(LongStructPack16Explicit* lspe);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_LongStructPack16Explicit(ByRefStdcallCaller_LongStructPack16Explicit caller)
+{
+ LongStructPack16Explicit lspe;
+ lspe.l1 = 64;
+ lspe.l2 = 64;
+
+ if(!caller(&lspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectLongStructPack16Explicit( &lspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+//---------------------------- ----------//
+
+
+//----------Reverse Pinvoke. PassByVal---------//
+/////
+typedef BOOL (_cdecl *ByValCdeclCaller_INNER2)(INNER2 inner2);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_INNER2(ByValCdeclCaller_INNER2 caller)
+{
+ //init
+ INNER2 inner2;
+ inner2.f1 = 1;
+ inner2.f2 = 1.0;
+
+ char* pstr = GetSomeString();
+ inner2.f3 = pstr;
+
+ if(!caller(inner2))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if(!IsCorrectINNER2(&inner2))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_INNER2)(INNER2 inner2);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_INNER2(ByValStdcallCaller_INNER2 caller)
+{
+ //init
+ INNER2 inner2;
+ inner2.f1 = 1;
+ inner2.f2 = 1.0;
+
+ char* pstr = GetSomeString();
+ inner2.f3 = pstr;
+
+ if(!caller(inner2))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if(!IsCorrectINNER2(&inner2))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+
+typedef BOOL (_cdecl *ByValCdeclCaller_InnerExplicit)(InnerExplicit inner2);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_InnerExplicit(ByValCdeclCaller_InnerExplicit caller)
+{
+ //init
+ InnerExplicit ie;
+ ie.f1 = 1;
+
+ char* pstr = GetNativeString();
+ ie.f3 = pstr;
+
+ if(!caller(ie))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( ie.f1 != 1 || 0 != strcmp((char*)ie.f3, (char*)NativeStr) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_InnerExplicit)(InnerExplicit inner2);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_InnerExplicit(ByValStdcallCaller_InnerExplicit caller)
+{
+ //init
+ InnerExplicit ie;
+ ie.f1 = 1;
+
+ char* pstr = GetNativeString();
+ ie.f3 = pstr;
+
+ if(!caller(ie))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( ie.f1 != 1 || 0 != strcmp((char*)ie.f3, (char*)NativeStr) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/////
+typedef BOOL (_cdecl *ByValCdeclCaller_InnerArrayExplicit)(InnerArrayExplicit iae);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_InnerArrayExplicit(ByValCdeclCaller_InnerArrayExplicit caller)
+{
+ //init
+ InnerArrayExplicit iae;
+ LPSTR str = NULL;
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ iae.arr[i].f1 = 1;
+ str = GetSomeString();
+ iae.arr[i].f3 = str;
+ str = NULL;
+ }
+
+ str = GetSomeString();
+ iae.f4 = str;
+
+ if(!caller(iae))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ if( iae.arr[i].f1 != 1 || 0 != strcmp((char*)iae.arr[i].f3, "some string"))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+ }
+ if( 0 != strcmp((char*)iae.f4, "some string") )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_InnerArrayExplicit)(InnerArrayExplicit iae);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_InnerArrayExplicit(ByValStdcallCaller_InnerArrayExplicit caller)
+{
+ //init
+ InnerArrayExplicit iae;
+ LPSTR str = NULL;
+
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ iae.arr[i].f1 = 1;
+
+ str = GetSomeString();
+ iae.arr[i].f3 = str;
+ str = NULL;
+ }
+
+ str = GetSomeString();
+ iae.f4 = str;
+
+ if(!caller(iae))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ if( iae.arr[i].f1 != 1 || 0 != strcmp((char*)iae.arr[i].f3, "some string"))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+ }
+ if( 0 != strcmp((char*)iae.f4, "some string") )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+
+typedef BOOL (_cdecl *ByValCdeclCaller_OUTER3)(OUTER3 outer3);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_OUTER3(ByValCdeclCaller_OUTER3 caller)
+{
+ //init
+ OUTER3 outer3;
+ LPSTR str = NULL;
+
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ outer3.arr[i].f1 = 1;
+ outer3.arr[i].f2 = 1.0;
+ str = GetSomeString();
+ outer3.arr[i].f3 = (LPCSTR)str;
+ str = NULL;
+ }
+
+ str = GetSomeString();
+ outer3.f4 = (LPCSTR)str;
+
+ if(!caller(outer3))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectOUTER3( &outer3 ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_OUTER3)(OUTER3 outer3);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_OUTER3(ByValStdcallCaller_OUTER3 caller)
+{
+ //init
+ OUTER3 outer3;
+ LPSTR str = NULL;
+ for( size_t i = 0; i < NumArrElements; i++ )
+ {
+ outer3.arr[i].f1 = 1;
+ outer3.arr[i].f2 = 1.0;
+ str = GetSomeString();
+ outer3.arr[i].f3 = (LPCSTR)str;
+ str = NULL;
+ }
+
+ str = GetSomeString();
+ outer3.f4 = (LPCSTR)str;
+
+ if(!caller(outer3))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectOUTER3( &outer3 ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/////
+typedef BOOL (_cdecl *ByValCdeclCaller_U)(U u);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_U(ByValCdeclCaller_U caller)
+{
+ U u;
+ u.d = 3.2;
+
+ if(!caller(u))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectU( &u ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_U)(U u);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_U(ByValStdcallCaller_U caller)
+{
+ U u;
+ u.d = 3.2;
+
+ if(!caller(u))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectU( &u ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+
+typedef BOOL (_cdecl *ByValCdeclCaller_ByteStructPack2Explicit)(ByteStructPack2Explicit bspe);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_ByteStructPack2Explicit(ByValCdeclCaller_ByteStructPack2Explicit caller)
+{
+ ByteStructPack2Explicit bspe;
+ bspe.b1 = 32;
+ bspe.b2 = 32;
+
+ if(!caller(bspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectByteStructPack2Explicit( &bspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_ByteStructPack2Explicit)(ByteStructPack2Explicit bspe);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_ByteStructPack2Explicit(ByValStdcallCaller_ByteStructPack2Explicit caller)
+{
+ ByteStructPack2Explicit bspe;
+ bspe.b1 = 32;
+ bspe.b2 = 32;
+
+ if(!caller(bspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectByteStructPack2Explicit( &bspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/////
+typedef BOOL (_cdecl *ByValCdeclCaller_ShortStructPack4Explicit)(ShortStructPack4Explicit sspe);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_ShortStructPack4Explicit(ByValCdeclCaller_ShortStructPack4Explicit caller)
+{
+ ShortStructPack4Explicit sspe;
+ sspe.s1 = 32;
+ sspe.s2 = 32;
+
+ if(!caller(sspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectShortStructPack4Explicit( &sspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_ShortStructPack4Explicit)(ShortStructPack4Explicit sspe);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_ShortStructPack4Explicit(ByValStdcallCaller_ShortStructPack4Explicit caller)
+{
+ ShortStructPack4Explicit sspe;
+ sspe.s1 = 32;
+ sspe.s2 = 32;
+
+ if(!caller(sspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectShortStructPack4Explicit( &sspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+
+typedef BOOL (_cdecl *ByValCdeclCaller_IntStructPack8Explicit)(IntStructPack8Explicit ispe);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_IntStructPack8Explicit(ByValCdeclCaller_IntStructPack8Explicit caller)
+{
+ IntStructPack8Explicit ispe;
+ ispe.i1 = 32;
+ ispe.i2 = 32;
+
+ if(!caller(ispe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectIntStructPack8Explicit( &ispe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_IntStructPack8Explicit)(IntStructPack8Explicit ispe);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_IntStructPack8Explicit(ByValStdcallCaller_IntStructPack8Explicit caller)
+{
+ IntStructPack8Explicit ispe;
+ ispe.i1 = 32;
+ ispe.i2 = 32;
+
+ if(!caller(ispe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectIntStructPack8Explicit( &ispe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/////
+typedef BOOL (_cdecl *ByValCdeclCaller_LongStructPack16Explicit)(LongStructPack16Explicit lspe);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByValStruct_Cdecl_LongStructPack16Explicit(ByValCdeclCaller_LongStructPack16Explicit caller)
+{
+ LongStructPack16Explicit lspe;
+ lspe.l1 = 32;
+ lspe.l2 = 32;
+
+ if(!caller(lspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectLongStructPack16Explicit( &lspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ByValStdcallCaller_LongStructPack16Explicit)(LongStructPack16Explicit lspe);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_LongStructPack16Explicit(ByValStdcallCaller_LongStructPack16Explicit caller)
+{
+ LongStructPack16Explicit lspe;
+ lspe.l1 = 32;
+ lspe.l2 = 32;
+
+ if(!caller(lspe))
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ if( !IsCorrectLongStructPack16Explicit( &lspe ) )
+ {
+ PRINT_ERR_INFO();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+/////
+//---------------------------- ----------//
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.h b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.h
new file mode 100644
index 0000000000..cde3b524d0
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.h
@@ -0,0 +1,919 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <xplatform.h>
+#include "platformdefines.h"
+
+const int NumArrElements = 2;
+struct InnerSequential
+{
+ int f1;
+ float f2;
+ LPCSTR f3;
+};
+
+void PrintInnerSequential(InnerSequential* p, const char* name)
+{
+ printf("\t%s.f1 = %d\n", name, p->f1);
+ printf("\t%s.f2 = %f\n", name, p->f2);
+ printf("\t%s.f3 = %s\n", name, p->f3);
+}
+
+void ChangeInnerSequential(InnerSequential* p)
+{
+ p->f1 = 77;
+ p->f2 = 77.0;
+
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strncpy_s((char*)temp,size,lpstr,size-1);
+ p->f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+}
+
+bool IsCorrectInnerSequential(InnerSequential* p)
+{
+ if(p->f1 != 1)
+ return false;
+ if(p->f2 != 1.0)
+ return false;
+ if(strcmp((char*)p->f3,"some string") != 0 )
+ return false;
+
+ return true;
+}
+
+struct INNER2 // size = 12 bytes
+{
+ INT f1;
+ FLOAT f2;
+ LPCSTR f3;
+};
+
+void ChangeINNER2(INNER2* p)
+{
+ p->f1 = 77;
+ p->f2 = 77.0;
+ const char* temp = "changed string";
+ size_t len = strlen(temp);
+ LPCSTR str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ memset((LPVOID)str,0,len+1);
+ strncpy_s((char*)str,len+1,temp,len);
+ p->f3 = str;
+}
+
+void PrintINNER2(INNER2* p, const char* name)
+{
+ printf("\t%s.f1 = %d\n", name, p->f1);
+ printf("\t%s.f2 = %f\n", name, p->f2);
+ printf("\t%s.f3 = %s\n", name, p->f3);
+}
+
+bool IsCorrectINNER2(INNER2* p)
+{
+ if(p->f1 != 1)
+ return false;
+ if(p->f2 != 1.0)
+ return false;
+ if(memcmp(p->f3, "some string",11*sizeof(char)) != 0 )
+ return false;
+ return true;
+}
+
+struct InnerExplicit
+{
+#ifdef WINDOWS
+ union
+ {
+ INT f1;
+ FLOAT f2;
+ };
+ CHAR _unused0[4];
+ LPCSTR f3;
+#else
+ union
+ {
+ INT f1;
+ FLOAT f2;
+ };
+ INT _unused0;
+ LPCSTR f3;
+#endif
+};
+
+
+void PrintInnerExplicit(InnerExplicit* p, const char* name)
+{
+ printf("\t%s.f1 = %d\n", name, p->f1);
+ printf("\t%s.f2 = %f\n", name, p->f2);
+ printf("\t%s.f3 = %s\n", name, p->f3);
+}
+
+void ChangeInnerExplicit(InnerExplicit* p)
+{
+ p->f1 = 77;
+
+ const char* temp = "changed string";
+ size_t len = strlen(temp);
+ LPCSTR str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ memset((LPVOID)str,0,len+1);
+ strncpy_s((char*)str,len+1,temp,len);
+ p->f3 = str;
+}
+
+struct InnerArraySequential
+{
+ InnerSequential arr[NumArrElements];
+};
+
+void PrintInnerArraySequential(InnerArraySequential* p, const char* name)
+{
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1);
+ printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2);
+ printf("\t%s.arr[%d].f2 = %s\n", name, i, (p->arr)[i].f3);
+ }
+}
+
+void ChangeInnerArraySequential(InnerArraySequential* p)
+{
+ const char* lpstr = "changed string";
+ LPSTR temp;
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ (p->arr)[i].f1 = 77;
+ (p->arr)[i].f2 = 77.0;
+
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strncpy_s((char*)temp,strlen(lpstr)+1,lpstr,strlen(lpstr));
+ (p->arr)[i].f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ }
+}
+
+bool IsCorrectInnerArraySequential(InnerArraySequential* p)
+{
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ if( (p->arr)[i].f1 != 1 )
+ return false;
+ if( (p->arr)[i].f2 != 1.0 )
+ return false;
+ }
+ return true;
+}
+
+union InnerArrayExplicit // size = 32 bytes
+{
+ struct InnerSequential arr[2];
+ struct
+ {
+ LONG64 _unused0;
+ LPCSTR f4;
+ };
+
+};
+
+#ifdef _WIN64
+union OUTER3 // size = 32 bytes
+{
+ struct InnerSequential arr[2];
+ struct
+ {
+ CHAR _unused0[24];
+ LPCSTR f4;
+ };
+};
+#else
+struct OUTER3 // size = 28 bytes
+{
+ struct InnerSequential arr[2];
+ LPCSTR f4;
+};
+#endif
+
+void PrintOUTER3(OUTER3* p, const char* name)
+{
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1);
+ printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2);
+ printf("\t%s.arr[%d].f3 = %s\n", name, i, (p->arr)[i].f3);
+ }
+ printf("\t%s.f4 = %s\n",name,p->f4);
+}
+
+void ChangeOUTER3(OUTER3* p)
+{
+ const char* temp = "changed string";
+ size_t len = strlen(temp);
+ LPCSTR str = NULL;
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ (p->arr)[i].f1 = 77;
+ (p->arr)[i].f2 = 77.0;
+
+ str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ memset((LPVOID)str,0,len+1);
+ strncpy_s((char*)str,len+1,temp,len);
+ (p->arr)[i].f3 = str;
+ }
+
+ str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ memset((LPVOID)str,0,len+1);
+ strncpy_s((char*)str,len+1,temp,len);
+ p->f4 = str;
+}
+
+bool IsCorrectOUTER3(OUTER3* p)
+{
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ if( (p->arr)[i].f1 != 1 )
+ return false;
+ if( (p->arr)[i].f2 != 1.0 )
+ return false;
+ if( memcmp((p->arr)[i].f3, "some string",11*sizeof(char)) != 0 )
+ return false;
+ }
+ if(memcmp(p->f4,"some string",11*sizeof(char)) != 0)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct CharSetAnsiSequential
+{
+ LPCSTR f1;
+ char f2;
+};
+
+void PrintCharSetAnsiSequential(CharSetAnsiSequential* p, const char* name)
+{
+ printf("\t%s.f1 = %s\n", name, p->f1);
+ printf("\t%s.f2 = %c\n", name, p->f2);
+}
+
+void ChangeCharSetAnsiSequential(CharSetAnsiSequential* p)
+{
+ const char* strSource = "change string";
+ size_t size = strlen(strSource) + 1;
+ LPSTR temp = (LPSTR)CoreClrAlloc(size);
+ if(temp != NULL)
+ {
+ memset(temp,0,size);
+ strncpy_s((char*)temp,size,strSource,size-1);
+ p->f1 = temp;
+ p->f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+}
+
+bool IsCorrectCharSetAnsiSequential(CharSetAnsiSequential* p)
+{
+ if(strcmp((char*)p->f1, (char*)"some string") != 0 )
+ return false;
+ if(p->f2 != 'c')
+ return false;
+ return true;
+}
+
+
+struct CharSetUnicodeSequential
+{
+ LPCWSTR f1;
+ WCHAR f2;
+};
+
+void PrintCharSetUnicodeSequential(CharSetUnicodeSequential* p, const char* name)
+{
+#ifdef _WIN32
+ wprintf(L"\t%S.first = %s\n", name, p->f1);
+ wprintf(L"\t%S.last = %c\n", name, p->f2);
+#else
+ wprintf(L"\t%s.first = %s\n", name, p->f1);
+ wprintf(L"\t%s.last = %c\n", name, p->f2);
+#endif
+}
+
+void ChangeCharSetUnicodeSequential(CharSetUnicodeSequential* p)
+{
+ WCHAR* strSource = (WCHAR*)(W("change string"));
+ size_t len =TP_slen(strSource);
+ LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
+ if(temp != NULL)
+ {
+ memset((LPWSTR)temp,0,len+1);
+ wcsncpy_s((WCHAR*)temp, len, strSource, len);
+ p->f1 = temp;
+ p->f2 = L'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+}
+
+bool IsCorrectCharSetUnicodeSequential(CharSetUnicodeSequential* p)
+{
+ WCHAR* expected= const_cast<WCHAR*>(W("some string"));
+ WCHAR* actual = const_cast<WCHAR*>(p->f1);
+ if(0 != TP_wcmp_s(actual, expected))
+ {
+ return false;
+ }
+ if(p->f2 != L'c')
+ {
+ return false;
+ }
+ return true;
+}
+
+struct NumberSequential // size = 64 bytes
+{
+ LONG64 i64;
+ ULONG64 ui64;
+ DOUBLE d;
+ INT i32;
+ UINT ui32;
+ SHORT s1;
+ WORD us1;
+ SHORT i16;
+ WORD ui16;
+ FLOAT sgl;
+ BYTE b;
+ CHAR sb;
+};
+
+void PrintNumberSequential(NumberSequential* str, const char* name)
+{
+ printf("\t%s.i32 = %d\n", name, str->i32);
+ printf("\t%s.ui32 = %d\n", name, str->ui32);
+ printf("\t%s.s1 = %d\n", name, str->s1);
+ printf("\t%s.us1 = %u\n", name, str->us1);
+ printf("\t%s.b = %u\n", name, str->b);
+ printf("\t%s.sb = %d\n", name, str->sb);
+ printf("\t%s.i16 = %d\n", name, str->i16);
+ printf("\t%s.ui16 = %u\n", name, str->ui16);
+ printf("\t%s.i64 = %lld\n", name, str->i64);
+ printf("\t%s.ui64 = %llu\n", name, str->ui64);
+ printf("\t%s.sgl = %f\n", name, str->sgl);
+ printf("\t%s.d = %f\n",name, str->d);
+}
+
+void ChangeNumberSequential(NumberSequential* p)
+{
+ p->i32 = 0;
+ p->ui32 = 32;
+ p->s1 = 0;
+ p->us1 = 16;
+ p->b = 0;
+ p->sb = 8;
+ p->i16 = 0;
+ p->ui16 = 16;
+ p->i64 = 0;
+ p->ui64 = 64;
+ p->sgl = 64.0;
+ p->d = 6.4;
+}
+
+bool IsCorrectNumberSequential(NumberSequential* p)
+{
+ if(p->i32 != INT_MIN || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 ||
+ p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 ||
+ p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct S3 // size = 1032 bytes
+{
+ BOOL flag;
+ LPCSTR str;
+ INT vals[256];
+};
+
+void PrintS3(S3* str, const char* name)
+{
+ printf("\t%s.flag = %d\n", name, str->flag);
+ printf("\t%s.str = %s\n", name, str->str);
+ for(int i = 0; i<256 ;i++)
+ {
+ printf("\t%s.vals[%d] = %d\n",name,i,str->vals[i]);
+ }
+}
+
+void ChangeS3(S3* p)
+{
+ p->flag = false;
+
+ const char* strSource = "change string";
+ size_t len =strlen(strSource)+1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ memset((LPVOID)temp,0,len);
+ strncpy_s((char*)temp,len,strSource,len-1);
+ p->str = temp;
+ }
+ for(int i = 1;i<257;i++)
+ {
+ p->vals[i-1] = i;
+ }
+}
+
+bool IsCorrectS3(S3* p)
+{
+ int iflag = 0;
+ if(!p->flag || strcmp((char*)p->str,"some string") != 0)
+ return false;
+ for (int i = 0; i < 256; i++)
+ {
+ if (p->vals[i] != i)
+ {
+ printf("\tThe Index of %i is not expected",i);
+ iflag++;
+ }
+ }
+ if (iflag != 0)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct S4 // size = 8 bytes
+{
+ INT age;
+ LPCSTR name;
+};
+
+enum Enum1
+{
+ e1 = 1,
+ e2 = 3
+};
+
+struct S5 // size = 8 bytes
+{
+ struct S4 s4;
+ Enum1 ef;
+};
+
+void PrintS5(S5* str, const char* name)
+{
+ printf("\t%s.s4.age = %d", name, str->s4.age);
+ printf("\t%s.s4.name = %s", name, str->s4.name);
+ printf("\t%s.ef = %d", name, str->ef);
+}
+
+void ChangeS5(S5* str)
+{
+ Enum1 eInstance = e2;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource)+1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ memset((LPVOID)temp,0,len);
+ strncpy_s((char*)temp,len,strSource,len-1);
+ str->s4.name = temp;
+ }
+ str->s4.age = 64;
+ str->ef = eInstance;
+}
+
+bool IsCorrectS5(S5* str)
+{
+ Enum1 eInstance = e1;
+ if(str->s4.age != 32 || strcmp((char*)str->s4.name,"some string") != 0)
+ return false;
+ if(str->ef != eInstance)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct StringStructSequentialAnsi // size = 8 bytes
+{
+ LPCSTR first;
+ LPCSTR last;
+};
+
+void PrintStringStructSequentialAnsi(StringStructSequentialAnsi* str, const char* name)
+{
+ printf("\t%s.first = %s\n", name, str->first);
+ printf("\t%s.last = %s\n", name, str->last);
+}
+
+bool IsCorrectStringStructSequentialAnsi(StringStructSequentialAnsi* str)
+{
+ char strOne[512];
+ char strTwo[512];
+ for(int i = 0;i<512;i++)
+ {
+ strOne[i] = 'a';
+ strTwo[i] = 'b';
+ }
+
+ if(memcmp(str->first,strOne,512)!= 0)
+ return false;
+
+ if(memcmp(str->last,strTwo,512)!= 0)
+ return false;
+
+ return true;
+}
+
+void ChangeStringStructSequentialAnsi(StringStructSequentialAnsi* str)
+{
+ char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
+ char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
+ for (int i = 0; i < 512; ++i)
+ {
+ newFirst[i] = 'b';
+ newLast[i] = 'a';
+ }
+ newFirst[512] = '\0';
+ newLast[512] = '\0';
+
+ str->first = newFirst;
+ str->last = newLast;
+}
+
+struct StringStructSequentialUnicode // size = 8 bytes
+{
+ LPCWSTR first;
+ LPCWSTR last;
+};
+
+void PrintStringStructSequentialUnicode(StringStructSequentialUnicode* str, const char* name)
+{
+#ifdef _WIN32
+ wprintf(L"\t%S.first = %s\n", name, str->first);
+ wprintf(L"\t%S.last = %s\n", name, str->last);
+#else
+ wprintf(L"\t%s.first = %s\n", name, str->first);
+ wprintf(L"\t%s.last = %s\n", name, str->last);
+#endif
+}
+
+bool IsCorrectStringStructSequentialUnicode(StringStructSequentialUnicode* str)
+{
+ WCHAR strOne[256+1];
+ WCHAR strTwo[256+1];
+
+ for(int i = 0;i<256;++i)
+ {
+ strOne[i] = L'a';
+ strTwo[i] = L'b';
+ }
+ strOne[256] = L'\0';
+ strTwo[256] = L'\0';
+
+ if(memcmp(str->first,strOne,256*sizeof(WCHAR)) != 0)
+ return false;
+ if(memcmp(str->last,strTwo,256*sizeof(WCHAR)) != 0)
+ return false;
+ return true;
+}
+
+void ChangeStringStructSequentialUnicode(StringStructSequentialUnicode* str)
+{
+ WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ for (int i = 0; i < 256; ++i)
+ {
+ newFirst[i] = L'b';
+ newLast[i] = L'a';
+ }
+ newFirst[256] = L'\0';
+ newLast[256] = L'\0';
+ str->first = (const WCHAR*)newFirst;
+ str->last = (const WCHAR*)newLast;
+}
+
+struct S8 // size = 32 bytes
+{
+ LPCSTR name;
+ BOOL gender;
+ HRESULT i32;
+ HRESULT ui32;
+ WORD jobNum;
+ CHAR mySByte;
+};
+
+void PrintS8(S8* str, const char* name)
+{
+ printf("\t%s.name = %s\n",name, str->name);
+ printf("\t%s.gender = %d\n", name, str->gender);
+ printf("\t%s.jobNum = %d\n",name, str->jobNum);
+ printf("\t%s.i32 = %d\n", name, (int)(str->i32));
+ printf("\t%s.ui32 = %u\n", name, (unsigned int)(str->ui32));
+ printf("\t%s.mySByte = %c\n", name, str->mySByte);
+}
+
+bool IsCorrectS8(S8* str)
+{
+ if(memcmp( str->name,"hello", strlen("hello")*sizeof(char)+1 )!= 0)
+ return false;
+ if(!str->gender)
+ return false;
+ if(str->jobNum != 10)
+ return false;
+ if(str->i32!= 128 || str->ui32 != 128)
+ return false;
+ if(str->mySByte != 32)
+ return false;
+ return true;
+}
+
+void ChangeS8(S8* str)
+{
+ const char* lpstr = "world";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ str->name = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ str->gender = false;
+ str->jobNum = 1;
+ str->i32 = 256;
+ str->ui32 = 256;
+ str->mySByte = 64;
+}
+
+#pragma pack (8)
+struct S_int // size = 4 bytes
+{
+ INT i;
+};
+
+struct S9;
+typedef void (*TestDelegate1)(struct S9 myStruct);
+
+struct S9 // size = 8 bytes
+{
+ HRESULT i32;
+ TestDelegate1 myDelegate1;
+};
+
+struct S101 // size = 8 bytes
+{
+ INT i;
+ struct S_int s_int;
+};
+
+struct S10 // size = 8 bytes
+{
+ struct S101 s;
+};
+
+void PrintS10(S10* str, const char* name)
+{
+ printf("\t%s.s.s_int.i = %d\n", name, str->s.s_int.i);
+ printf("\t%s.s.i = %d\n", name, str->s.i);
+}
+
+bool IsCorrectS10(S10* str)
+{
+ if(str->s.s_int.i != 32)
+ return false;
+ if(str->s.i != 32)
+ return false;
+ return true;
+}
+
+void ChangeS10(S10* str)
+{
+ str->s.s_int.i = 64;
+ str->s.i = 64;
+}
+
+#ifndef WINDOWS
+typedef int* LPINT;
+#endif
+
+struct S11 // size = 8 bytes
+{
+ LPINT i32;
+ INT i;
+};
+
+union U // size = 8 bytes
+{
+ INT i32;
+ UINT ui32;
+ LPVOID iPtr;
+ LPVOID uiPtr;
+ SHORT s;
+ WORD us;
+ BYTE b;
+ CHAR sb;
+ LONG64 l;
+ ULONG64 ul;
+ FLOAT f;
+ DOUBLE d;
+};
+
+void PrintU(U* str, const char* name)
+{
+ printf("\t%s.i32 = %d\n", name, str->i32);
+ printf("\t%s.ui32 = %u\n", name, str->ui32);
+ printf("\t%s.iPtr = %zu\n", name, (size_t)(str->iPtr));
+ printf("\t%s.uiPtr = %zu\n", name, (size_t)(str->uiPtr));
+ printf("\t%s.s = %d\n", name, str->s);
+ printf("\t%s.us = %u\n", name, str->us);
+ printf("\t%s.b = %u\n", name, str->b);
+ printf("\t%s.sb = %d\n", name, str->sb);
+ printf("\t%s.l = %lld\n", name, str->l);
+ printf("\t%s.ul = %llu\n", name, str->ul);
+ printf("\t%s.f = %f\n", name, str->f);
+ printf("\t%s.d = %f\n", name, str->d);
+}
+
+void ChangeU(U* p)
+{
+ p->i32 = 2147483647;
+ p->ui32 = 0;
+ p->iPtr = (LPVOID)(-64);
+ p->uiPtr = (LPVOID)(64);
+ p->s = 32767;
+ p->us = 0;
+ p->b = 255;
+ p->sb = -128;
+ p->l = -1234567890;
+ p->ul = 0;
+ p->f = 64.0;
+ p->d = 6.4;
+}
+
+bool IsCorrectU(U* p)
+{
+ if(p->d != 3.2)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct ByteStructPack2Explicit // size = 2 bytes
+{
+ BYTE b1;
+ BYTE b2;
+};
+
+void PrintByteStructPack2Explicit(ByteStructPack2Explicit* str, const char* name)
+{
+ printf("\t%s.b1 = %d", name, str->b1);
+ printf("\t%s.b2 = %d", name, str->b2);
+}
+
+void ChangeByteStructPack2Explicit(ByteStructPack2Explicit* p)
+{
+ p->b1 = 64;
+ p->b2 = 64;
+}
+
+bool IsCorrectByteStructPack2Explicit(ByteStructPack2Explicit* p)
+{
+ if(p->b1 != 32 || p->b2 != 32)
+ return false;
+ return true;
+}
+
+struct ShortStructPack4Explicit // size = 4 bytes
+{
+ SHORT s1;
+ SHORT s2;
+};
+
+void PrintShortStructPack4Explicit(ShortStructPack4Explicit* str, const char* name)
+{
+ printf("\t%s.s1 = %d", name, str->s1);
+ printf("\t%s.s2 = %d", name, str->s2);
+}
+
+void ChangeShortStructPack4Explicit(ShortStructPack4Explicit* p)
+{
+ p->s1 = 64;
+ p->s2 = 64;
+}
+
+bool IsCorrectShortStructPack4Explicit(ShortStructPack4Explicit* p)
+{
+ if(p->s1 != 32 || p->s2 != 32)
+ return false;
+ return true;
+}
+
+struct IntStructPack8Explicit // size = 8 bytes
+{
+ INT i1;
+ INT i2;
+};
+
+void PrintIntStructPack8Explicit(IntStructPack8Explicit* str, const char* name)
+{
+ printf("\t%s.i1 = %d", name, str->i1);
+ printf("\t%s.i2 = %d", name, str->i2);
+}
+
+void ChangeIntStructPack8Explicit(IntStructPack8Explicit* p)
+{
+ p->i1 = 64;
+ p->i2 = 64;
+}
+
+bool IsCorrectIntStructPack8Explicit(IntStructPack8Explicit* p)
+{
+ if(p->i1 != 32 || p->i2 != 32)
+ return false;
+ return true;
+}
+
+struct LongStructPack16Explicit // size = 16 bytes
+{
+ LONG64 l1;
+ LONG64 l2;
+};
+
+void PrintLongStructPack16Explicit(LongStructPack16Explicit* str, const char* name)
+{
+ printf("\t%s.l1 = %lld", name, str->l1);
+ printf("\t%s.l2 = %lld", name, str->l2);
+}
+
+void ChangeLongStructPack16Explicit(LongStructPack16Explicit* p)
+{
+ p->l1 = 64;
+ p->l2 = 64;
+}
+
+bool IsCorrectLongStructPack16Explicit(LongStructPack16Explicit* p)
+{
+ if(p->l1 != 32 || p->l2 != 32)
+ return false;
+ return true;
+}
+
+LPSTR GetNativeString()
+{
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+ LPSTR str = NULL;
+
+ str = (LPSTR)CoreClrAlloc( lsize+1 );
+ memset(str,0,lsize+1);
+ strcpy_s((char*)str,lsize+1,lNativeStr);
+
+ return str;
+}
+
+LPSTR GetSomeString()
+{
+ const char* lNativeStr = "some string";
+ const size_t lsize = strlen(lNativeStr);
+ LPSTR str = NULL;
+
+ str = (LPSTR)CoreClrAlloc( lsize+1 );
+ memset(str,0,lsize+1);
+ strcpy_s((char*)str,lsize+1,lNativeStr);
+
+ return str;
+}
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ReversePInvokeManaged/ReversePInvokeTest.cs b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ReversePInvokeManaged/ReversePInvokeTest.cs
new file mode 100644
index 0000000000..674bbb2f6f
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ReversePInvokeManaged/ReversePInvokeTest.cs
@@ -0,0 +1,807 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Text;
+using System.Security;
+using System.Runtime.InteropServices;
+using TestLibrary;
+
+public class Test
+{
+ const int iNative = 11;//the value passed from Native side to Managed side
+ const int iManaged = 10;//The value passed from Managed side to Native sid
+
+ enum StructID
+ {
+ INNER2Id,
+ InnerExplicitId,
+ InnerArrayExplicitId,
+ OUTER3Id,
+ UId,
+ ByteStructPack2ExplicitId,
+ ShortStructPack4ExplicitId,
+ IntStructPack8ExplicitId,
+ LongStructPack16ExplicitId
+ }
+
+ #region Methods implementation
+
+ #region ReversePinvoke, ByRef, Cdel
+
+ //ReversePinvoke,Cdel
+ // 1.1
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_INNER2([In, Out]ref INNER2 inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_INNER2(ByRefCdeclcaller_INNER2 caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_INNER2_Cdecl(ref INNER2 inner2)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ INNER2 sourceINNER2 = Helper.NewINNER2(77, 77.0F, "Native");
+ Assert.IsTrue(Helper.ValidateINNER2(sourceINNER2, inner2, "TestMethod_DoCallBack_MarshalStructByRef_INNER2_Cdecl"));
+ //changed the value
+ inner2.f1 = 1;
+ inner2.f2 = 1.0F;
+ inner2.f3 = "some string";
+ return true;
+ }
+
+ // 1.2
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_InnerExplicit([In, Out]ref InnerExplicit inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_InnerExplicit(ByRefCdeclcaller_InnerExplicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_InnerExplicit_Cdecl(ref InnerExplicit inner2)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ InnerExplicit source_ie = new InnerExplicit();
+ source_ie.f1 = 77;
+ source_ie.f3 = "Native";
+ Assert.IsTrue(Helper.ValidateInnerExplicit(source_ie, inner2, "TestMethod_DoCallBack_MarshalStructByRef_InnerExplicit_Cdecl"));
+ //changed the value
+ inner2.f1 = 1;
+ inner2.f3 = "some string";
+ return true;
+ }
+
+ // 1.3
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_InnerArrayExplicit([In, Out]ref InnerArrayExplicit inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_InnerArrayExplicit(ByRefCdeclcaller_InnerArrayExplicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_InnerArrayExplicit_Cdecl(ref InnerArrayExplicit iae)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ InnerArrayExplicit source_iae = Helper.NewInnerArrayExplicit(77, 77.0F, "Native", "Native");
+ Assert.IsTrue(Helper.ValidateInnerArrayExplicit(source_iae, iae, "TestMethod_DoCallBack_MarshalStructByRef_InnerArrayExplicit_Cdecl"));
+ //changed the value
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ iae.arr[i].f1 = 1;
+ iae.arr[i].f3 = "some string";
+ }
+ iae.f4 = "some string";
+ return true;
+ }
+
+ // 1.4
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_OUTER3([In, Out]ref OUTER3 outer3);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_OUTER3(ByRefCdeclcaller_OUTER3 caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_OUTER3_Cdecl(ref OUTER3 outer3)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ OUTER3 sourceOUTER3 = Helper.NewOUTER3(77, 77.0F, "Native", "Native");
+ Assert.IsTrue(Helper.ValidateOUTER3(sourceOUTER3, outer3, "TestMethod_DoCallBack_MarshalStructByRef_OUTER3_Cdecl"));
+ //changed the value
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ outer3.arr[i].f1 = 1;
+ outer3.arr[i].f2 = 1.0F;
+ outer3.arr[i].f3 = "some string";
+ }
+ outer3.f4 = "some string";
+ return true;
+ }
+
+ // 1.5
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_U([In, Out]ref U u);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_U(ByRefCdeclcaller_U caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_U_Cdecl(ref U u)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ U changeU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue,
+ sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 1.23);
+ Assert.IsTrue(Helper.ValidateU(changeU, u, "TestMethod_DoCallBack_MarshalStructByRef_U_Cdecl"));
+ //changed the value
+ u.d = 3.2;
+ return true;
+ }
+
+ // 1.6
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_ByteStructPack2Explicit([In, Out]ref ByteStructPack2Explicit bspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_ByteStructPack2Explicit(ByRefCdeclcaller_ByteStructPack2Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_ByteStructPack2Explicit_Cdecl(ref ByteStructPack2Explicit bspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(64, 64);
+ Assert.IsTrue(Helper.ValidateByteStructPack2Explicit(change_bspe, bspe, "TestMethod_DoCallBack_MarshalStructByRef_ByteStructPack2Explicit_Cdecl"));
+ //changed the value
+ bspe.b1 = 32;
+ bspe.b2 = 32;
+ return true;
+ }
+
+ // 1.7
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_ShortStructPack4Explicit([In, Out]ref ShortStructPack4Explicit sspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_ShortStructPack4Explicit(ByRefCdeclcaller_ShortStructPack4Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_ShortStructPack4Explicit_Cdecl(ref ShortStructPack4Explicit sspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(64, 64);
+ Assert.IsTrue(Helper.ValidateShortStructPack4Explicit(change_sspe, sspe, "TestMethod_DoCallBack_MarshalStructByRef_ShortStructPack4Explicit_Cdecl"));
+ //changed the value
+ sspe.s1 = 32;
+ sspe.s2 = 32;
+ return true;
+ }
+
+ // 1.8
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_IntStructPack8Explicit([In, Out]ref IntStructPack8Explicit ispe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_IntStructPack8Explicit(ByRefCdeclcaller_IntStructPack8Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_IntStructPack8Explicit_Cdecl(ref IntStructPack8Explicit ispe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(64, 64);
+ Assert.IsTrue(Helper.ValidateIntStructPack8Explicit(change_ispe, ispe, "TestMethod_DoCallBack_MarshalStructByRef_IntStructPack8Explicit_Cdecl"));
+ //changed the value
+ ispe.i1 = 32;
+ ispe.i2 = 32;
+ return true;
+ }
+
+ // 1.9
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByRefCdeclcaller_LongStructPack16Explicit([In, Out]ref LongStructPack16Explicit lspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Cdecl_LongStructPack16Explicit(ByRefCdeclcaller_LongStructPack16Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_LongStructPack16Explicit_Cdecl(ref LongStructPack16Explicit lspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ LongStructPack16Explicit change_lspe = Helper.NewLongStructPack16Explicit(64, 64);
+ Assert.IsTrue(Helper.ValidateLongStructPack16Explicit(change_lspe, lspe, "TestMethod_DoCallBack_MarshalStructByRef_LongStructPack16Explicit_Cdecl"));
+ //changed the value
+ lspe.l1 = 32;
+ lspe.l2 = 32;
+ return true;
+ }
+
+ #endregion
+
+ #region ReversePinvoke, ByRef, Stdcall
+
+ //ReversePinvoke,Stdcall
+ // 2.1
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_INNER2([In, Out]ref INNER2 inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_INNER2(ByRefStdcallcaller_INNER2 caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_INNER2_Stdcall(ref INNER2 inner2)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ INNER2 sourceINNER2 = Helper.NewINNER2(77, 77.0F, "Native");
+ Assert.IsTrue(Helper.ValidateINNER2(sourceINNER2, inner2, "TestMethod_DoCallBack_MarshalStructByRef_INNER2_Stdcall"));
+ //changed the value
+ inner2.f1 = 1;
+ inner2.f2 = 1.0F;
+ inner2.f3 = "some string";
+ return true;
+ }
+
+ // 2.2
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_InnerExplicit([In, Out]ref InnerExplicit inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_InnerExplicit(ByRefStdcallcaller_InnerExplicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_InnerExplicit_Stdcall(ref InnerExplicit inner2)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ InnerExplicit source_ie = new InnerExplicit();
+ source_ie.f1 = 77;
+ source_ie.f3 = "Native";
+ Assert.IsTrue(Helper.ValidateInnerExplicit(inner2,source_ie, "TestMethod_DoCallBack_MarshalStructByRef_InnerExplicit_Stdcall"));
+ //changed the value
+ inner2.f1 = 1;
+ inner2.f3 = "some string";
+ return true;
+ }
+
+ // 2.3
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_InnerArrayExplicit([In, Out]ref InnerArrayExplicit inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_InnerArrayExplicit(ByRefStdcallcaller_InnerArrayExplicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_InnerArrayExplicit_Stdcall(ref InnerArrayExplicit iae)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ InnerArrayExplicit source_iae = Helper.NewInnerArrayExplicit(77, 77.0F, "Native", "Native");
+ Assert.IsTrue(Helper.ValidateInnerArrayExplicit(source_iae, iae, "TestMethod_DoCallBack_MarshalStructByRef_InnerArrayExplicit_Stdcall"));
+ //changed the value
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ iae.arr[i].f1 = 1;
+ iae.arr[i].f3 = "some string";
+ }
+ iae.f4 = "some string";
+ return true;
+ }
+
+ // 2.4
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_OUTER3([In, Out]ref OUTER3 outer3);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_OUTER3(ByRefStdcallcaller_OUTER3 caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_OUTER3_Stdcall(ref OUTER3 outer3)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ OUTER3 sourceOUTER3 = Helper.NewOUTER3(77, 77.0F, "Native", "Native");
+ Assert.IsTrue(Helper.ValidateOUTER3(sourceOUTER3, outer3, "TestMethod_DoCallBack_MarshalStructByRef_OUTER3_Stdcall"));
+ //changed the value
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ outer3.arr[i].f1 = 1;
+ outer3.arr[i].f2 = 1.0F;
+ outer3.arr[i].f3 = "some string";
+ }
+ outer3.f4 = "some string";
+ return true;
+ }
+
+ // 2.5
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_U([In, Out]ref U u);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_U(ByRefStdcallcaller_U caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_U_Stdcall(ref U u)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ U changeU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue,
+ sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 1.23);
+ Assert.IsTrue(Helper.ValidateU(changeU, u, "TestMethod_DoCallBack_MarshalStructByRef_U_Stdcall"));
+ //changed the value
+ u.d = 3.2;
+ return true;
+ }
+
+ // 2.6
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_ByteStructPack2Explicit([In, Out]ref ByteStructPack2Explicit bspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_ByteStructPack2Explicit(ByRefStdcallcaller_ByteStructPack2Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_ByteStructPack2Explicit_Stdcall(ref ByteStructPack2Explicit bspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(64, 64);
+ Assert.IsTrue(Helper.ValidateByteStructPack2Explicit(change_bspe, bspe, "TestMethod_DoCallBack_MarshalStructByRef_ByteStructPack2Explicit_Stdcall"));
+ //changed the value
+ bspe.b1 = 32;
+ bspe.b2 = 32;
+ return true;
+ }
+
+ // 2.7
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_ShortStructPack4Explicit([In, Out]ref ShortStructPack4Explicit sspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_ShortStructPack4Explicit(ByRefStdcallcaller_ShortStructPack4Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_ShortStructPack4Explicit_Stdcall(ref ShortStructPack4Explicit sspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(64, 64);
+ Assert.IsTrue(Helper.ValidateShortStructPack4Explicit(change_sspe, sspe, "TestMethod_DoCallBack_MarshalStructByRef_ShortStructPack4Explicit_Stdcall"));
+ //changed the value
+ sspe.s1 = 32;
+ sspe.s2 = 32;
+ return true;
+ }
+
+ // 2.8
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_IntStructPack8Explicit([In, Out]ref IntStructPack8Explicit ispe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_IntStructPack8Explicit(ByRefStdcallcaller_IntStructPack8Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_IntStructPack8Explicit_Stdcall(ref IntStructPack8Explicit ispe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(64, 64);
+ Assert.IsTrue(Helper.ValidateIntStructPack8Explicit(change_ispe, ispe, "TestMethod_DoCallBack_MarshalStructByRef_IntStructPack8Explicit_Stdcall"));
+ //changed the value
+ ispe.i1 = 32;
+ ispe.i2 = 32;
+ return true;
+ }
+
+ // 2.9
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByRefStdcallcaller_LongStructPack16Explicit([In, Out]ref LongStructPack16Explicit lspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByRefStruct_Stdcall_LongStructPack16Explicit(ByRefStdcallcaller_LongStructPack16Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByRef_LongStructPack16Explicit_Stdcall(ref LongStructPack16Explicit lspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Stdcall");
+ LongStructPack16Explicit change_lspe = Helper.NewLongStructPack16Explicit(64, 64);
+ Assert.IsTrue(Helper.ValidateLongStructPack16Explicit(change_lspe, lspe, "TestMethod_DoCallBack_MarshalStructByRef_LongStructPack16Explicit_Stdcall"));
+ //changed the value
+ lspe.l1 = 32;
+ lspe.l2 = 32;
+ return true;
+ }
+
+ #endregion
+
+ #region ReversePinvoke, ByVal, Cdel
+
+ // 3.1
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_INNER2([In, Out] INNER2 inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_INNER2(ByValCdeclcaller_INNER2 caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_INNER2_Cdecl( INNER2 inner2)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
+ INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string");
+ Assert.IsTrue(Helper.ValidateINNER2(sourceINNER2, inner2, "TestMethod_DoCallBack_MarshalStructByVal_INNER2_Cdecl"));
+ //changed the value
+ inner2.f1 = 77;
+ inner2.f2 = 77.0F;
+ inner2.f3 = "changed string";
+ return true;
+ }
+
+ // 3.2
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_InnerExplicit([In, Out] InnerExplicit inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_InnerExplicit(ByValCdeclcaller_InnerExplicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_InnerExplicit_Cdecl( InnerExplicit inner2)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Cdecl");
+ InnerExplicit source_ie = new InnerExplicit();
+ source_ie.f1 = 1;
+ source_ie.f3 = "Native";
+ Assert.IsTrue(Helper.ValidateInnerExplicit(source_ie, inner2, "TestMethod_DoCallBack_MarshalStructByVal_InnerExplicit_Cdecl"));
+ //changed the value
+ inner2.f1 = 1;
+ inner2.f3 = "changed string";
+ return true;
+ }
+
+ // 3.3
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_InnerArrayExplicit([In, Out] InnerArrayExplicit inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_InnerArrayExplicit(ByValCdeclcaller_InnerArrayExplicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_InnerArrayExplicit_Cdecl( InnerArrayExplicit iae)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Cdecl");
+ InnerArrayExplicit source_iae = Helper.NewInnerArrayExplicit(1, 1.0F, "some string", "some string");
+ Assert.IsTrue(Helper.ValidateInnerArrayExplicit(source_iae, iae, "TestMethod_DoCallBack_MarshalStructByVal_InnerArrayExplicit_Cdecl"));
+ //changed the value
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ iae.arr[i].f1 = 1;
+ iae.arr[i].f3 = "changed string";
+ }
+ iae.f4 = "changed string";
+ return true;
+ }
+
+ // 3.4
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_OUTER3([In, Out] OUTER3 outer3);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_OUTER3(ByValCdeclcaller_OUTER3 caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_OUTER3_Cdecl( OUTER3 outer3)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Cdecl");
+ OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string");
+ Assert.IsTrue(Helper.ValidateOUTER3(sourceOUTER3, outer3, "TestMethod_DoCallBack_MarshalStructByVal_OUTER3_Cdecl"));
+ //changed the value
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ outer3.arr[i].f1 = 1;
+ outer3.arr[i].f2 = 1.0F;
+ outer3.arr[i].f3 = "changed string";
+ }
+ outer3.f4 = "changed string";
+ return true;
+ }
+
+ // 3.5
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_U([In, Out] U u);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_U(ByValCdeclcaller_U caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_U_Cdecl( U u)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Cdecl");
+ U changeU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue,
+ sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2);
+ Assert.IsTrue(Helper.ValidateU(changeU, u, "TestMethod_DoCallBack_MarshalStructByVal_U_Cdecl"));
+ //changed the value
+ u.d = 1.23;
+ return true;
+ }
+
+ // 3.6
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_ByteStructPack2Explicit([In, Out] ByteStructPack2Explicit bspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_ByteStructPack2Explicit(ByValCdeclcaller_ByteStructPack2Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_ByteStructPack2Explicit_Cdecl( ByteStructPack2Explicit bspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Cdecl");
+ ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(32, 32);
+ Assert.IsTrue(Helper.ValidateByteStructPack2Explicit(change_bspe, bspe, "TestMethod_DoCallBack_MarshalStructByVal_ByteStructPack2Explicit_Cdecl"));
+ //changed the value
+ bspe.b1 = 64;
+ bspe.b2 = 64;
+ return true;
+ }
+
+ // 3.7
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_ShortStructPack4Explicit([In, Out] ShortStructPack4Explicit sspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_ShortStructPack4Explicit(ByValCdeclcaller_ShortStructPack4Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_ShortStructPack4Explicit_Cdecl( ShortStructPack4Explicit sspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Cdecl");
+ ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(32, 32);
+ Assert.IsTrue(Helper.ValidateShortStructPack4Explicit(change_sspe, sspe, "TestMethod_DoCallBack_MarshalStructByVal_ShortStructPack4Explicit_Cdecl"));
+ //changed the value
+ sspe.s1 = 64;
+ sspe.s2 = 64;
+ return true;
+ }
+
+ // 3.8
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_IntStructPack8Explicit([In, Out] IntStructPack8Explicit ispe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_IntStructPack8Explicit(ByValCdeclcaller_IntStructPack8Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_IntStructPack8Explicit_Cdecl( IntStructPack8Explicit ispe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Cdecl");
+ IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(32, 32);
+ Assert.IsTrue(Helper.ValidateIntStructPack8Explicit(change_ispe, ispe, "TestMethod_DoCallBack_MarshalStructByVal_IntStructPack8Explicit_Cdecl"));
+ //changed the value
+ ispe.i1 = 64;
+ ispe.i2 = 64;
+ return true;
+ }
+
+ // 3.9
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate bool ByValCdeclcaller_LongStructPack16Explicit([In, Out] LongStructPack16Explicit lspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.Cdecl)]
+ public static extern bool DoCallBack_MarshalByValStruct_Cdecl_LongStructPack16Explicit(ByValCdeclcaller_LongStructPack16Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_LongStructPack16Explicit_Cdecl( LongStructPack16Explicit lspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Cdecl");
+ LongStructPack16Explicit change_lspe = Helper.NewLongStructPack16Explicit(32, 32);
+ Assert.IsTrue(Helper.ValidateLongStructPack16Explicit(change_lspe, lspe, "TestMethod_DoCallBack_MarshalStructByVal_LongStructPack16Explicit_Cdecl"));
+ //changed the value
+ lspe.l1 = 64;
+ lspe.l2 = 64;
+ return true;
+ }
+
+ #endregion
+
+ #region ReversePinvoke, ByVal, Stdcall
+
+ // 4.1
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_INNER2([In, Out] INNER2 inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_INNER2(ByValStdcallcaller_INNER2 caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_INNER2_Stdcall(INNER2 inner2)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string");
+ Assert.IsTrue(Helper.ValidateINNER2(sourceINNER2, inner2, "TestMethod_DoCallBack_MarshalStructByVal_INNER2_Stdcall"));
+ //changed the value
+ inner2.f1 = 77;
+ inner2.f2 = 77.0F;
+ inner2.f3 = "changed string";
+ return true;
+ }
+
+ // 4.2
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_InnerExplicit([In, Out] InnerExplicit inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_InnerExplicit(ByValStdcallcaller_InnerExplicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_InnerExplicit_Stdcall(InnerExplicit inner2)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ InnerExplicit source_ie = new InnerExplicit();
+ source_ie.f1 = 1;
+ source_ie.f3 = "Native";
+ Assert.IsTrue(Helper.ValidateInnerExplicit(source_ie, inner2, "TestMethod_DoCallBack_MarshalStructByVal_InnerExplicit_Stdcall"));
+ //changed the value
+ inner2.f1 = 1;
+ inner2.f3 = "changed string";
+ return true;
+ }
+
+ // 4.3
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_InnerArrayExplicit([In, Out] InnerArrayExplicit inner2);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_InnerArrayExplicit(ByValStdcallcaller_InnerArrayExplicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_InnerArrayExplicit_Stdcall(InnerArrayExplicit iae)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ InnerArrayExplicit source_iae = Helper.NewInnerArrayExplicit(1, 1.0F, "some string", "some string");
+ Assert.IsTrue(Helper.ValidateInnerArrayExplicit(source_iae, iae, "TestMethod_DoCallBack_MarshalStructByVal_InnerArrayExplicit_Stdcall"));
+ //changed the value
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ iae.arr[i].f1 = 1;
+ iae.arr[i].f3 = "changed string";
+ }
+ iae.f4 = "changed string";
+ return true;
+ }
+
+ // 4.4
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_OUTER3([In, Out] OUTER3 outer3);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_OUTER3(ByValStdcallcaller_OUTER3 caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_OUTER3_Stdcall(OUTER3 outer3)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string");
+ Assert.IsTrue(Helper.ValidateOUTER3(sourceOUTER3, outer3, "TestMethod_DoCallBack_MarshalStructByVal_OUTER3_Stdcall"));
+ //changed the value
+ for (int i = 0; i < Common.NumArrElements; i++)
+ {
+ outer3.arr[i].f1 = 1;
+ outer3.arr[i].f2 = 1.0F;
+ outer3.arr[i].f3 = "changed string";
+ }
+ outer3.f4 = "changed string";
+ return true;
+ }
+
+ // 4.5
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_U([In, Out] U u);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_U(ByValStdcallcaller_U caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_U_Stdcall(U u)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ U changeU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue,
+ sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2);
+ Assert.IsTrue(Helper.ValidateU(changeU, u, "TestMethod_DoCallBack_MarshalStructByVal_U_Stdcall"));
+ //changed the value
+ u.d = 1.23;
+ return true;
+ }
+
+ // 4.6
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_ByteStructPack2Explicit([In, Out] ByteStructPack2Explicit bspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_ByteStructPack2Explicit(ByValStdcallcaller_ByteStructPack2Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_ByteStructPack2Explicit_Stdcall(ByteStructPack2Explicit bspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(32, 32);
+ Assert.IsTrue(Helper.ValidateByteStructPack2Explicit(change_bspe, bspe, "TestMethod_DoCallBack_MarshalStructByVal_ByteStructPack2Explicit_Stdcall"));
+ //changed the value
+ bspe.b1 = 64;
+ bspe.b2 = 64;
+ return true;
+ }
+
+ // 4.7
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_ShortStructPack4Explicit([In, Out] ShortStructPack4Explicit sspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_ShortStructPack4Explicit(ByValStdcallcaller_ShortStructPack4Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_ShortStructPack4Explicit_Stdcall(ShortStructPack4Explicit sspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(32, 32);
+ Assert.IsTrue(Helper.ValidateShortStructPack4Explicit(change_sspe, sspe, "TestMethod_DoCallBack_MarshalStructByVal_ShortStructPack4Explicit_Stdcall"));
+ //changed the value
+ sspe.s1 = 64;
+ sspe.s2 = 64;
+ return true;
+ }
+
+ // 4.8
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_IntStructPack8Explicit([In, Out] IntStructPack8Explicit ispe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_IntStructPack8Explicit(ByValStdcallcaller_IntStructPack8Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_IntStructPack8Explicit_Stdcall(IntStructPack8Explicit ispe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(32, 32);
+ Assert.IsTrue(Helper.ValidateIntStructPack8Explicit(change_ispe, ispe, "TestMethod_DoCallBack_MarshalStructByVal_IntStructPack8Explicit_Stdcall"));
+ //changed the value
+ ispe.i1 = 64;
+ ispe.i2 = 64;
+ return true;
+ }
+
+ // 4.9
+ [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+ public delegate bool ByValStdcallcaller_LongStructPack16Explicit([In, Out] LongStructPack16Explicit lspe);
+
+ [DllImport("ReversePInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ public static extern bool DoCallBack_MarshalByValStruct_Stdcall_LongStructPack16Explicit(ByValStdcallcaller_LongStructPack16Explicit caller);
+
+ public static bool TestMethod_DoCallBack_MarshalStructByVal_LongStructPack16Explicit_Stdcall(LongStructPack16Explicit lspe)
+ {
+ Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
+ LongStructPack16Explicit change_lspe = Helper.NewLongStructPack16Explicit(32, 32);
+ Assert.IsTrue(Helper.ValidateLongStructPack16Explicit(change_lspe, lspe, "TestMethod_DoCallBack_MarshalStructByVal_LongStructPack16Explicit_Stdcall"));
+ //changed the value
+ lspe.l1 = 64;
+ lspe.l2 = 64;
+ return true;
+ }
+
+ #endregion
+
+ #endregion
+
+ static int Main()
+ {
+ try{
+
+ #region calling method
+
+ ////Reverse Pinvoke,ByRef,cdecl
+ DoCallBack_MarshalByRefStruct_Cdecl_INNER2(new ByRefCdeclcaller_INNER2(TestMethod_DoCallBack_MarshalStructByRef_INNER2_Cdecl));
+ DoCallBack_MarshalByRefStruct_Cdecl_InnerExplicit(new ByRefCdeclcaller_InnerExplicit(TestMethod_DoCallBack_MarshalStructByRef_InnerExplicit_Cdecl));
+ DoCallBack_MarshalByRefStruct_Cdecl_InnerArrayExplicit(new ByRefCdeclcaller_InnerArrayExplicit(TestMethod_DoCallBack_MarshalStructByRef_InnerArrayExplicit_Cdecl));
+ DoCallBack_MarshalByRefStruct_Cdecl_OUTER3(new ByRefCdeclcaller_OUTER3(TestMethod_DoCallBack_MarshalStructByRef_OUTER3_Cdecl));
+ DoCallBack_MarshalByRefStruct_Cdecl_U(new ByRefCdeclcaller_U(TestMethod_DoCallBack_MarshalStructByRef_U_Cdecl));
+ DoCallBack_MarshalByRefStruct_Cdecl_ByteStructPack2Explicit(new ByRefCdeclcaller_ByteStructPack2Explicit(TestMethod_DoCallBack_MarshalStructByRef_ByteStructPack2Explicit_Cdecl));
+ DoCallBack_MarshalByRefStruct_Cdecl_ShortStructPack4Explicit(new ByRefCdeclcaller_ShortStructPack4Explicit(TestMethod_DoCallBack_MarshalStructByRef_ShortStructPack4Explicit_Cdecl));
+ DoCallBack_MarshalByRefStruct_Cdecl_IntStructPack8Explicit(new ByRefCdeclcaller_IntStructPack8Explicit(TestMethod_DoCallBack_MarshalStructByRef_IntStructPack8Explicit_Cdecl));
+ DoCallBack_MarshalByRefStruct_Cdecl_LongStructPack16Explicit(new ByRefCdeclcaller_LongStructPack16Explicit(TestMethod_DoCallBack_MarshalStructByRef_LongStructPack16Explicit_Cdecl));
+
+ ////Reverse Pinvoke,ByRef,StdCall
+ DoCallBack_MarshalByRefStruct_Stdcall_INNER2(new ByRefStdcallcaller_INNER2(TestMethod_DoCallBack_MarshalStructByRef_INNER2_Stdcall));
+ DoCallBack_MarshalByRefStruct_Stdcall_InnerExplicit(new ByRefStdcallcaller_InnerExplicit(TestMethod_DoCallBack_MarshalStructByRef_InnerExplicit_Stdcall));
+ DoCallBack_MarshalByRefStruct_Stdcall_InnerArrayExplicit(new ByRefStdcallcaller_InnerArrayExplicit(TestMethod_DoCallBack_MarshalStructByRef_InnerArrayExplicit_Stdcall));
+ DoCallBack_MarshalByRefStruct_Stdcall_OUTER3(new ByRefStdcallcaller_OUTER3(TestMethod_DoCallBack_MarshalStructByRef_OUTER3_Stdcall));
+ DoCallBack_MarshalByRefStruct_Stdcall_U(new ByRefStdcallcaller_U(TestMethod_DoCallBack_MarshalStructByRef_U_Stdcall));
+ DoCallBack_MarshalByRefStruct_Stdcall_ByteStructPack2Explicit(new ByRefStdcallcaller_ByteStructPack2Explicit(TestMethod_DoCallBack_MarshalStructByRef_ByteStructPack2Explicit_Stdcall));
+ DoCallBack_MarshalByRefStruct_Stdcall_ShortStructPack4Explicit(new ByRefStdcallcaller_ShortStructPack4Explicit(TestMethod_DoCallBack_MarshalStructByRef_ShortStructPack4Explicit_Stdcall));
+ DoCallBack_MarshalByRefStruct_Stdcall_IntStructPack8Explicit(new ByRefStdcallcaller_IntStructPack8Explicit(TestMethod_DoCallBack_MarshalStructByRef_IntStructPack8Explicit_Stdcall));
+ DoCallBack_MarshalByRefStruct_Stdcall_LongStructPack16Explicit(new ByRefStdcallcaller_LongStructPack16Explicit(TestMethod_DoCallBack_MarshalStructByRef_LongStructPack16Explicit_Stdcall));
+
+ ////Reverse Pinvoke,ByVal,cdecl
+ DoCallBack_MarshalByValStruct_Cdecl_INNER2(new ByValCdeclcaller_INNER2(TestMethod_DoCallBack_MarshalStructByVal_INNER2_Cdecl));
+ DoCallBack_MarshalByValStruct_Cdecl_InnerExplicit(new ByValCdeclcaller_InnerExplicit(TestMethod_DoCallBack_MarshalStructByVal_InnerExplicit_Cdecl));
+ DoCallBack_MarshalByValStruct_Cdecl_InnerArrayExplicit(new ByValCdeclcaller_InnerArrayExplicit(TestMethod_DoCallBack_MarshalStructByVal_InnerArrayExplicit_Cdecl));
+ DoCallBack_MarshalByValStruct_Cdecl_OUTER3(new ByValCdeclcaller_OUTER3(TestMethod_DoCallBack_MarshalStructByVal_OUTER3_Cdecl));
+ DoCallBack_MarshalByValStruct_Cdecl_U(new ByValCdeclcaller_U(TestMethod_DoCallBack_MarshalStructByVal_U_Cdecl));
+ DoCallBack_MarshalByValStruct_Cdecl_ByteStructPack2Explicit(new ByValCdeclcaller_ByteStructPack2Explicit(TestMethod_DoCallBack_MarshalStructByVal_ByteStructPack2Explicit_Cdecl));
+ DoCallBack_MarshalByValStruct_Cdecl_ShortStructPack4Explicit(new ByValCdeclcaller_ShortStructPack4Explicit(TestMethod_DoCallBack_MarshalStructByVal_ShortStructPack4Explicit_Cdecl));
+ DoCallBack_MarshalByValStruct_Cdecl_IntStructPack8Explicit(new ByValCdeclcaller_IntStructPack8Explicit(TestMethod_DoCallBack_MarshalStructByVal_IntStructPack8Explicit_Cdecl));
+ DoCallBack_MarshalByValStruct_Cdecl_LongStructPack16Explicit(new ByValCdeclcaller_LongStructPack16Explicit(TestMethod_DoCallBack_MarshalStructByVal_LongStructPack16Explicit_Cdecl));
+
+ ////Reverse Pinvoke,ByVal,stdcall
+ DoCallBack_MarshalByValStruct_Stdcall_INNER2(new ByValStdcallcaller_INNER2(TestMethod_DoCallBack_MarshalStructByVal_INNER2_Stdcall));
+ DoCallBack_MarshalByValStruct_Stdcall_InnerExplicit(new ByValStdcallcaller_InnerExplicit(TestMethod_DoCallBack_MarshalStructByVal_InnerExplicit_Stdcall));
+ DoCallBack_MarshalByValStruct_Stdcall_InnerArrayExplicit(new ByValStdcallcaller_InnerArrayExplicit(TestMethod_DoCallBack_MarshalStructByVal_InnerArrayExplicit_Stdcall));
+ DoCallBack_MarshalByValStruct_Stdcall_OUTER3(new ByValStdcallcaller_OUTER3(TestMethod_DoCallBack_MarshalStructByVal_OUTER3_Stdcall));
+ DoCallBack_MarshalByValStruct_Stdcall_U(new ByValStdcallcaller_U(TestMethod_DoCallBack_MarshalStructByVal_U_Stdcall));
+ DoCallBack_MarshalByValStruct_Stdcall_ByteStructPack2Explicit(new ByValStdcallcaller_ByteStructPack2Explicit(TestMethod_DoCallBack_MarshalStructByVal_ByteStructPack2Explicit_Stdcall));
+ DoCallBack_MarshalByValStruct_Stdcall_ShortStructPack4Explicit(new ByValStdcallcaller_ShortStructPack4Explicit(TestMethod_DoCallBack_MarshalStructByVal_ShortStructPack4Explicit_Stdcall));
+ DoCallBack_MarshalByValStruct_Stdcall_IntStructPack8Explicit(new ByValStdcallcaller_IntStructPack8Explicit(TestMethod_DoCallBack_MarshalStructByVal_IntStructPack8Explicit_Stdcall));
+ DoCallBack_MarshalByValStruct_Stdcall_LongStructPack16Explicit(new ByValStdcallcaller_LongStructPack16Explicit(TestMethod_DoCallBack_MarshalStructByVal_LongStructPack16Explicit_Stdcall));
+
+ #endregion
+
+ return 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine($"Test Failure: {e}");
+ return 101;
+ }
+ }
+}
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ReversePInvokeManaged/ReversePInvokeTest.csproj b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ReversePInvokeManaged/ReversePInvokeTest.csproj
new file mode 100644
index 0000000000..ea6ff85431
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ReversePInvokeManaged/ReversePInvokeTest.csproj
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>ReversePInvokeTest</AssemblyName>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\..\</SolutionDir>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <!-- Test unsupported outside of windows -->
+ <TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows>
+ <DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ReversePInvokeTest.cs" />
+ <Compile Include="..\..\Helper.cs" />
+ <Compile Include="..\..\Struct.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\CMakeLists.txt" />
+ </ItemGroup>
+ <Import Project="../../../../Interop.settings.targets" />
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/CMakeLists.txt b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/CMakeLists.txt
new file mode 100644
index 0000000000..0b3aef3904
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required (VERSION 2.6)
+project (SeqPInvokeNative)
+include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake")
+include_directories(${INC_PLATFORM_DIR})
+set(SOURCES
+ SeqStructDelRevPInvokeNative.cpp
+)
+add_library (SeqPInvokeNative SHARED ${SOURCES})
+target_link_libraries(SeqPInvokeNative ${LINK_LIBRARIES_ADDITIONAL})
+# add the install targets
+install (TARGETS SeqPInvokeNative DESTINATION bin)
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/DelegatePInvoke/DelegatePInvokeTest.cs b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/DelegatePInvoke/DelegatePInvokeTest.cs
new file mode 100644
index 0000000000..ad63deebdd
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/DelegatePInvoke/DelegatePInvokeTest.cs
Binary files differ
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/DelegatePInvoke/DelegatePInvokeTest.csproj b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/DelegatePInvoke/DelegatePInvokeTest.csproj
new file mode 100644
index 0000000000..b579275ec2
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/DelegatePInvoke/DelegatePInvokeTest.csproj
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>DelegatePInvokeTest</AssemblyName>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\..\</SolutionDir>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="DelegatePInvokeTest.cs" />
+ <Compile Include="..\..\Helper.cs" />
+ <Compile Include="..\..\Struct.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\CMakeLists.txt" />
+ </ItemGroup>
+ <Import Project="../../../../Interop.settings.targets" />
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest.cs b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest.cs
new file mode 100644
index 0000000000..a6e789c30f
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest.cs
Binary files differ
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest.csproj b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest.csproj
new file mode 100644
index 0000000000..5b3703f4e8
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest.csproj
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>ReversePInvokeTest</AssemblyName>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\..\</SolutionDir>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ReversePInvokeTest.cs" />
+ <Compile Include="..\..\Helper.cs" />
+ <Compile Include="..\..\Struct.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\CMakeLists.txt" />
+ </ItemGroup>
+ <Import Project="../../../../Interop.settings.targets" />
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.cpp b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.cpp
new file mode 100644
index 0000000000..08f069c707
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.cpp
@@ -0,0 +1,3241 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include <xplatform.h>
+#include "platformdefines.h"
+#include "SeqStructDelRevPInvokeNative.h"
+
+const char* NativeStr = "Native";
+//const size_t size = strlen(NativeStr);
+
+struct ScriptParamType
+{
+ int idata;
+ int useless; //Use this as pedding, since in the Manage code,the union starts at offset 8
+ union unionType
+ {
+ bool bdata;
+ double ddata;
+ int * ptrdata;
+ }udata;
+};
+
+struct ComplexStruct
+{
+ INT i;
+ CHAR b;
+ LPCSTR str;
+ //use this(padding), since in the Mac, it use 4bytes as struct pack(In windows, it is 8 bytes).
+ //if i dont add this. In Mac, it will try to replace the value of (pedding) with idata's value
+ LPVOID padding;//padding
+ ScriptParamType type;
+};
+
+
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructComplexStructByRef_Cdecl(ComplexStruct * pcs)
+{
+ //Check the Input
+ if((321 != pcs->i)||(!pcs->b)||(0 != strcmp(pcs->str,"Managed"))||(123 != pcs->type.idata)||(0x120000 != (int)(LONG64)(pcs->type.udata.ptrdata)))
+ {
+
+ printf("The parameter for MarshalRefStruct_Cdecl is wrong\n");
+ printf("ComplexStruct:%d:%d,%s,%d,%d\n",pcs->i,pcs->b,pcs->str,pcs->type.idata,(int)(LONG64)(pcs->type.udata.ptrdata));
+ return FALSE;
+ }
+ CoreClrFree((LPVOID)pcs->str);
+
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+ char * pstr = (char*)CoreClrAlloc((lsize + 1) * sizeof(char));
+ memset(pstr,0,lsize+1);
+
+ strncpy_s(pstr,lsize+1,lNativeStr,lsize);
+
+ //Change the value
+ pcs->i = 9999;
+ pcs->b = false;
+ pcs->str = pstr;
+ pcs->type.idata = -1;
+ pcs->type.udata.ddata = 3.14159;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructComplexStructByRef_StdCall(ComplexStruct * pcs)
+{
+ //Check the input
+ if((321 != pcs->i)||(!pcs->b)||(0 != strcmp(pcs->str,"Managed"))||(123 != pcs->type.idata)||(0x120000 != (int)(LONG64)(pcs->type.udata.ptrdata)))
+ {
+ printf("The parameter for MarshalRefStruct_StdCall is wrong\n");
+ return FALSE;
+ }
+ CoreClrFree((LPVOID)pcs->str);
+
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+ char * pstr = (char*)CoreClrAlloc(lsize + 1);
+ memset(pstr,0,lsize+1);
+ strncpy_s(pstr,lsize+1,lNativeStr,lsize);
+
+ //Change the value
+ pcs->i = 9999;
+ pcs->b = false;
+ pcs->str = pstr;
+ pcs->type.idata = -1;
+ pcs->type.udata.ddata = 3.14159;
+
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *ComplexStructByRefCdeclCaller)(ComplexStruct* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructComplexStructByRef_Cdecl(ComplexStructByRefCdeclCaller caller)
+{
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+
+ //Init
+ char * pstr = (char*)CoreClrAlloc(lsize + 1);
+ memset(pstr,0,lsize+1);
+ strncpy_s(pstr,lsize+1,lNativeStr,lsize);
+
+ ComplexStruct cs;
+ cs.i = 9999;
+ cs.b = false;
+ cs.str = pstr;
+ cs.type.idata = -1;
+ cs.type.udata.ddata = 3.14159;
+
+ if(!caller(&cs))
+ {
+ printf("DoCallBack_MarshalByRefStruct_Cdecl:The Caller return wrong value!\n");
+ return FALSE;
+ }
+
+ if((321 != cs.i)||(!cs.b)||(0 != strcmp(cs.str,"Managed"))||(123 != cs.type.idata)||(0x120000 != (int)(LONG64)(cs.type.udata.ptrdata)))
+ {
+ printf("The parameter for DoCallBack_MarshalRefStruct_Cdecl is wrong\n");
+ return FALSE;
+ }
+ CoreClrFree((LPVOID)cs.str);
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ComplexStructByRefStdCallCaller)(ComplexStruct* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructComplexStructByRef_StdCall(ComplexStructByRefStdCallCaller caller)
+{
+ const char* lNativeStr = "Native";
+ const size_t lsize = strlen(lNativeStr);
+
+ //init
+ char * pstr = (char*)CoreClrAlloc(lsize + 1);
+ memset(pstr,0,lsize+1);
+ strncpy_s(pstr,lsize+1,lNativeStr,lsize);
+
+ ComplexStruct cs;
+ cs.i = 9999;
+ cs.b = false;
+ cs.str = pstr;
+ cs.type.idata = -1;
+ cs.type.udata.ddata = 3.14159;
+
+ if(!caller(&cs))
+ {
+ printf("DoCallBack_MarshalByRefStruct_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ if((321 != cs.i)||(!cs.b)||(0 != strcmp(cs.str,"Managed"))||(123 != cs.type.idata)||(0x120000 != (int)(LONG64)(cs.type.udata.ptrdata)))
+ {
+ printf("The parameter for DoCallBack_MarshalRefStruct_StdCall is wrong\n");
+ return FALSE;
+ }
+ CoreClrFree((LPVOID)cs.str);
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *ComplexStructDelegatePInvokeByRefCdeclCaller)(ComplexStruct* pcs);
+extern "C" DLL_EXPORT ComplexStructDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructComplexStructByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructComplexStructByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *ComplexStructDelegatePInvokeByRefStdCallCaller)(ComplexStruct* pcs);
+extern "C" DLL_EXPORT ComplexStructDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructComplexStructByRef_StdCall_FuncPtr()
+{
+ return MarshalStructComplexStructByRef_StdCall;
+}
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructComplexStructByVal_Cdecl(ComplexStruct cs)
+{
+ //Check the Input
+ if((321 != cs.i)||(!cs.b)||(0 != strcmp(cs.str,"Managed"))||(123 != cs.type.idata)||(0x120000 != (int)(LONG64)(cs.type.udata.ptrdata)))
+ {
+
+ printf("The parameter for MarshalStructComplexStructByVal_Cdecl is wrong\n");
+ printf("ComplexStruct:%d:%d,%s,%d,%d\n",cs.i,cs.b,cs.str,cs.type.idata,(int)(LONG64)(cs.type.udata.ptrdata));
+ return FALSE;
+ }
+
+ cs.i = 9999;
+ cs.b = false;
+ cs.str = "Native";
+ cs.type.idata = -1;
+ cs.type.udata.ddata = 3.14159;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructComplexStructByVal_StdCall(ComplexStruct cs)
+{
+ //Check the input
+ if((321 != cs.i)||(!cs.b)||(0 != strcmp(cs.str,"Managed"))||(123 != cs.type.idata)||(0x120000 != (int)(LONG64)(cs.type.udata.ptrdata)))
+ {
+ printf("The parameter for MarshalStructComplexStructByVal_StdCall is wrong\n");
+ return FALSE;
+ }
+
+ cs.i = 9999;
+ cs.b = false;
+ cs.str = "Native";
+ cs.type.idata = -1;
+ cs.type.udata.ddata = 3.14159;
+
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *ComplexStructByValCdeclCaller)(ComplexStruct cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructComplexStructByVal_Cdecl(ComplexStructByValCdeclCaller caller)
+{
+ //Init
+ ComplexStruct cs;
+ cs.i = 9999;
+ cs.b = false;
+ cs.str = "Native";
+ cs.type.idata = -1;
+ cs.type.udata.ddata = 3.14159;
+
+ if(!caller(cs))
+ {
+ printf("DoCallBack_MarshalStructComplexStructByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if((9999 != cs.i)||(cs.b)||(0 != strcmp(cs.str,NativeStr))||(-1 != cs.type.idata)||(3.14159 != cs.type.udata.ddata))
+ {
+ printf("The parameter for DoCallBack_MarshalByValStruct_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *ComplexStructByValStdCallCaller)(ComplexStruct cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructComplexStructByVal_StdCall(ComplexStructByValStdCallCaller caller)
+{
+ ComplexStruct cs;
+ cs.i = 9999;
+ cs.b = false;
+ cs.str = "Native";
+ cs.type.idata = -1;
+ cs.type.udata.ddata = 3.14159;
+
+ if(!caller(cs))
+ {
+ printf("The parameter for DoCallBack_MarshalStructComplexStructByVal_StdCall is wrong\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if((9999 != cs.i)||(cs.b)||(0 != strcmp(cs.str,NativeStr))||(-1 != cs.type.idata)||(3.14159 != cs.type.udata.ddata))
+ {
+ printf("DoCallBack_MarshalStructComplexStructByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *ComplexStructDelegatePInvokeByValCdeclCaller)(ComplexStruct cs);
+extern "C" DLL_EXPORT ComplexStructDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructComplexStructByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructComplexStructByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *ComplexStructDelegatePInvokeByValStdCallCaller)(ComplexStruct cs);
+extern "C" DLL_EXPORT ComplexStructDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructComplexStructByVal_StdCall_FuncPtr()
+{
+ return MarshalStructComplexStructByVal_StdCall;
+}
+
+///////////////////////////////////////////Methods for InnerSequential struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructInnerSequentialByRef_Cdecl(InnerSequential* argstr)
+{
+ if(!IsCorrectInnerSequential(argstr))
+ {
+ printf("\tMarshalStructInnerSequentialByRef_Cdecl: InnerSequential param not as expected\n");
+ PrintInnerSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeInnerSequential(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructInnerSequentialByRef_StdCall(InnerSequential* argstr)
+{
+ if(!IsCorrectInnerSequential(argstr))
+ {
+ printf("\tMarshalStructInnerSequentialByRef_StdCall: InnerSequential param not as expected\n");
+ PrintInnerSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeInnerSequential(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *InnerSequentialByRefCdeclCaller)(InnerSequential* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructInnerSequentialByRef_Cdecl(InnerSequentialByRefCdeclCaller caller)
+{
+ //Init
+ InnerSequential argstr;
+ argstr.f1 = 77;
+ argstr.f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.f3 = temp;
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructInnerSequentialByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectInnerSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructInnerSequentialByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *InnerSequentialByRefStdCallCaller)(InnerSequential* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructInnerSequentialByRef_StdCall(InnerSequentialByRefStdCallCaller caller)
+{
+ //Init
+ InnerSequential argstr;
+ argstr.f1 = 77;
+ argstr.f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.f3 = temp;
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructInnerSequentialByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectInnerSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructInnerSequentialByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *InnerSequentialDelegatePInvokeByRefCdeclCaller)(InnerSequential* pcs);
+extern "C" DLL_EXPORT InnerSequentialDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructInnerSequentialByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructInnerSequentialByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *InnerSequentialDelegatePInvokeByRefStdCallCaller)(InnerSequential* pcs);
+extern "C" DLL_EXPORT InnerSequentialDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructInnerSequentialByRef_StdCall_FuncPtr()
+{
+ return MarshalStructInnerSequentialByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructInnerSequentialByVal_Cdecl(InnerSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectInnerSequential(&argstr))
+ {
+ printf("\tMarshalStructInnerSequentialByVal_Cdecl: InnerSequential param not as expected\n");
+ PrintInnerSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ argstr.f1 = 77;
+ argstr.f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.f3 = temp;
+ }
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructInnerSequentialByVal_StdCall(InnerSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectInnerSequential(&argstr))
+ {
+ printf("\tMarshalStructInnerSequentialByVal_StdCall: InnerSequential param not as expected\n");
+ PrintInnerSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ argstr.f1 = 77;
+ argstr.f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.f3 = temp;
+ }
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *InnerSequentialByValCdeclCaller)(InnerSequential cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructInnerSequentialByVal_Cdecl(InnerSequentialByValCdeclCaller caller)
+{
+ //Init
+ InnerSequential argstr{};
+ argstr.f1 = 77;
+ argstr.f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.f3 = temp;
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructInnerSequentialByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.f1 != 77 || argstr.f2 != 77.0 || strcmp((char*)argstr.f3, "changed string") != 0)
+ {
+ printf("The parameter for DoCallBack_MarshalStructInnerSequentialByVal_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *InnerSequentialByValStdCallCaller)(InnerSequential cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructInnerSequentialByVal_StdCall(InnerSequentialByValStdCallCaller caller)
+{
+ //Init
+ InnerSequential argstr{};
+ argstr.f1 = 77;
+ argstr.f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.f3 = temp;
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructInnerSequentialByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.f1 != 77 || argstr.f2 != 77.0 || strcmp((char*)argstr.f3, "changed string") != 0)
+ {
+ printf("The parameter for DoCallBack_MarshalStructInnerSequentialByVal_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *InnerSequentialDelegatePInvokeByValCdeclCaller)(InnerSequential cs);
+extern "C" DLL_EXPORT InnerSequentialDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructInnerSequentialByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructInnerSequentialByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *InnerSequentialDelegatePInvokeByValStdCallCaller)(InnerSequential cs);
+extern "C" DLL_EXPORT InnerSequentialDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructInnerSequentialByVal_StdCall_FuncPtr()
+{
+ return MarshalStructInnerSequentialByVal_StdCall;
+}
+
+
+///////////////////////////////////////////Methods for InnerArraySequential struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructInnerArraySequentialByRef_Cdecl(InnerArraySequential* argstr)
+{
+ if(!IsCorrectInnerArraySequential(argstr))
+ {
+ printf("\tMarshalStructInnerArraySequentialByRef_Cdecl: InnerArraySequential param not as expected\n");
+ PrintInnerArraySequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeInnerArraySequential(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructInnerArraySequentialByRef_StdCall(InnerArraySequential* argstr)
+{
+ if(!IsCorrectInnerArraySequential(argstr))
+ {
+ printf("\tMarshalStructInnerArraySequentialByRef_StdCall: InnerArraySequential param not as expected\n");
+ PrintInnerArraySequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeInnerArraySequential(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *InnerArraySequentialByRefCdeclCaller)(InnerArraySequential* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructInnerArraySequentialByRef_Cdecl(InnerArraySequentialByRefCdeclCaller caller)
+{
+ //Init
+ InnerArraySequential argstr;
+
+ for(int i = 0;i<NumArrElements;i++)
+ {
+ argstr.arr[i].f1 = 77;
+ argstr.arr[i].f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.arr[i].f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructInnerArraySequentialByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectInnerArraySequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructInnerArraySequentialByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *InnerArraySequentialByRefStdCallCaller)(InnerArraySequential* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructInnerArraySequentialByRef_StdCall(InnerArraySequentialByRefStdCallCaller caller)
+{
+ //Init
+ InnerArraySequential argstr;
+ for(int i = 0;i<NumArrElements;i++)
+ {
+ argstr.arr[i].f1 = 77;
+ argstr.arr[i].f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.arr[i].f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ }
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructInnerArraySequentialByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectInnerArraySequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructInnerArraySequentialByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *InnerArraySequentialDelegatePInvokeByRefCdeclCaller)(InnerArraySequential* pcs);
+extern "C" DLL_EXPORT InnerArraySequentialDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructInnerArraySequentialByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructInnerArraySequentialByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *InnerArraySequentialDelegatePInvokeByRefStdCallCaller)(InnerArraySequential* pcs);
+extern "C" DLL_EXPORT InnerArraySequentialDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructInnerArraySequentialByRef_StdCall_FuncPtr()
+{
+ return MarshalStructInnerArraySequentialByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructInnerArraySequentialByVal_Cdecl(InnerArraySequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectInnerArraySequential(&argstr))
+ {
+ printf("\tMarshalStructInnerArraySequentialByVal_Cdecl: InnerArraySequential param not as expected\n");
+ PrintInnerArraySequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ for(int i = 0;i<NumArrElements;i++)
+ {
+ argstr.arr[i].f1 = 77;
+ argstr.arr[i].f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.arr[i].f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ }
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructInnerArraySequentialByVal_StdCall(InnerArraySequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectInnerArraySequential(&argstr))
+ {
+ printf("\tMarshalStructInnerArraySequentialByVal_StdCall: InnerArraySequential param not as expected\n");
+ PrintInnerArraySequential(&argstr,"argstr");
+ return FALSE;
+ }
+ for(int i = 0; i<NumArrElements;i++)
+ {
+ argstr.arr[i].f1 = 77;
+ argstr.arr[i].f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.arr[i].f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ }
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *InnerArraySequentialByValCdeclCaller)(InnerArraySequential cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructInnerArraySequentialByVal_Cdecl(InnerArraySequentialByValCdeclCaller caller)
+{
+ //Init
+ InnerArraySequential argstr;
+ for(int i = 0;i<NumArrElements;i++)
+ {
+ argstr.arr[i].f1 = 77;
+ argstr.arr[i].f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.arr[i].f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructInnerArraySequentialByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ for(int i =0;i<NumArrElements;i++)
+ {
+ if(argstr.arr[i].f1 != 77 || argstr.arr[i].f2 != 77.0 || strcmp((char*)argstr.arr[i].f3, "changed string") != 0)
+ {
+ printf("The parameter for DoCallBack_MarshalStructInnerArraySequentialByVal_Cdecl is wrong\n");
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *InnerArraySequentialByValStdCallCaller)(InnerArraySequential cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructInnerArraySequentialByVal_StdCall(InnerArraySequentialByValStdCallCaller caller)
+{
+ //Init
+ InnerArraySequential argstr;
+ for(int i = 0;i<NumArrElements;i++)
+ {
+ argstr.arr[i].f1 = 77;
+ argstr.arr[i].f2 = 77.0;
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.arr[i].f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructInnerArraySequentialByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ for(int i = 0;i<NumArrElements;i++)
+ {
+ if(argstr.arr[i].f1 != 77 || argstr.arr[i].f2 != 77.0 || strcmp((char*)argstr.arr[i].f3, "changed string") != 0)
+ {
+ printf("The parameter for DoCallBack_MarshalStructInnerArraySequentialByVal_StdCall is wrong\n");
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *InnerArraySequentialDelegatePInvokeByValCdeclCaller)(InnerArraySequential cs);
+extern "C" DLL_EXPORT InnerArraySequentialDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructInnerArraySequentialByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructInnerArraySequentialByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *InnerArraySequentialDelegatePInvokeByValStdCallCaller)(InnerArraySequential cs);
+extern "C" DLL_EXPORT InnerArraySequentialDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructInnerArraySequentialByVal_StdCall_FuncPtr()
+{
+ return MarshalStructInnerArraySequentialByVal_StdCall;
+}
+
+///////////////////////////////////////////Methods for CharSetAnsiSequential struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructCharSetAnsiSequentialByRef_Cdecl(CharSetAnsiSequential* argstr)
+{
+ if(!IsCorrectCharSetAnsiSequential(argstr))
+ {
+ printf("\tMarshalStructCharSetAnsiSequentialByRef_Cdecl: CharSetAnsiSequential param not as expected\n");
+ PrintCharSetAnsiSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeCharSetAnsiSequential(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructCharSetAnsiSequentialByRef_StdCall(CharSetAnsiSequential* argstr)
+{
+ if(!IsCorrectCharSetAnsiSequential(argstr))
+ {
+ printf("\tMarshalStructCharSetAnsiSequentialByRef_StdCall: CharSetAnsiSequential param not as expected\n");
+ PrintCharSetAnsiSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeCharSetAnsiSequential(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *CharSetAnsiSequentialByRefCdeclCaller)(CharSetAnsiSequential* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructCharSetAnsiSequentialByRef_Cdecl(CharSetAnsiSequentialByRefCdeclCaller caller)
+{
+ //Init
+ CharSetAnsiSequential argstr;
+
+ const char* strSource = "change string";
+ size_t size = strlen(strSource) + 1;
+ LPSTR temp = (LPSTR)CoreClrAlloc(size);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,size,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructCharSetAnsiSequentialByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectCharSetAnsiSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructCharSetAnsiSequentialByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *CharSetAnsiSequentialByRefStdCallCaller)(CharSetAnsiSequential* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructCharSetAnsiSequentialByRef_StdCall(CharSetAnsiSequentialByRefStdCallCaller caller)
+{
+ //Init
+ CharSetAnsiSequential argstr;
+
+ const char* strSource = "change string";
+ size_t size = strlen(strSource) + 1;
+ LPSTR temp = (LPSTR)CoreClrAlloc(size);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,size,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructCharSetAnsiSequentialByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectCharSetAnsiSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructCharSetAnsiSequentialByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *CharSetAnsiSequentialDelegatePInvokeByRefCdeclCaller)(CharSetAnsiSequential* pcs);
+extern "C" DLL_EXPORT CharSetAnsiSequentialDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructCharSetAnsiSequentialByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructCharSetAnsiSequentialByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *CharSetAnsiSequentialDelegatePInvokeByRefStdCallCaller)(CharSetAnsiSequential* pcs);
+extern "C" DLL_EXPORT CharSetAnsiSequentialDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructCharSetAnsiSequentialByRef_StdCall_FuncPtr()
+{
+ return MarshalStructCharSetAnsiSequentialByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructCharSetAnsiSequentialByVal_Cdecl(CharSetAnsiSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectCharSetAnsiSequential(&argstr))
+ {
+ printf("\tMarshalStructCharSetAnsiSequentialByVal_Cdecl: CharSetAnsiSequential param not as expected\n");
+ PrintCharSetAnsiSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ const char* strSource = "change string";
+ size_t size = strlen(strSource) + 1;
+ LPSTR temp = (LPSTR)CoreClrAlloc(size);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,size,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructCharSetAnsiSequentialByVal_StdCall(CharSetAnsiSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectCharSetAnsiSequential(&argstr))
+ {
+ printf("\tMarshalStructCharSetAnsiSequentialByVal_StdCall: CharSetAnsiSequential param not as expected\n");
+ PrintCharSetAnsiSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ const char* strSource = "change string";
+ size_t size = strlen(strSource) + 1;
+ LPSTR temp = (LPSTR)CoreClrAlloc(size);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,size,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *CharSetAnsiSequentialByValCdeclCaller)(CharSetAnsiSequential cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructCharSetAnsiSequentialByVal_Cdecl(CharSetAnsiSequentialByValCdeclCaller caller)
+{
+ //Init
+ CharSetAnsiSequential argstr{};
+ const char* strSource = "change string";
+ size_t size = strlen(strSource) + 1;
+ LPSTR temp = (LPSTR)CoreClrAlloc(size);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,size,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructCharSetAnsiSequentialByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(strcmp((char*)argstr.f1,"change string") != 0 || argstr.f2 != 'n')
+ {
+ printf("The parameter for DoCallBack_MarshalStructCharSetAnsiSequentialByVal_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *CharSetAnsiSequentialByValStdCallCaller)(CharSetAnsiSequential cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructCharSetAnsiSequentialByVal_StdCall(CharSetAnsiSequentialByValStdCallCaller caller)
+{
+ //Init
+ CharSetAnsiSequential argstr{};
+ const char* strSource = "change string";
+ size_t size = strlen(strSource) + 1;
+ LPSTR temp = (LPSTR)CoreClrAlloc(size);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,size,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructCharSetAnsiSequentialByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(strcmp((char*)argstr.f1,"change string") != 0 || argstr.f2 != 'n')
+ {
+ printf("The parameter for DoCallBack_MarshalStructCharSetAnsiSequentialByVal_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *CharSetAnsiSequentialDelegatePInvokeByValCdeclCaller)(CharSetAnsiSequential cs);
+extern "C" DLL_EXPORT CharSetAnsiSequentialDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructCharSetAnsiSequentialByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructCharSetAnsiSequentialByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *CharSetAnsiSequentialDelegatePInvokeByValStdCallCaller)(CharSetAnsiSequential cs);
+extern "C" DLL_EXPORT CharSetAnsiSequentialDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructCharSetAnsiSequentialByVal_StdCall_FuncPtr()
+{
+ return MarshalStructCharSetAnsiSequentialByVal_StdCall;
+}
+
+
+///////////////////////////////////////////Methods for CharSetUnicodeSequential struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructCharSetUnicodeSequentialByRef_Cdecl(CharSetUnicodeSequential* argstr)
+{
+ if(!IsCorrectCharSetUnicodeSequential(argstr))
+ {
+ printf("\tMarshalStructCharSetUnicodeSequentialByRef_Cdecl: CharSetUnicodeSequential param not as expected\n");
+ PrintCharSetUnicodeSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeCharSetUnicodeSequential(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructCharSetUnicodeSequentialByRef_StdCall(CharSetUnicodeSequential* argstr)
+{
+ if(!IsCorrectCharSetUnicodeSequential(argstr))
+ {
+ printf("\tMarshalStructCharSetUnicodeSequentialByRef_StdCall: CharSetUnicodeSequential param not as expected\n");
+ PrintCharSetUnicodeSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeCharSetUnicodeSequential(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *CharSetUnicodeSequentialByRefCdeclCaller)(CharSetUnicodeSequential* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructCharSetUnicodeSequentialByRef_Cdecl(CharSetUnicodeSequentialByRefCdeclCaller caller)
+{
+ //Init
+ CharSetUnicodeSequential argstr;
+
+ WCHAR* strSource = (WCHAR*)(W("change string"));
+ size_t len = wcslen(strSource);
+ LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
+ if(temp != NULL)
+ {
+ //wcscpy((WCHAR*)temp, (len+1)*sizeof(WCHAR), strSource);
+ wcscpy_s((WCHAR*)temp,len+1,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructCharSetUnicodeSequentialByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectCharSetUnicodeSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructCharSetUnicodeSequentialByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *CharSetUnicodeSequentialByRefStdCallCaller)(CharSetUnicodeSequential* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructCharSetUnicodeSequentialByRef_StdCall(CharSetUnicodeSequentialByRefStdCallCaller caller)
+{
+ //Init
+ CharSetUnicodeSequential argstr;
+
+ WCHAR* strSource = (WCHAR*)(W("change string"));
+ size_t len = wcslen(strSource);
+ LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
+ if(temp != NULL)
+ {
+ //wcscpy((WCHAR*)temp, (len+1)*sizeof(WCHAR), strSource);
+ wcscpy_s((WCHAR*)temp,len+1,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructCharSetUnicodeSequentialByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectCharSetUnicodeSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructCharSetUnicodeSequentialByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *CharSetUnicodeSequentialDelegatePInvokeByRefCdeclCaller)(CharSetUnicodeSequential* pcs);
+extern "C" DLL_EXPORT CharSetUnicodeSequentialDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructCharSetUnicodeSequentialByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructCharSetUnicodeSequentialByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *CharSetUnicodeSequentialDelegatePInvokeByRefStdCallCaller)(CharSetUnicodeSequential* pcs);
+extern "C" DLL_EXPORT CharSetUnicodeSequentialDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructCharSetUnicodeSequentialByRef_StdCall_FuncPtr()
+{
+ return MarshalStructCharSetUnicodeSequentialByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructCharSetUnicodeSequentialByVal_Cdecl(CharSetUnicodeSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectCharSetUnicodeSequential(&argstr))
+ {
+ printf("\tMarshalStructCharSetUnicodeSequentialByVal_Cdecl: CharSetUnicodeSequential param not as expected\n");
+ PrintCharSetUnicodeSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ WCHAR* strSource = (WCHAR*)(W("change string"));
+ size_t len = wcslen(strSource);
+ LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
+ if(temp != NULL)
+ {
+ //wcscpy((WCHAR*)temp, (len+1)*sizeof(WCHAR), strSource);
+ wcscpy_s((WCHAR*)temp,len+1,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructCharSetUnicodeSequentialByVal_StdCall(CharSetUnicodeSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectCharSetUnicodeSequential(&argstr))
+ {
+ printf("\tMarshalStructCharSetUnicodeSequentialByVal_StdCall: CharSetUnicodeSequential param not as expected\n");
+ PrintCharSetUnicodeSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ WCHAR* strSource = (WCHAR*)(W("change string"));
+ size_t len = wcslen(strSource);
+ LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
+ if(temp != NULL)
+ {
+ //wcscpy((WCHAR*)temp, (len+1)*sizeof(WCHAR), strSource);
+ wcscpy_s((WCHAR*)temp,len+1,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *CharSetUnicodeSequentialByValCdeclCaller)(CharSetUnicodeSequential cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructCharSetUnicodeSequentialByVal_Cdecl(CharSetUnicodeSequentialByValCdeclCaller caller)
+{
+ //Init
+ CharSetUnicodeSequential argstr{};
+ WCHAR* strSource = (WCHAR*)(W("change string"));
+ size_t len =wcslen(strSource);
+ LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
+ if(temp != NULL)
+ {
+ //wcscpy((WCHAR*)temp, (len+1)*sizeof(WCHAR), strSource);
+ wcscpy_s((WCHAR*)temp,len+1,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructCharSetUnicodeSequentialByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(0 != wcscmp(const_cast<WCHAR*>(argstr.f1), const_cast<WCHAR*>(W("change string"))) || argstr.f2 != L'n')
+ {
+ printf("The parameter for DoCallBack_MarshalStructCharSetUnicodeSequentialByVal_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *CharSetUnicodeSequentialByValStdCallCaller)(CharSetUnicodeSequential cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructCharSetUnicodeSequentialByVal_StdCall(CharSetUnicodeSequentialByValStdCallCaller caller)
+{
+ //Init
+ CharSetUnicodeSequential argstr{};
+ WCHAR* strSource = (WCHAR*)(W("change string"));
+ size_t len =wcslen(strSource);
+ LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
+ if(temp != NULL)
+ {
+ //wcscpy((WCHAR*)temp, (len+1)*sizeof(WCHAR), strSource);
+ wcscpy_s((WCHAR*)temp,len+1,strSource);
+ argstr.f1 = temp;
+ argstr.f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructCharSetUnicodeSequentialByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(0 != wcscmp(const_cast<WCHAR*>(argstr.f1), const_cast<WCHAR*>(W("change string"))) || argstr.f2 != L'n')
+ {
+ printf("The parameter for DoCallBack_MarshalStructCharSetUnicodeSequentialByVal_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *CharSetUnicodeSequentialDelegatePInvokeByValCdeclCaller)(CharSetUnicodeSequential cs);
+extern "C" DLL_EXPORT CharSetUnicodeSequentialDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructCharSetUnicodeSequentialByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructCharSetUnicodeSequentialByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *CharSetUnicodeSequentialDelegatePInvokeByValStdCallCaller)(CharSetUnicodeSequential cs);
+extern "C" DLL_EXPORT CharSetUnicodeSequentialDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructCharSetUnicodeSequentialByVal_StdCall_FuncPtr()
+{
+ return MarshalStructCharSetUnicodeSequentialByVal_StdCall;
+}
+
+
+///////////////////////////////////////////Methods for NumberSequential struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructNumberSequentialByRef_Cdecl(NumberSequential* argstr)
+{
+ if(!IsCorrectNumberSequential(argstr))
+ {
+ printf("\tMarshalStructNumberSequentialByRef_Cdecl: NumberSequential param not as expected\n");
+ PrintNumberSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeNumberSequential(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructNumberSequentialByRef_StdCall(NumberSequential* argstr)
+{
+ if(!IsCorrectNumberSequential(argstr))
+ {
+ printf("\tMarshalStructNumberSequentialByRef_StdCall: NumberSequential param not as expected\n");
+ PrintNumberSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeNumberSequential(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *NumberSequentialByRefCdeclCaller)(NumberSequential* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructNumberSequentialByRef_Cdecl(NumberSequentialByRefCdeclCaller caller)
+{
+ //Init
+ NumberSequential argstr;
+
+ argstr.i32 = 0;
+ argstr.ui32 = 32;
+ argstr.s1 = 0;
+ argstr.us1 = 16;
+ argstr.b = 0;
+ argstr.sb = 8;
+ argstr.i16 = 0;
+ argstr.ui16 = 16;
+ argstr.i64 = 0;
+ argstr.ui64 = 64;
+ argstr.sgl = 64.0;
+ argstr.d = 6.4;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructNumberSequentialByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectNumberSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructNumberSequentialByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *NumberSequentialByRefStdCallCaller)(NumberSequential* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructNumberSequentialByRef_StdCall(NumberSequentialByRefStdCallCaller caller)
+{
+ //Init
+ NumberSequential argstr;
+
+ argstr.i32 = 0;
+ argstr.ui32 = 32;
+ argstr.s1 = 0;
+ argstr.us1 = 16;
+ argstr.b = 0;
+ argstr.sb = 8;
+ argstr.i16 = 0;
+ argstr.ui16 = 16;
+ argstr.i64 = 0;
+ argstr.ui64 = 64;
+ argstr.sgl = 64.0;
+ argstr.d = 6.4;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructNumberSequentialByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectNumberSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructNumberSequentialByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *NumberSequentialDelegatePInvokeByRefCdeclCaller)(NumberSequential* pcs);
+extern "C" DLL_EXPORT NumberSequentialDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructNumberSequentialByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructNumberSequentialByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *NumberSequentialDelegatePInvokeByRefStdCallCaller)(NumberSequential* pcs);
+extern "C" DLL_EXPORT NumberSequentialDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructNumberSequentialByRef_StdCall_FuncPtr()
+{
+ return MarshalStructNumberSequentialByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructNumberSequentialByVal_Cdecl(NumberSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectNumberSequential(&argstr))
+ {
+ printf("\tMarshalStructNumberSequentialByVal_Cdecl: NumberSequential param not as expected\n");
+ PrintNumberSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ argstr.i32 = 0;
+ argstr.ui32 = 32;
+ argstr.s1 = 0;
+ argstr.us1 = 16;
+ argstr.b = 0;
+ argstr.sb = 8;
+ argstr.i16 = 0;
+ argstr.ui16 = 16;
+ argstr.i64 = 0;
+ argstr.ui64 = 64;
+ argstr.sgl = 64.0;
+ argstr.d = 6.4;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructNumberSequentialByVal_StdCall(NumberSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectNumberSequential(&argstr))
+ {
+ printf("\tMarshalStructNumberSequentialByVal_StdCall: NumberSequential param not as expected\n");
+ PrintNumberSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ argstr.i32 = 0;
+ argstr.ui32 = 32;
+ argstr.s1 = 0;
+ argstr.us1 = 16;
+ argstr.b = 0;
+ argstr.sb = 8;
+ argstr.i16 = 0;
+ argstr.ui16 = 16;
+ argstr.i64 = 0;
+ argstr.ui64 = 64;
+ argstr.sgl = 64.0;
+ argstr.d = 6.4;
+
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *NumberSequentialByValCdeclCaller)(NumberSequential cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructNumberSequentialByVal_Cdecl(NumberSequentialByValCdeclCaller caller)
+{
+ //Init
+ NumberSequential argstr;
+
+ argstr.i32 = 0;
+ argstr.ui32 = 32;
+ argstr.s1 = 0;
+ argstr.us1 = 16;
+ argstr.b = 0;
+ argstr.sb = 8;
+ argstr.i16 = 0;
+ argstr.ui16 = 16;
+ argstr.i64 = 0;
+ argstr.ui64 = 64;
+ argstr.sgl = 64.0;
+ argstr.d = 6.4;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructNumberSequentialByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.i32 != 0 || argstr.ui32 != 32 || argstr.s1 != 0 || argstr.us1 != 16 || argstr.b != 0 ||
+ argstr.sb != 8 || argstr.i16 != 0 || argstr.ui16 != 16 || argstr.i64 != 0 || argstr.ui64 != 64 ||
+ argstr.sgl != 64.0 || argstr.d != 6.4)
+ {
+ printf("The parameter for DoCallBack_MarshalStructNumberSequentialByVal_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *NumberSequentialByValStdCallCaller)(NumberSequential cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructNumberSequentialByVal_StdCall(NumberSequentialByValStdCallCaller caller)
+{
+ //Init
+ NumberSequential argstr;
+
+ argstr.i32 = 0;
+ argstr.ui32 = 32;
+ argstr.s1 = 0;
+ argstr.us1 = 16;
+ argstr.b = 0;
+ argstr.sb = 8;
+ argstr.i16 = 0;
+ argstr.ui16 = 16;
+ argstr.i64 = 0;
+ argstr.ui64 = 64;
+ argstr.sgl = 64.0;
+ argstr.d = 6.4;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructNumberSequentialByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.i32 != 0 || argstr.ui32 != 32 || argstr.s1 != 0 || argstr.us1 != 16 || argstr.b != 0 ||
+ argstr.sb != 8 || argstr.i16 != 0 || argstr.ui16 != 16 || argstr.i64 != 0 || argstr.ui64 != 64 ||
+ argstr.sgl != 64.0 || argstr.d != 6.4)
+ {
+ printf("The parameter for DoCallBack_MarshalStructNumberSequentialByVal_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *NumberSequentialDelegatePInvokeByValCdeclCaller)(NumberSequential cs);
+extern "C" DLL_EXPORT NumberSequentialDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructNumberSequentialByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructNumberSequentialByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *NumberSequentialDelegatePInvokeByValStdCallCaller)(NumberSequential cs);
+extern "C" DLL_EXPORT NumberSequentialDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructNumberSequentialByVal_StdCall_FuncPtr()
+{
+ return MarshalStructNumberSequentialByVal_StdCall;
+}
+
+
+///////////////////////////////////////////Methods for S3 struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS3ByRef_Cdecl(S3* argstr)
+{
+ if(!IsCorrectS3(argstr))
+ {
+ printf("\tMarshalStructS3ByRef_Cdecl: S3 param not as expected\n");
+ PrintS3(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeS3(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS3ByRef_StdCall(S3* argstr)
+{
+ if(!IsCorrectS3(argstr))
+ {
+ printf("\tMarshalStructS3ByRef_StdCall: S3 param not as expected\n");
+ PrintS3(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeS3(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *S3ByRefCdeclCaller)(S3* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS3ByRef_Cdecl(S3ByRefCdeclCaller caller)
+{
+ //Init
+ S3 argstr;
+
+ argstr.flag = false;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.str = temp;
+ }
+ for(int i = 1;i<257;i++)
+ {
+ argstr.vals[i-1] = i;
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS3ByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectS3(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructS3ByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S3ByRefStdCallCaller)(S3* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS3ByRef_StdCall(S3ByRefStdCallCaller caller)
+{
+ //Init
+ S3 argstr;
+
+ argstr.flag = false;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.str = temp;
+ }
+ for(int i = 1;i<257;i++)
+ {
+ argstr.vals[i-1] = i;
+ }
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS3ByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectS3(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructS3ByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *S3DelegatePInvokeByRefCdeclCaller)(S3* pcs);
+extern "C" DLL_EXPORT S3DelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructS3ByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructS3ByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *S3DelegatePInvokeByRefStdCallCaller)(S3* pcs);
+extern "C" DLL_EXPORT S3DelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructS3ByRef_StdCall_FuncPtr()
+{
+ return MarshalStructS3ByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS3ByVal_Cdecl(S3 argstr)
+{
+ //Check the Input
+ if(!IsCorrectS3(&argstr))
+ {
+ printf("\tMarshalStructS3ByVal_Cdecl: S3 param not as expected\n");
+ PrintS3(&argstr,"argstr");
+ return FALSE;
+ }
+
+ argstr.flag = false;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.str = temp;
+ }
+ for(int i = 1;i<257;i++)
+ {
+ argstr.vals[i-1] = i;
+ }
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS3ByVal_StdCall(S3 argstr)
+{
+ //Check the Input
+ if(!IsCorrectS3(&argstr))
+ {
+ printf("\tMarshalStructS3ByVal_StdCall: S3 param not as expected\n");
+ PrintS3(&argstr,"argstr");
+ return FALSE;
+ }
+
+ argstr.flag = false;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.str = temp;
+ }
+ for(int i = 1;i<257;i++)
+ {
+ argstr.vals[i-1] = i;
+ }
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *S3ByValCdeclCaller)(S3 cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS3ByVal_Cdecl(S3ByValCdeclCaller caller)
+{
+ //Init
+ S3 argstr;
+
+ argstr.flag = false;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.str = temp;
+ }
+ for(int i = 1;i<257;i++)
+ {
+ argstr.vals[i-1] = i;
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS3ByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ int iflag = 0;
+ if(argstr.flag || strcmp((char*)argstr.str,"change string") != 0)
+ return false;
+ for (int i = 1; i < 257; i++)
+ {
+ if (argstr.vals[i-1] != i)
+ {
+ printf("\tThe Index of %i is not expected",i);
+ iflag++;
+ }
+ }
+ if (iflag != 0)
+ {
+ return false;
+ }
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S3ByValStdCallCaller)(S3 cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS3ByVal_StdCall(S3ByValStdCallCaller caller)
+{
+ //Init
+ S3 argstr;
+
+ argstr.flag = false;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.str = temp;
+ }
+ for(int i = 1;i<257;i++)
+ {
+ argstr.vals[i-1] = i;
+ }
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS3ByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ int iflag = 0;
+ if(argstr.flag || strcmp((char*)argstr.str,"change string") != 0)
+ return false;
+ for (int i = 1; i < 257; i++)
+ {
+ if (argstr.vals[i-1] != i)
+ {
+ printf("\tThe Index of %i is not expected",i);
+ iflag++;
+ }
+ }
+ if (iflag != 0)
+ {
+ return false;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *S3DelegatePInvokeByValCdeclCaller)(S3 cs);
+extern "C" DLL_EXPORT S3DelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructS3ByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructS3ByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *S3DelegatePInvokeByValStdCallCaller)(S3 cs);
+extern "C" DLL_EXPORT S3DelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructS3ByVal_StdCall_FuncPtr()
+{
+ return MarshalStructS3ByVal_StdCall;
+}
+
+
+
+///////////////////////////////////////////Methods for S5 struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS5ByRef_Cdecl(S5* argstr)
+{
+ if(!IsCorrectS5(argstr))
+ {
+ printf("\tMarshalStructS5ByRef_Cdecl: S5 param not as expected\n");
+ PrintS5(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeS5(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS5ByRef_StdCall(S5* argstr)
+{
+ if(!IsCorrectS5(argstr))
+ {
+ printf("\tMarshalStructS5ByRef_StdCall: S5 param not as expected\n");
+ PrintS5(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeS5(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *S5ByRefCdeclCaller)(S5* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS5ByRef_Cdecl(S5ByRefCdeclCaller caller)
+{
+ //Init
+ S5 argstr;
+
+ Enum1 eInstance = e2;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.s4.name = temp;
+ }
+ argstr.s4.age = 64;
+ argstr.ef = eInstance;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS5ByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectS5(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructS5ByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S5ByRefStdCallCaller)(S5* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS5ByRef_StdCall(S5ByRefStdCallCaller caller)
+{
+ //Init
+ S5 argstr;
+
+ Enum1 eInstance = e2;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.s4.name = temp;
+ }
+ argstr.s4.age = 64;
+ argstr.ef = eInstance;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS5ByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectS5(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructS5ByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *S5DelegatePInvokeByRefCdeclCaller)(S5* pcs);
+extern "C" DLL_EXPORT S5DelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructS5ByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructS5ByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *S5DelegatePInvokeByRefStdCallCaller)(S5* pcs);
+extern "C" DLL_EXPORT S5DelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructS5ByRef_StdCall_FuncPtr()
+{
+ return MarshalStructS5ByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS5ByVal_Cdecl(S5 argstr)
+{
+ //Check the Input
+ if(!IsCorrectS5(&argstr))
+ {
+ printf("\tMarshalStructS5ByVal_Cdecl: S5 param not as expected\n");
+ PrintS5(&argstr,"argstr");
+ return FALSE;
+ }
+
+ Enum1 eInstance = e2;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.s4.name = temp;
+ }
+ argstr.s4.age = 64;
+ argstr.ef = eInstance;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS5ByVal_StdCall(S5 argstr)
+{
+ //Check the Input
+ if(!IsCorrectS5(&argstr))
+ {
+ printf("\tMarshalStructS5ByVal_StdCall: S5 param not as expected\n");
+ PrintS5(&argstr,"argstr");
+ return FALSE;
+ }
+
+ Enum1 eInstance = e2;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.s4.name = temp;
+ }
+ argstr.s4.age = 64;
+ argstr.ef = eInstance;
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *S5ByValCdeclCaller)(S5 cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS5ByVal_Cdecl(S5ByValCdeclCaller caller)
+{
+ //Init
+ S5 argstr{};
+
+ Enum1 eInstance = e2;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.s4.name = temp;
+ }
+ argstr.s4.age = 64;
+ argstr.ef = eInstance;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS5ByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.s4.age != 64 || strcmp((char*)argstr.s4.name,"change string") != 0)
+ return false;
+ if(argstr.ef != eInstance)
+ {
+ return false;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S5ByValStdCallCaller)(S5 cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS5ByVal_StdCall(S5ByValStdCallCaller caller)
+{
+ //Init
+ S5 argstr{};
+
+ Enum1 eInstance = e2;
+ const char* strSource = "change string";
+ size_t len =strlen(strSource) + 1;
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*len);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,len,strSource);
+ argstr.s4.name = temp;
+ }
+ argstr.s4.age = 64;
+ argstr.ef = eInstance;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS5ByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.s4.age != 64 || strcmp((char*)argstr.s4.name,"change string") != 0)
+ return false;
+ if(argstr.ef != eInstance)
+ {
+ return false;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *S5DelegatePInvokeByValCdeclCaller)(S5 cs);
+extern "C" DLL_EXPORT S5DelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructS5ByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructS5ByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *S5DelegatePInvokeByValStdCallCaller)(S5 cs);
+extern "C" DLL_EXPORT S5DelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructS5ByVal_StdCall_FuncPtr()
+{
+ return MarshalStructS5ByVal_StdCall;
+}
+
+
+///////////////////////////////////////////Methods for StringStructSequentialAnsi struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructStringStructSequentialAnsiByRef_Cdecl(StringStructSequentialAnsi* argstr)
+{
+ if(!IsCorrectStringStructSequentialAnsi(argstr))
+ {
+ printf("\tMarshalStructStringStructSequentialAnsiByRef_Cdecl: StringStructSequentialAnsi param not as expected\n");
+ PrintStringStructSequentialAnsi(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeStringStructSequentialAnsi(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructStringStructSequentialAnsiByRef_StdCall(StringStructSequentialAnsi* argstr)
+{
+ if(!IsCorrectStringStructSequentialAnsi(argstr))
+ {
+ printf("\tMarshalStructStringStructSequentialAnsiByRef_StdCall: StringStructSequentialAnsi param not as expected\n");
+ PrintStringStructSequentialAnsi(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeStringStructSequentialAnsi(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *StringStructSequentialAnsiByRefCdeclCaller)(StringStructSequentialAnsi* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructStringStructSequentialAnsiByRef_Cdecl(StringStructSequentialAnsiByRefCdeclCaller caller)
+{
+ //Init
+ StringStructSequentialAnsi argstr;
+
+ char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
+ char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
+ for (int i = 0; i < 512; ++i)
+ {
+ newFirst[i] = 'b';
+ newLast[i] = 'a';
+ }
+ newFirst[512] = '\0';
+ newLast[512] = '\0';
+ argstr.first = newFirst;
+ argstr.last = newLast;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructStringStructSequentialAnsiByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectStringStructSequentialAnsi(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructStringStructSequentialAnsiByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *StringStructSequentialAnsiByRefStdCallCaller)(StringStructSequentialAnsi* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructStringStructSequentialAnsiByRef_StdCall(StringStructSequentialAnsiByRefStdCallCaller caller)
+{
+ //Init
+ StringStructSequentialAnsi argstr;
+
+ char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
+ char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
+ for (int i = 0; i < 512; ++i)
+ {
+ newFirst[i] = 'b';
+ newLast[i] = 'a';
+ }
+ newFirst[512] = '\0';
+ newLast[512] = '\0';
+ argstr.first = newFirst;
+ argstr.last = newLast;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructStringStructSequentialAnsiByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectStringStructSequentialAnsi(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructStringStructSequentialAnsiByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *StringStructSequentialAnsiDelegatePInvokeByRefCdeclCaller)(StringStructSequentialAnsi* pcs);
+extern "C" DLL_EXPORT StringStructSequentialAnsiDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructStringStructSequentialAnsiByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructStringStructSequentialAnsiByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *StringStructSequentialAnsiDelegatePInvokeByRefStdCallCaller)(StringStructSequentialAnsi* pcs);
+extern "C" DLL_EXPORT StringStructSequentialAnsiDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructStringStructSequentialAnsiByRef_StdCall_FuncPtr()
+{
+ return MarshalStructStringStructSequentialAnsiByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructStringStructSequentialAnsiByVal_Cdecl(StringStructSequentialAnsi argstr)
+{
+ //Check the Input
+ if(!IsCorrectStringStructSequentialAnsi(&argstr))
+ {
+ printf("\tMarshalStructStringStructSequentialAnsiByVal_Cdecl: StringStructSequentialAnsi param not as expected\n");
+ PrintStringStructSequentialAnsi(&argstr,"argstr");
+ return FALSE;
+ }
+
+ char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
+ char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
+ for (int i = 0; i < 512; ++i)
+ {
+ newFirst[i] = 'b';
+ newLast[i] = 'a';
+ }
+ newFirst[512] = '\0';
+ newLast[512] = '\0';
+ argstr.first = newFirst;
+ argstr.last = newLast;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructStringStructSequentialAnsiByVal_StdCall(StringStructSequentialAnsi argstr)
+{
+ //Check the Input
+ if(!IsCorrectStringStructSequentialAnsi(&argstr))
+ {
+ printf("\tMarshalStructStringStructSequentialAnsiByVal_StdCall: StringStructSequentialAnsi param not as expected\n");
+ PrintStringStructSequentialAnsi(&argstr,"argstr");
+ return FALSE;
+ }
+
+ char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
+ char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
+ for (int i = 0; i < 512; ++i)
+ {
+ newFirst[i] = 'b';
+ newLast[i] = 'a';
+ }
+ newFirst[512] = '\0';
+ newLast[512] = '\0';
+ argstr.first = newFirst;
+ argstr.last = newLast;
+
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *StringStructSequentialAnsiByValCdeclCaller)(StringStructSequentialAnsi cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructStringStructSequentialAnsiByVal_Cdecl(StringStructSequentialAnsiByValCdeclCaller caller)
+{
+ //Init
+ StringStructSequentialAnsi argstr;
+ char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
+ char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
+ for (int i = 0; i < 512; ++i)
+ {
+ newFirst[i] = 'b';
+ newLast[i] = 'a';
+ }
+ newFirst[512] = '\0';
+ newLast[512] = '\0';
+ argstr.first = newFirst;
+ argstr.last = newLast;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructStringStructSequentialAnsiByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(memcmp(argstr.first,newFirst,512)!= 0)
+ return false;
+ if(memcmp(argstr.last,newLast,512)!= 0)
+ return false;
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *StringStructSequentialAnsiByValStdCallCaller)(StringStructSequentialAnsi cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructStringStructSequentialAnsiByVal_StdCall(StringStructSequentialAnsiByValStdCallCaller caller)
+{
+ //Init
+ StringStructSequentialAnsi argstr;
+ char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
+ char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
+ for (int i = 0; i < 512; ++i)
+ {
+ newFirst[i] = 'b';
+ newLast[i] = 'a';
+ }
+ newFirst[512] = '\0';
+ newLast[512] = '\0';
+ argstr.first = newFirst;
+ argstr.last = newLast;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructStringStructSequentialAnsiByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(memcmp(argstr.first,newFirst,512)!= 0)
+ return false;
+ if(memcmp(argstr.last,newLast,512)!= 0)
+ return false;
+
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *StringStructSequentialAnsiDelegatePInvokeByValCdeclCaller)(StringStructSequentialAnsi cs);
+extern "C" DLL_EXPORT StringStructSequentialAnsiDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructStringStructSequentialAnsiByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructStringStructSequentialAnsiByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *StringStructSequentialAnsiDelegatePInvokeByValStdCallCaller)(StringStructSequentialAnsi cs);
+extern "C" DLL_EXPORT StringStructSequentialAnsiDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructStringStructSequentialAnsiByVal_StdCall_FuncPtr()
+{
+ return MarshalStructStringStructSequentialAnsiByVal_StdCall;
+}
+
+
+
+
+///////////////////////////////////////////Methods for StringStructSequentialUnicode struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructStringStructSequentialUnicodeByRef_Cdecl(StringStructSequentialUnicode* argstr)
+{
+ if(!IsCorrectStringStructSequentialUnicode(argstr))
+ {
+ printf("\tMarshalStructStringStructSequentialUnicodeByRef_Cdecl: StringStructSequentialUnicode param not as expected\n");
+ PrintStringStructSequentialUnicode(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeStringStructSequentialUnicode(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructStringStructSequentialUnicodeByRef_StdCall(StringStructSequentialUnicode* argstr)
+{
+ if(!IsCorrectStringStructSequentialUnicode(argstr))
+ {
+ printf("\tMarshalStructStringStructSequentialUnicodeByRef_StdCall: StringStructSequentialUnicode param not as expected\n");
+ PrintStringStructSequentialUnicode(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeStringStructSequentialUnicode(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *StringStructSequentialUnicodeByRefCdeclCaller)(StringStructSequentialUnicode* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructStringStructSequentialUnicodeByRef_Cdecl(StringStructSequentialUnicodeByRefCdeclCaller caller)
+{
+ //Init
+ StringStructSequentialUnicode argstr;
+
+ WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ for (int i = 0; i < 256; ++i)
+ {
+ newFirst[i] = L'b';
+ newLast[i] = L'a';
+ }
+ newFirst[256] = L'\0';
+ newLast[256] = L'\0';
+ argstr.first = (const WCHAR*)newFirst;
+ argstr.last = (const WCHAR*)newLast;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructStringStructSequentialUnicodeByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectStringStructSequentialUnicode(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructStringStructSequentialUnicodeByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *StringStructSequentialUnicodeByRefStdCallCaller)(StringStructSequentialUnicode* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructStringStructSequentialUnicodeByRef_StdCall(StringStructSequentialUnicodeByRefStdCallCaller caller)
+{
+ //Init
+ StringStructSequentialUnicode argstr;
+
+ WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ for (int i = 0; i < 256; ++i)
+ {
+ newFirst[i] = L'b';
+ newLast[i] = L'a';
+ }
+ newFirst[256] = L'\0';
+ newLast[256] = L'\0';
+ argstr.first = (const WCHAR*)newFirst;
+ argstr.last = (const WCHAR*)newLast;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructStringStructSequentialUnicodeByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectStringStructSequentialUnicode(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructStringStructSequentialUnicodeByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *StringStructSequentialUnicodeDelegatePInvokeByRefCdeclCaller)(StringStructSequentialUnicode* pcs);
+extern "C" DLL_EXPORT StringStructSequentialUnicodeDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructStringStructSequentialUnicodeByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructStringStructSequentialUnicodeByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *StringStructSequentialUnicodeDelegatePInvokeByRefStdCallCaller)(StringStructSequentialUnicode* pcs);
+extern "C" DLL_EXPORT StringStructSequentialUnicodeDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructStringStructSequentialUnicodeByRef_StdCall_FuncPtr()
+{
+ return MarshalStructStringStructSequentialUnicodeByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructStringStructSequentialUnicodeByVal_Cdecl(StringStructSequentialUnicode argstr)
+{
+ //Check the Input
+ if(!IsCorrectStringStructSequentialUnicode(&argstr))
+ {
+ printf("\tMarshalStructStringStructSequentialUnicodeByVal_Cdecl: StringStructSequentialUnicode param not as expected\n");
+ PrintStringStructSequentialUnicode(&argstr,"argstr");
+ return FALSE;
+ }
+
+ WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ for (int i = 0; i < 256; ++i)
+ {
+ newFirst[i] = L'b';
+ newLast[i] = L'a';
+ }
+ newFirst[256] = L'\0';
+ newLast[256] = L'\0';
+ argstr.first = (const WCHAR*)newFirst;
+ argstr.last = (const WCHAR*)newLast;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructStringStructSequentialUnicodeByVal_StdCall(StringStructSequentialUnicode argstr)
+{
+ //Check the Input
+ if(!IsCorrectStringStructSequentialUnicode(&argstr))
+ {
+ printf("\tMarshalStructStringStructSequentialUnicodeByVal_StdCall: StringStructSequentialUnicode param not as expected\n");
+ PrintStringStructSequentialUnicode(&argstr,"argstr");
+ return FALSE;
+ }
+
+ WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ for (int i = 0; i < 256; ++i)
+ {
+ newFirst[i] = L'b';
+ newLast[i] = L'a';
+ }
+ newFirst[256] = L'\0';
+ newLast[256] = L'\0';
+ argstr.first = (const WCHAR*)newFirst;
+ argstr.last = (const WCHAR*)newLast;
+
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *StringStructSequentialUnicodeByValCdeclCaller)(StringStructSequentialUnicode cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructStringStructSequentialUnicodeByVal_Cdecl(StringStructSequentialUnicodeByValCdeclCaller caller)
+{
+ //Init
+ StringStructSequentialUnicode argstr;
+
+ WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ for (int i = 0; i < 256; ++i)
+ {
+ newFirst[i] = L'b';
+ newLast[i] = L'a';
+ }
+ newFirst[256] = L'\0';
+ newLast[256] = L'\0';
+ argstr.first = (const WCHAR*)newFirst;
+ argstr.last = (const WCHAR*)newLast;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructStringStructSequentialUnicodeByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(memcmp(argstr.first,newFirst,256*sizeof(WCHAR)) != 0)
+ return false;
+ if(memcmp(argstr.last,newLast,256*sizeof(WCHAR)) != 0)
+ return false;
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *StringStructSequentialUnicodeByValStdCallCaller)(StringStructSequentialUnicode cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructStringStructSequentialUnicodeByVal_StdCall(StringStructSequentialUnicodeByValStdCallCaller caller)
+{
+ //Init
+ StringStructSequentialUnicode argstr;
+
+ WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ for (int i = 0; i < 256; ++i)
+ {
+ newFirst[i] = L'b';
+ newLast[i] = L'a';
+ }
+ newFirst[256] = L'\0';
+ newLast[256] = L'\0';
+ argstr.first = (const WCHAR*)newFirst;
+ argstr.last = (const WCHAR*)newLast;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructStringStructSequentialUnicodeByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(memcmp(argstr.first,newFirst,256*sizeof(WCHAR)) != 0)
+ return false;
+ if(memcmp(argstr.last,newLast,256*sizeof(WCHAR)) != 0)
+ return false;
+
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *StringStructSequentialUnicodeDelegatePInvokeByValCdeclCaller)(StringStructSequentialUnicode cs);
+extern "C" DLL_EXPORT StringStructSequentialUnicodeDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructStringStructSequentialUnicodeByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructStringStructSequentialUnicodeByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *StringStructSequentialUnicodeDelegatePInvokeByValStdCallCaller)(StringStructSequentialUnicode cs);
+extern "C" DLL_EXPORT StringStructSequentialUnicodeDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructStringStructSequentialUnicodeByVal_StdCall_FuncPtr()
+{
+ return MarshalStructStringStructSequentialUnicodeByVal_StdCall;
+}
+
+
+
+
+///////////////////////////////////////////Methods for S8 struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS8ByRef_Cdecl(S8* argstr)
+{
+ if(!IsCorrectS8(argstr))
+ {
+ printf("\tMarshalStructS8ByRef_Cdecl: S8 param not as expected\n");
+ PrintS8(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeS8(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS8ByRef_StdCall(S8* argstr)
+{
+ if(!IsCorrectS8(argstr))
+ {
+ printf("\tMarshalStructS8ByRef_StdCall: S8 param not as expected\n");
+ PrintS8(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeS8(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *S8ByRefCdeclCaller)(S8* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS8ByRef_Cdecl(S8ByRefCdeclCaller caller)
+{
+ //Init
+ S8 argstr;
+
+ const char* lpstr = "world";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.name = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ argstr.gender = false;
+ argstr.jobNum = 1;
+ argstr.i32 = 256;
+ argstr.ui32 = 256;
+ argstr.mySByte = 64;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS8ByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectS8(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructS8ByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S8ByRefStdCallCaller)(S8* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS8ByRef_StdCall(S8ByRefStdCallCaller caller)
+{
+ //Init
+ S8 argstr;
+
+ const char* lpstr = "world";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.name = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ argstr.gender = false;
+ argstr.jobNum = 1;
+ argstr.i32 = 256;
+ argstr.ui32 = 256;
+ argstr.mySByte = 64;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS8ByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectS8(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructS8ByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *S8DelegatePInvokeByRefCdeclCaller)(S8* pcs);
+extern "C" DLL_EXPORT S8DelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructS8ByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructS8ByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *S8DelegatePInvokeByRefStdCallCaller)(S8* pcs);
+extern "C" DLL_EXPORT S8DelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructS8ByRef_StdCall_FuncPtr()
+{
+ return MarshalStructS8ByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS8ByVal_Cdecl(S8 argstr)
+{
+ //Check the Input
+ if(!IsCorrectS8(&argstr))
+ {
+ printf("\tMarshalStructS8ByVal_Cdecl: S8 param not as expected\n");
+ PrintS8(&argstr,"argstr");
+ return FALSE;
+ }
+
+ const char* lpstr = "world";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.name = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ argstr.gender = false;
+ argstr.jobNum = 1;
+ argstr.i32 = 256;
+ argstr.ui32 = 256;
+ argstr.mySByte = 64;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS8ByVal_StdCall(S8 argstr)
+{
+ //Check the Input
+ if(!IsCorrectS8(&argstr))
+ {
+ printf("\tMarshalStructS8ByVal_StdCall: S8 param not as expected\n");
+ PrintS8(&argstr,"argstr");
+ return FALSE;
+ }
+
+ const char* lpstr = "world";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.name = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ argstr.gender = false;
+ argstr.jobNum = 1;
+ argstr.i32 = 256;
+ argstr.ui32 = 256;
+ argstr.mySByte = 64;
+
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *S8ByValCdeclCaller)(S8 cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS8ByVal_Cdecl(S8ByValCdeclCaller caller)
+{
+ //Init
+ S8 argstr{};
+
+ const char* lpstr = "world";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.name = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ argstr.gender = false;
+ argstr.jobNum = 1;
+ argstr.i32 = 256;
+ argstr.ui32 = 256;
+ argstr.mySByte = 64;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS8ByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(memcmp( argstr.name,"world", strlen("world")*sizeof(char)+1 )!= 0)
+ return false;
+ if(argstr.gender)
+ return false;
+ if(argstr.jobNum != 1)
+ return false;
+ if(argstr.i32!= 256 || argstr.ui32 != 256)
+ return false;
+ if(argstr.mySByte != 64)
+ return false;
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S8ByValStdCallCaller)(S8 cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS8ByVal_StdCall(S8ByValStdCallCaller caller)
+{
+ //Init
+ S8 argstr{};
+
+ const char* lpstr = "world";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ argstr.name = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ argstr.gender = false;
+ argstr.jobNum = 1;
+ argstr.i32 = 256;
+ argstr.ui32 = 256;
+ argstr.mySByte = 64;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS8ByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(memcmp( argstr.name,"world", strlen("world")*sizeof(char)+1 )!= 0)
+ return false;
+ if(argstr.gender)
+ return false;
+ if(argstr.jobNum != 1)
+ return false;
+ if(argstr.i32!= 256 || argstr.ui32 != 256)
+ return false;
+ if(argstr.mySByte != 64)
+ return false;
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *S8DelegatePInvokeByValCdeclCaller)(S8 cs);
+extern "C" DLL_EXPORT S8DelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructS8ByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructS8ByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *S8DelegatePInvokeByValStdCallCaller)(S8 cs);
+extern "C" DLL_EXPORT S8DelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructS8ByVal_StdCall_FuncPtr()
+{
+ return MarshalStructS8ByVal_StdCall;
+}
+
+
+
+///////////////////////////////////////////Methods for S9 struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT void NtestMethod(S9 str1)
+{
+ printf("\tAction of the delegate");
+}
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS9ByRef_Cdecl(S9* argstr)
+{
+ if(argstr->i32 != 128 ||
+ argstr->myDelegate1 == NULL)
+ {
+ printf("\tMarshalStructS9ByRef_Cdecl: S9 param not as expected\n");
+ return FALSE;
+ }
+ argstr->i32 = 256;
+ argstr->myDelegate1 = NULL;
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS9ByRef_StdCall(S9* argstr)
+{
+ if(argstr->i32 != 128 ||
+ argstr->myDelegate1 == NULL)
+ {
+ printf("\tMarshalStructS9ByRef_StdCall: S9 param not as expected\n");
+ return FALSE;
+ }
+ argstr->i32 = 256;
+ argstr->myDelegate1 = NULL;
+ return TRUE;
+}
+typedef BOOL (_cdecl *S9ByRefCdeclCaller)(S9* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS9ByRef_Cdecl(S9ByRefCdeclCaller caller)
+{
+ //Init
+ S9 argstr;
+
+ argstr.i32 = 256;
+ argstr.myDelegate1 = NULL;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS9ByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(argstr.i32 != 128 ||
+ argstr.myDelegate1 == NULL)
+ {
+ printf("The parameter for DoCallBack_MarshalStructS9ByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S9ByRefStdCallCaller)(S9* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS9ByRef_StdCall(S9ByRefStdCallCaller caller)
+{
+ //Init
+ S9 argstr;
+
+ argstr.i32 = 256;
+ argstr.myDelegate1 = NULL;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS9ByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(argstr.i32 != 128 ||
+ argstr.myDelegate1 == NULL)
+ {
+ printf("The parameter for DoCallBack_MarshalStructS9ByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *S9DelegatePInvokeByRefCdeclCaller)(S9* pcs);
+extern "C" DLL_EXPORT S9DelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructS9ByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructS9ByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *S9DelegatePInvokeByRefStdCallCaller)(S9* pcs);
+extern "C" DLL_EXPORT S9DelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructS9ByRef_StdCall_FuncPtr()
+{
+ return MarshalStructS9ByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS9ByVal_Cdecl(S9 argstr)
+{
+ //Check the Input
+ if(argstr.i32 != 128 ||
+ argstr.myDelegate1 == NULL)
+ {
+ printf("\tMarshalStructS9ByVal_Cdecl: S9 param not as expected\n");
+ return FALSE;
+ }
+ argstr.i32 = 256;
+ argstr.myDelegate1 = NULL;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS9ByVal_StdCall(S9 argstr)
+{
+ //Check the Input
+ if(argstr.i32 != 128 ||
+ argstr.myDelegate1 == NULL)
+ {
+ printf("\tMarshalStructS9ByVal_StdCall: S9 param not as expected\n");
+ return FALSE;
+ }
+
+ argstr.i32 = 256;
+ argstr.myDelegate1 = NULL;
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *S9ByValCdeclCaller)(S9 cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS9ByVal_Cdecl(S9ByValCdeclCaller caller)
+{
+ //Init
+ S9 argstr;
+
+ argstr.i32 = 256;
+ argstr.myDelegate1 = NULL;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS9ByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.i32 != 256 || argstr.myDelegate1 != NULL)
+ return false;
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S9ByValStdCallCaller)(S9 cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS9ByVal_StdCall(S9ByValStdCallCaller caller)
+{
+ //Init
+ S9 argstr;
+
+ argstr.i32 = 256;
+ argstr.myDelegate1 = NULL;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS9ByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.i32 != 256 || argstr.myDelegate1 != NULL)
+ return false;
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *S9DelegatePInvokeByValCdeclCaller)(S9 cs);
+extern "C" DLL_EXPORT S9DelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructS9ByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructS9ByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *S9DelegatePInvokeByValStdCallCaller)(S9 cs);
+extern "C" DLL_EXPORT S9DelegatePInvokeByValStdCallCaller _cdecl Get_MarshalStructS9ByVal_StdCall_FuncPtr()
+{
+ return MarshalStructS9ByVal_StdCall;
+}
+
+///////////////////////////////////////////Methods for IncludeOuterIntergerStructSequential struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructIncludeOuterIntergerStructSequentialByRef_Cdecl(IncludeOuterIntergerStructSequential* argstr)
+{
+ if(!IsCorrectIncludeOuterIntergerStructSequential(argstr))
+ {
+ printf("\tMarshalStructIncludeOuterIntergerStructSequentialByRef_Cdecl: IncludeOuterIntergerStructSequential param not as expected\n");
+ PrintIncludeOuterIntergerStructSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeIncludeOuterIntergerStructSequential(argstr);
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructIncludeOuterIntergerStructSequentialByRef_StdCall(IncludeOuterIntergerStructSequential* argstr)
+{
+ if(!IsCorrectIncludeOuterIntergerStructSequential(argstr))
+ {
+ printf("\tMarshalStructIncludeOuterIntergerStructSequentialByRef_StdCall: IncludeOuterIntergerStructSequential param not as expected\n");
+ PrintIncludeOuterIntergerStructSequential(argstr,"argstr");
+ return FALSE;
+ }
+ ChangeIncludeOuterIntergerStructSequential(argstr);
+ return TRUE;
+}
+typedef BOOL (_cdecl *IncludeOuterIntergerStructSequentialByRefCdeclCaller)(IncludeOuterIntergerStructSequential* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByRef_Cdecl(IncludeOuterIntergerStructSequentialByRefCdeclCaller caller)
+{
+ //Init
+ IncludeOuterIntergerStructSequential argstr;
+
+ argstr.s.s_int.i = 64;
+ argstr.s.i = 64;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectIncludeOuterIntergerStructSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *IncludeOuterIntergerStructSequentialByRefStdCallCaller)(IncludeOuterIntergerStructSequential* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByRef_StdCall(IncludeOuterIntergerStructSequentialByRefStdCallCaller caller)
+{
+ //Init
+ IncludeOuterIntergerStructSequential argstr;
+
+ argstr.s.s_int.i = 64;
+ argstr.s.i = 64;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(!IsCorrectIncludeOuterIntergerStructSequential(&argstr))
+ {
+ printf("The parameter for DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *IncludeOuterIntergerStructSequentialDelegatePInvokeByRefCdeclCaller)(IncludeOuterIntergerStructSequential* pcs);
+extern "C" DLL_EXPORT IncludeOuterIntergerStructSequentialDelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructIncludeOuterIntergerStructSequentialByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructIncludeOuterIntergerStructSequentialByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *IncludeOuterIntergerStructSequentialDelegatePInvokeByRefStdCallCaller)(IncludeOuterIntergerStructSequential* pcs);
+extern "C" DLL_EXPORT IncludeOuterIntergerStructSequentialDelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructIncludeOuterIntergerStructSequentialByRef_StdCall_FuncPtr()
+{
+ return MarshalStructIncludeOuterIntergerStructSequentialByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructIncludeOuterIntergerStructSequentialByVal_Cdecl(IncludeOuterIntergerStructSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectIncludeOuterIntergerStructSequential(&argstr))
+ {
+ printf("\tMarshalStructIncludeOuterIntergerStructSequentialByVal_Cdecl: IncludeOuterIntergerStructSequential param not as expected\n");
+ PrintIncludeOuterIntergerStructSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ argstr.s.s_int.i = 64;
+ argstr.s.i = 64;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructIncludeOuterIntergerStructSequentialByVal_StdCall(IncludeOuterIntergerStructSequential argstr)
+{
+ //Check the Input
+ if(!IsCorrectIncludeOuterIntergerStructSequential(&argstr))
+ {
+ printf("\tMarshalStructIncludeOuterIntergerStructSequentialByVal_StdCall: IncludeOuterIntergerStructSequential param not as expected\n");
+ PrintIncludeOuterIntergerStructSequential(&argstr,"argstr");
+ return FALSE;
+ }
+
+ argstr.s.s_int.i = 64;
+ argstr.s.i = 64;
+
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *IncludeOuterIntergerStructSequentialByValCdeclCaller)(IncludeOuterIntergerStructSequential cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByVal_Cdecl(IncludeOuterIntergerStructSequentialByValCdeclCaller caller)
+{
+ //Init
+ IncludeOuterIntergerStructSequential argstr;
+
+ argstr.s.s_int.i = 64;
+ argstr.s.i = 64;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.s.s_int.i != 64)
+ return false;
+ if(argstr.s.i != 64)
+ return false;
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *IncludeOuterIntergerStructSequentialByValStdCallCaller)(IncludeOuterIntergerStructSequential cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByVal_StdCall(IncludeOuterIntergerStructSequentialByValStdCallCaller caller)
+{
+ //Init
+ IncludeOuterIntergerStructSequential argstr;
+
+ argstr.s.s_int.i = 64;
+ argstr.s.i = 64;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructIncludeOuterIntergerStructSequentialByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.s.s_int.i != 64)
+ return false;
+ if(argstr.s.i != 64)
+ return false;
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *IncludeOuterIntergerStructSequentialDelegatePInvokeByValCdeclCaller)(IncludeOuterIntergerStructSequential cs);
+extern "C" DLL_EXPORT IncludeOuterIntergerStructSequentialDelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructIncludeOuterIntergerStructSequentialByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructIncludeOuterIntergerStructSequentialByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *IncludeOuterIntergerStructSequentialDelegatePInvokeByValStdCallCaller)(IncludeOuterIntergerStructSequential cs);
+extern "C" DLL_EXPORT IncludeOuterIntergerStructSequentialDelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructIncludeOuterIntergerStructSequentialByVal_StdCall_FuncPtr()
+{
+ return MarshalStructIncludeOuterIntergerStructSequentialByVal_StdCall;
+}
+
+///////////////////////////////////////////Methods for S11 struct////////////////////////////////////////////////////
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS11ByRef_Cdecl(S11* argstr)
+{
+ if(argstr->i32 != (LPINT)(32) || argstr->i != 32)
+ {
+ printf("\tMarshalStructS11ByRef_Cdecl: S11 param not as expected\n");
+ return FALSE;
+ }
+ argstr->i32 = (LPINT)(64);
+ argstr->i = 64;
+ return TRUE;
+}
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS11ByRef_StdCall(S11* argstr)
+{
+ if(argstr->i32 != (LPINT)(32) || argstr->i != 32)
+ {
+ printf("\tMarshalStructS11ByRef_StdCall: S11 param not as expected\n");
+ return FALSE;
+ }
+ argstr->i32 = (LPINT)(64);
+ argstr->i = 64;
+ return TRUE;
+}
+typedef BOOL (_cdecl *S11ByRefCdeclCaller)(S11* pcs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS11ByRef_Cdecl(S11ByRefCdeclCaller caller)
+{
+ //Init
+ S11 argstr;
+
+ argstr.i32 = (LPINT)(64);
+ argstr.i = 64;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS11ByRef_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(argstr.i32 != (LPINT)32 || argstr.i != 32)
+ {
+ printf("The parameter for DoCallBack_MarshalStructS11ByRef_Cdecl is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S11ByRefStdCallCaller)(S11* pcs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS11ByRef_StdCall(S11ByRefStdCallCaller caller)
+{
+ //Init
+ S11 argstr;
+
+ argstr.i32 = (LPINT)(64);
+ argstr.i = 64;
+
+ if(!caller(&argstr))
+ {
+ printf("DoCallBack_MarshalStructS11ByRef_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+ //Verify the value unchanged
+ if(argstr.i32 != (LPINT)(32) || argstr.i != 32)
+ {
+ printf("The parameter for DoCallBack_MarshalStructS11ByRef_StdCall is wrong\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+//Delegate PInvoke,passbyref
+typedef BOOL (_cdecl *S11DelegatePInvokeByRefCdeclCaller)(S11* pcs);
+extern "C" DLL_EXPORT S11DelegatePInvokeByRefCdeclCaller _cdecl Get_MarshalStructS11ByRef_Cdecl_FuncPtr()
+{
+ return MarshalStructS11ByRef_Cdecl;
+}
+
+typedef BOOL (__stdcall *S11DelegatePInvokeByRefStdCallCaller)(S11* pcs);
+extern "C" DLL_EXPORT S11DelegatePInvokeByRefStdCallCaller __stdcall Get_MarshalStructS11ByRef_StdCall_FuncPtr()
+{
+ return MarshalStructS11ByRef_StdCall;
+}
+
+
+//Passby value
+extern "C" DLL_EXPORT BOOL _cdecl MarshalStructS11ByVal_Cdecl(S11 argstr)
+{
+ //Check the Input
+ if(argstr.i32 != (LPINT)(32) || argstr.i != 32)
+ {
+ printf("\tMarshalStructS11ByVal_Cdecl: S11 param not as expected\n");
+ return FALSE;
+ }
+
+ argstr.i32 = (LPINT)(64);
+ argstr.i = 64;
+
+ return TRUE;
+}
+
+extern "C" DLL_EXPORT BOOL __stdcall MarshalStructS11ByVal_StdCall(S11 argstr)
+{
+ //Check the Input
+ if(argstr.i32 != (LPINT)(32) || argstr.i != 32)
+ {
+ printf("\tMarshalStructS11ByVal_StdCall: S11 param not as expected\n");
+ return FALSE;
+ }
+
+ argstr.i32 = (LPINT)(64);
+ argstr.i = 64;
+
+ return TRUE;
+}
+
+typedef BOOL (_cdecl *S11ByValCdeclCaller)(S11 cs);
+extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalStructS11ByVal_Cdecl(S11ByValCdeclCaller caller)
+{
+ //Init
+ S11 argstr;
+
+ argstr.i32 = (LPINT)(64);
+ argstr.i = 64;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS11ByVal_Cdecl:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.i32 != (LPINT)(64) || argstr.i != 64)
+ return false;
+
+ return TRUE;
+}
+
+typedef BOOL (__stdcall *S11ByValStdCallCaller)(S11 cs);
+extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalStructS11ByVal_StdCall(S11ByValStdCallCaller caller)
+{
+ //Init
+ S11 argstr;
+
+ argstr.i32 = (LPINT)(64);
+ argstr.i = 64;
+
+ if(!caller(argstr))
+ {
+ printf("DoCallBack_MarshalStructS11ByVal_StdCall:The Caller returns wrong value\n");
+ return FALSE;
+ }
+
+ //Verify the value unchanged
+ if(argstr.i32 != (LPINT)(64) || argstr.i != 64)
+ return false;
+ return TRUE;
+}
+//Delegate PInvoke,passbyval
+typedef BOOL (_cdecl *S11DelegatePInvokeByValCdeclCaller)(S11 cs);
+extern "C" DLL_EXPORT S11DelegatePInvokeByValCdeclCaller _cdecl Get_MarshalStructS11ByVal_Cdecl_FuncPtr()
+{
+ return MarshalStructS11ByVal_Cdecl;
+}
+
+typedef BOOL (__stdcall *S11DelegatePInvokeByValStdCallCaller)(S11 cs);
+extern "C" DLL_EXPORT S11DelegatePInvokeByValStdCallCaller __stdcall Get_MarshalStructS11ByVal_StdCall_FuncPtr()
+{
+ return MarshalStructS11ByVal_StdCall;
+}
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.h b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.h
new file mode 100644
index 0000000000..6022d5aeab
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.h
@@ -0,0 +1,881 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <xplatform.h>
+
+const int NumArrElements = 2;
+struct InnerSequential
+{
+ int f1;
+ float f2;
+ LPCSTR f3;
+};
+
+void PrintInnerSequential(InnerSequential* p, const char* name)
+{
+ printf("\t%s.f1 = %d\n", name, p->f1);
+ printf("\t%s.f2 = %f\n", name, p->f2);
+ printf("\t%s.f3 = %s\n", name, p->f3);
+}
+
+void ChangeInnerSequential(InnerSequential* p)
+{
+ p->f1 = 77;
+ p->f2 = 77.0;
+
+ const char* lpstr = "changed string";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ p->f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+}
+
+bool IsCorrectInnerSequential(InnerSequential* p)
+{
+ if(p->f1 != 1)
+ return false;
+ if(p->f2 != 1.0)
+ return false;
+ if( strcmp((char*)p->f3,"some string") != 0 )
+ return false;
+ return true;
+}
+
+struct INNER2 // size = 12 bytes
+{
+ INT f1;
+ FLOAT f2;
+ LPCSTR f3;
+};
+
+void ChangeINNER2(INNER2* p)
+{
+ p->f1 = 77;
+ p->f2 = 77.0;
+ const char* temp = "changed string";
+ size_t len = strlen(temp);
+ LPCSTR str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ strcpy_s((char*)str,len+1,temp);
+ p->f3 = str;
+}
+
+void PrintINNER2(INNER2* p, const char* name)
+{
+ printf("\t%s.f1 = %d\n", name, p->f1);
+ printf("\t%s.f2 = %f\n", name, p->f2);
+ printf("\t%s.f3 = %s\n", name, p->f3);
+}
+
+bool IsCorrectINNER2(INNER2* p)
+{
+ if(p->f1 != 1)
+ return false;
+ if(p->f2 != 1.0)
+ return false;
+ if(memcmp(p->f3, "some string",11*sizeof(char)) != 0 )
+ return false;
+ return true;
+}
+
+struct InnerExplicit
+{
+#ifdef WINDOWS
+ union
+ {
+ INT f1;
+ FLOAT f2;
+ };
+ CHAR _unused0[4];
+ LPCSTR f3;
+#else
+ union
+ {
+ INT f1;
+ FLOAT f2;
+ };
+ INT _unused0;
+ LPCSTR f3;
+#endif
+};
+
+void PrintInnerExplicit(InnerExplicit* p, const char* name)
+{
+ printf("\t%s.f1 = %d\n", name, p->f1);
+ printf("\t%s.f2 = %f\n", name, p->f2);
+ printf("\t%s.f3 = %s\n", name, p->f3);
+}
+
+void ChangeInnerExplicit(InnerExplicit* p)
+{
+ p->f1 = 77;
+
+ const char* temp = "changed string";
+ size_t len = strlen(temp);
+ LPCSTR str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ strcpy_s((char*)str,len+1,temp);
+ p->f3 = str;
+}
+
+struct InnerArraySequential
+{
+ InnerSequential arr[NumArrElements];
+};
+
+void PrintInnerArraySequential(InnerArraySequential* p, const char* name)
+{
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1);
+ printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2);
+ printf("\t%s.arr[%d].f2 = %s\n", name, i, (p->arr)[i].f3);
+ }
+}
+
+void ChangeInnerArraySequential(InnerArraySequential* p)
+{
+ const char* lpstr = "changed string";
+ LPSTR temp;
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ (p->arr)[i].f1 = 77;
+ (p->arr)[i].f2 = 77.0;
+
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ (p->arr)[i].f3 = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ }
+}
+
+bool IsCorrectInnerArraySequential(InnerArraySequential* p)
+{
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ if( (p->arr)[i].f1 != 1 )
+ return false;
+ if( (p->arr)[i].f2 != 1.0 )
+ return false;
+ }
+ return true;
+}
+
+#ifdef WINDOWS
+#ifdef _WIN64
+union OUTER3 // size = 32 bytes
+{
+ struct InnerSequential arr[2];
+ struct
+ {
+ CHAR _unused0[24];
+ LPCSTR f4;
+ };
+};
+#else
+struct OUTER3 // size = 28 bytes
+{
+ struct InnerSequential arr[2];
+ LPCSTR f4;
+};
+#endif
+#else
+struct OUTER3 // size = 28 bytes
+{
+ struct InnerSequential arr[2];
+ LPCSTR f4;
+};
+#endif
+
+void PrintOUTER3(OUTER3* p, const char* name)
+{
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1);
+ printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2);
+ printf("\t%s.arr[%d].f3 = %s\n", name, i, (p->arr)[i].f3);
+ }
+ printf("\t%s.f4 = %s\n",name,p->f4);
+}
+
+void ChangeOUTER3(OUTER3* p)
+{
+ const char* temp = "changed string";
+ size_t len = strlen(temp);
+ LPCSTR str = NULL;
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ (p->arr)[i].f1 = 77;
+ (p->arr)[i].f2 = 77.0;
+
+ str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ strcpy_s((char*)str,len+1,temp);
+ (p->arr)[i].f3 = str;
+ }
+
+ str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) );
+ strcpy_s((char*)str,len+1,temp);
+ p->f4 = str;
+}
+
+bool IsCorrectOUTER3(OUTER3* p)
+{
+ for(int i = 0; i < NumArrElements; i++)
+ {
+ if( (p->arr)[i].f1 != 1 )
+ return false;
+ if( (p->arr)[i].f2 != 1.0 )
+ return false;
+ if( memcmp((p->arr)[i].f3, "some string",11*sizeof(char)) != 0 )
+ return false;
+ }
+ if(memcmp(p->f4,"some string",11*sizeof(char)) != 0)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct CharSetAnsiSequential
+{
+ LPCSTR f1;
+ char f2;
+};
+
+void PrintCharSetAnsiSequential(CharSetAnsiSequential* p, const char* name)
+{
+ printf("\t%s.f1 = %s\n", name, p->f1);
+ printf("\t%s.f2 = %c\n", name, p->f2);
+}
+
+void ChangeCharSetAnsiSequential(CharSetAnsiSequential* p)
+{
+ const char* strSource = "change string";
+ size_t size = strlen(strSource) + 1;
+ LPSTR temp = (LPSTR)CoreClrAlloc(size);
+ if(temp != NULL)
+ {
+ strcpy_s((char*)temp,size,strSource);
+ p->f1 = temp;
+ p->f2 = 'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+}
+
+bool IsCorrectCharSetAnsiSequential(CharSetAnsiSequential* p)
+{
+ if(strcmp((char*)p->f1, (char*)"some string") != 0 )
+ return false;
+ if(p->f2 != 'c')
+ return false;
+ return true;
+}
+
+
+struct CharSetUnicodeSequential
+{
+ LPCWSTR f1;
+ WCHAR f2;
+};
+
+void PrintCharSetUnicodeSequential(CharSetUnicodeSequential* p, const char* name)
+{
+#ifdef _WIN32
+ wprintf(L"\t%S.first = %s\n", name, p->f1);
+ wprintf(L"\t%S.last = %c\n", name, p->f2);
+#else
+ wprintf(L"\t%s.first = %s\n", name, p->f1);
+ wprintf(L"\t%s.last = %c\n", name, p->f2);
+#endif
+}
+
+void ChangeCharSetUnicodeSequential(CharSetUnicodeSequential* p)
+{
+ LPCWSTR strSource = W("change string");
+ size_t len = wcslen(strSource);
+ LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
+ if(temp != NULL)
+ {
+ wcscpy_s((WCHAR*)temp, (len+1), strSource);
+ p->f1 = temp;
+ p->f2 = L'n';
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+}
+
+bool IsCorrectCharSetUnicodeSequential(CharSetUnicodeSequential* p)
+{
+ LPCWSTR expected= W("some string");
+ LPCWSTR actual = p->f1;
+ if(0 != wcscmp(actual, expected))
+ {
+ return false;
+ }
+ if(p->f2 != L'c')
+ {
+ return false;
+ }
+ return true;
+}
+
+struct NumberSequential // size = 64 bytes
+{
+ LONG64 i64;
+ ULONG64 ui64;
+ DOUBLE d;
+ INT i32;
+ UINT ui32;
+ SHORT s1;
+ WORD us1;
+ SHORT i16;
+ WORD ui16;
+ FLOAT sgl;
+ BYTE b;
+ CHAR sb;
+};
+
+void PrintNumberSequential(NumberSequential* str, const char* name)
+{
+ printf("\t%s.i32 = %d\n", name, str->i32);
+ printf("\t%s.ui32 = %d\n", name, str->ui32);
+ printf("\t%s.s1 = %d\n", name, str->s1);
+ printf("\t%s.us1 = %u\n", name, str->us1);
+ printf("\t%s.b = %u\n", name, str->b);
+ printf("\t%s.sb = %d\n", name, str->sb);
+ printf("\t%s.i16 = %d\n", name, str->i16);
+ printf("\t%s.ui16 = %u\n", name, str->ui16);
+ printf("\t%s.i64 = %lld\n", name, str->i64);
+ printf("\t%s.ui64 = %llu\n", name, str->ui64);
+ printf("\t%s.sgl = %f\n", name, str->sgl);
+ printf("\t%s.d = %f\n",name, str->d);
+}
+
+void ChangeNumberSequential(NumberSequential* p)
+{
+ p->i32 = 0;
+ p->ui32 = 32;
+ p->s1 = 0;
+ p->us1 = 16;
+ p->b = 0;
+ p->sb = 8;
+ p->i16 = 0;
+ p->ui16 = 16;
+ p->i64 = 0;
+ p->ui64 = 64;
+ p->sgl = 64.0;
+ p->d = 6.4;
+}
+
+bool IsCorrectNumberSequential(NumberSequential* p)
+{
+ if(p->i32 != INT_MIN || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 ||
+ p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 ||
+ p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct S3 // size = 1032 bytes
+{
+ BOOL flag;
+ LPCSTR str;
+ INT vals[256];
+};
+
+void PrintS3(S3* str, const char* name)
+{
+ printf("\t%s.flag = %d\n", name, str->flag);
+ printf("\t%s.str = %s\n", name, str->str);
+ for(int i = 0; i<256 ;i++)
+ {
+ printf("\t%s.vals[%d] = %d\n",name,i,str->vals[i]);
+ }
+}
+
+void ChangeS3(S3* p)
+{
+ p->flag = false;
+
+ const char* strSource = "change string";
+ size_t len = strlen(strSource);
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*(len+1));
+ if(temp != NULL)
+ {
+ memset((LPVOID)temp,0,len+1);
+ strncpy_s((char*)temp,len+1,strSource,len);
+ p->str = temp;
+ }
+ for(int i = 1;i<257;i++)
+ {
+ p->vals[i-1] = i;
+ }
+}
+
+bool IsCorrectS3(S3* p)
+{
+ int iflag = 0;
+ if(!p->flag || strcmp((char*)p->str,"some string") != 0)
+ return false;
+ for (int i = 0; i < 256; i++)
+ {
+ if (p->vals[i] != i)
+ {
+ printf("\tThe Index of %i is not expected",i);
+ iflag++;
+ }
+ }
+ if (iflag != 0)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct S4 // size = 8 bytes
+{
+ INT age;
+ LPCSTR name;
+};
+
+enum Enum1
+{
+ e1 = 1,
+ e2 = 3
+};
+
+struct S5 // size = 8 bytes
+{
+ struct S4 s4;
+ Enum1 ef;
+};
+
+void PrintS5(S5* str, const char* name)
+{
+ printf("\t%s.s4.age = %d", name, str->s4.age);
+ printf("\t%s.s4.name = %s", name, str->s4.name);
+ printf("\t%s.ef = %d", name, str->ef);
+}
+
+void ChangeS5(S5* str)
+{
+ Enum1 eInstance = e2;
+ const char* strSource = "change string";
+ size_t len = strlen(strSource);
+ LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*(len+1));
+ if(temp != NULL)
+ {
+ memset((LPVOID)temp,0,len+1);
+ strncpy_s((char*)temp,len+1,strSource,len);
+ str->s4.name = temp;
+ }
+ str->s4.age = 64;
+ str->ef = eInstance;
+}
+
+bool IsCorrectS5(S5* str)
+{
+ Enum1 eInstance = e1;
+ if(str->s4.age != 32 || strcmp((char*)str->s4.name,"some string") != 0)
+ return false;
+ if(str->ef != eInstance)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct StringStructSequentialAnsi // size = 8 bytes
+{
+ LPCSTR first;
+ LPCSTR last;
+};
+
+void PrintStringStructSequentialAnsi(StringStructSequentialAnsi* str, const char* name)
+{
+ printf("\t%s.first = %s\n", name, str->first);
+ printf("\t%s.last = %s\n", name, str->last);
+}
+
+bool IsCorrectStringStructSequentialAnsi(StringStructSequentialAnsi* str)
+{
+ char strOne[512];
+ char strTwo[512];
+ for(int i = 0;i<512;i++)
+ {
+ strOne[i] = 'a';
+ strTwo[i] = 'b';
+ }
+
+ if(memcmp(str->first,strOne,512)!= 0)
+ return false;
+
+ if(memcmp(str->last,strTwo,512)!= 0)
+ return false;
+
+ return true;
+}
+
+void ChangeStringStructSequentialAnsi(StringStructSequentialAnsi* str)
+{
+ char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
+ char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
+ for (int i = 0; i < 512; ++i)
+ {
+ newFirst[i] = 'b';
+ newLast[i] = 'a';
+ }
+ newFirst[512] = '\0';
+ newLast[512] = '\0';
+
+ str->first = newFirst;
+ str->last = newLast;
+}
+
+struct StringStructSequentialUnicode // size = 8 bytes
+{
+ LPCWSTR first;
+ LPCWSTR last;
+};
+
+void PrintStringStructSequentialUnicode(StringStructSequentialUnicode* str, const char* name)
+{
+#ifdef _WIN32
+ wprintf(L"\t%S.first = %s\n", name, str->first);
+ wprintf(L"\t%S.last = %s\n", name, str->last);
+#else
+ wprintf(L"\t%s.first = %s\n", name, str->first);
+ wprintf(L"\t%s.last = %s\n", name, str->last);
+#endif
+}
+
+bool IsCorrectStringStructSequentialUnicode(StringStructSequentialUnicode* str)
+{
+ WCHAR strOne[256+1];
+ WCHAR strTwo[256+1];
+
+ for(int i = 0;i<256;++i)
+ {
+ strOne[i] = L'a';
+ strTwo[i] = L'b';
+ }
+ strOne[256] = L'\0';
+ strTwo[256] = L'\0';
+
+ if(memcmp(str->first,strOne,256*sizeof(WCHAR)) != 0)
+ return false;
+ if(memcmp(str->last,strTwo,256*sizeof(WCHAR)) != 0)
+ return false;
+ return true;
+}
+
+void ChangeStringStructSequentialUnicode(StringStructSequentialUnicode* str)
+{
+ WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
+ for (int i = 0; i < 256; ++i)
+ {
+ newFirst[i] = L'b';
+ newLast[i] = L'a';
+ }
+ newFirst[256] = L'\0';
+ newLast[256] = L'\0';
+ str->first = (const WCHAR*)newFirst;
+ str->last = (const WCHAR*)newLast;
+}
+
+struct S8 // size = 32 bytes
+{
+ LPCSTR name;
+ BOOL gender;
+ HRESULT i32;
+ HRESULT ui32;
+ WORD jobNum;
+ CHAR mySByte;
+};
+
+void PrintS8(S8* str, const char* name)
+{
+ printf("\t%s.name = %s\n",name, str->name);
+ printf("\t%s.gender = %d\n", name, str->gender);
+ printf("\t%s.jobNum = %d\n",name, str->jobNum);
+ printf("\t%s.i32 = %d\n", name, (int)(str->i32));
+ printf("\t%s.ui32 = %u\n", name, (unsigned int)(str->ui32));
+ printf("\t%s.mySByte = %c\n", name, str->mySByte);
+}
+
+bool IsCorrectS8(S8* str)
+{
+ if(memcmp( str->name,"hello", strlen("hello")*sizeof(char)+1 )!= 0)
+ return false;
+ if(!str->gender)
+ return false;
+ if(str->jobNum != 10)
+ return false;
+ if(str->i32!= 128 || str->ui32 != 128)
+ return false;
+ if(str->mySByte != 32)
+ return false;
+ return true;
+}
+
+void ChangeS8(S8* str)
+{
+ const char* lpstr = "world";
+ size_t size = sizeof(char) * (strlen(lpstr) + 1);
+ LPSTR temp = (LPSTR)CoreClrAlloc( size );
+ memset(temp, 0, size);
+ if(temp)
+ {
+ strcpy_s((char*)temp,size,lpstr);
+ str->name = temp;
+ }
+ else
+ {
+ printf("Memory Allocated Failed!");
+ }
+ str->gender = false;
+ str->jobNum = 1;
+ str->i32 = 256;
+ str->ui32 = 256;
+ str->mySByte = 64;
+}
+
+#pragma pack (8)
+struct IntergerStructSequential // size = 4 bytes
+{
+ INT i;
+};
+
+struct S9;
+typedef void (*TestDelegate1)(struct S9 myStruct);
+
+struct S9 // size = 8 bytes
+{
+ HRESULT i32;
+ TestDelegate1 myDelegate1;
+};
+
+struct OuterIntergerStructSequential // size = 8 bytes
+{
+ INT i;
+ struct IntergerStructSequential s_int;
+};
+
+struct IncludeOuterIntergerStructSequential // size = 8 bytes
+{
+ struct OuterIntergerStructSequential s;
+};
+
+void PrintIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential* str, const char* name)
+{
+ printf("\t%s.s.s_int.i = %d\n", name, str->s.s_int.i);
+ printf("\t%s.s.i = %d\n", name, str->s.i);
+}
+
+bool IsCorrectIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential* str)
+{
+ if(str->s.s_int.i != 32)
+ return false;
+ if(str->s.i != 32)
+ return false;
+ return true;
+}
+
+void ChangeIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential* str)
+{
+ str->s.s_int.i = 64;
+ str->s.i = 64;
+}
+
+#ifndef WINDOWS
+typedef int* LPINT;
+#endif
+
+struct S11 // size = 8 bytes
+{
+ LPINT i32;
+ INT i;
+};
+
+union U // size = 8 bytes
+{
+ INT i32;
+ UINT ui32;
+ LPVOID iPtr;
+ LPVOID uiPtr;
+ SHORT s;
+ WORD us;
+ BYTE b;
+ CHAR sb;
+ LONG64 l;
+ ULONG64 ul;
+ FLOAT f;
+ DOUBLE d;
+};
+
+void PrintU(U* str, const char* name)
+{
+ printf("\t%s.i32 = %d\n", name, str->i32);
+ printf("\t%s.ui32 = %u\n", name, str->ui32);
+ printf("\t%s.iPtr = %zu\n", name, (size_t)(str->iPtr));
+ printf("\t%s.uiPtr = %zu\n", name, (size_t)(str->uiPtr));
+ printf("\t%s.s = %d\n", name, str->s);
+ printf("\t%s.us = %u\n", name, str->us);
+ printf("\t%s.b = %u\n", name, str->b);
+ printf("\t%s.sb = %d\n", name, str->sb);
+ printf("\t%s.l = %lld\n", name, str->l);
+ printf("\t%s.ul = %llu\n", name, str->ul);
+ printf("\t%s.f = %f\n", name, str->f);
+ printf("\t%s.d = %f\n", name, str->d);
+}
+
+void ChangeU(U* p)
+{
+ p->i32 = 2147483647;
+ p->ui32 = 0;
+ p->iPtr = (LPVOID)(-64);
+ p->uiPtr = (LPVOID)(64);
+ p->s = 32767;
+ p->us = 0;
+ p->b = 255;
+ p->sb = -128;
+ p->l = -1234567890;
+ p->ul = 0;
+ p->f = 64.0;
+ p->d = 6.4;
+}
+
+bool IsCorrectU(U* p)
+{
+ if(p->d != 3.2)
+ {
+ return false;
+ }
+ return true;
+}
+
+struct ByteStructPack2Explicit // size = 2 bytes
+{
+ BYTE b1;
+ BYTE b2;
+};
+
+void PrintByteStructPack2Explicit(ByteStructPack2Explicit* str, const char* name)
+{
+ printf("\t%s.b1 = %d", name, str->b1);
+ printf("\t%s.b2 = %d", name, str->b2);
+}
+
+void ChangeByteStructPack2Explicit(ByteStructPack2Explicit* p)
+{
+ p->b1 = 64;
+ p->b2 = 64;
+}
+
+bool IsCorrectByteStructPack2Explicit(ByteStructPack2Explicit* p)
+{
+ if(p->b1 != 32 || p->b2 != 32)
+ return false;
+ return true;
+}
+
+struct ShortStructPack4Explicit // size = 4 bytes
+{
+ SHORT s1;
+ SHORT s2;
+};
+
+void PrintShortStructPack4Explicit(ShortStructPack4Explicit* str, const char* name)
+{
+ printf("\t%s.s1 = %d", name, str->s1);
+ printf("\t%s.s2 = %d", name, str->s2);
+}
+
+void ChangeShortStructPack4Explicit(ShortStructPack4Explicit* p)
+{
+ p->s1 = 64;
+ p->s2 = 64;
+}
+
+bool IsCorrectShortStructPack4Explicit(ShortStructPack4Explicit* p)
+{
+ if(p->s1 != 32 || p->s2 != 32)
+ return false;
+ return true;
+}
+
+struct IntStructPack8Explicit // size = 8 bytes
+{
+ INT i1;
+ INT i2;
+};
+
+void PrintIntStructPack8Explicit(IntStructPack8Explicit* str, const char* name)
+{
+ printf("\t%s.i1 = %d", name, str->i1);
+ printf("\t%s.i2 = %d", name, str->i2);
+}
+
+void ChangeIntStructPack8Explicit(IntStructPack8Explicit* p)
+{
+ p->i1 = 64;
+ p->i2 = 64;
+}
+
+bool IsCorrectIntStructPack8Explicit(IntStructPack8Explicit* p)
+{
+ if(p->i1 != 32 || p->i2 != 32)
+ return false;
+ return true;
+}
+
+struct LongStructPack16Explicit // size = 16 bytes
+{
+ LONG64 l1;
+ LONG64 l2;
+};
+
+void PrintLongStructPack16Explicit(LongStructPack16Explicit* str, const char* name)
+{
+ printf("\t%s.l1 = %lld", name, str->l1);
+ printf("\t%s.l2 = %lld", name, str->l2);
+}
+
+void ChangeLongStructPack16Explicit(LongStructPack16Explicit* p)
+{
+ p->l1 = 64;
+ p->l2 = 64;
+}
+
+bool IsCorrectLongStructPack16Explicit(LongStructPack16Explicit* p)
+{
+ if(p->l1 != 32 || p->l2 != 32)
+ return false;
+ return true;
+}
diff --git a/tests/src/Interop/StructMarshalling/ReversePInvoke/Struct.cs b/tests/src/Interop/StructMarshalling/ReversePInvoke/Struct.cs
new file mode 100644
index 0000000000..07edd32cbf
--- /dev/null
+++ b/tests/src/Interop/StructMarshalling/ReversePInvoke/Struct.cs
@@ -0,0 +1,279 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Common
+{
+ public const int NumArrElements = 2;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct InnerSequential
+{
+ public int f1;
+ public float f2;
+ public String f3;
+}
+
+[StructLayout(LayoutKind.Explicit)]
+public struct INNER2
+{
+ [FieldOffset(0)]
+ public int f1;
+ [FieldOffset(4)]
+ public float f2;
+ [FieldOffset(8)]
+ public String f3;
+}
+
+[StructLayout(LayoutKind.Explicit)]
+public struct InnerExplicit
+{
+ [FieldOffset(0)]
+ public int f1;
+ [FieldOffset(0)]
+ public float f2;
+ [FieldOffset(8)]
+ public String f3;
+}
+
+[StructLayout(LayoutKind.Sequential)]//struct containing one field of array type
+public struct InnerArraySequential
+{
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = Common.NumArrElements)]
+ public InnerSequential[] arr;
+}
+
+[StructLayout(LayoutKind.Explicit, Pack = 8)]
+public struct InnerArrayExplicit
+{
+ [FieldOffset(0)]
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = Common.NumArrElements)]
+ public InnerSequential[] arr;
+
+ [FieldOffset(8)]
+ public string f4;
+}
+
+[StructLayout(LayoutKind.Explicit)]
+public struct OUTER3
+{
+ [FieldOffset(0)]
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = Common.NumArrElements)]
+ public InnerSequential[] arr;
+
+ [FieldOffset(24)]
+ public string f4;
+}
+
+[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+public struct CharSetAnsiSequential
+{
+ public string f1;
+ public char f2;
+}
+
+[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+public struct CharSetUnicodeSequential
+{
+ public string f1;
+ public char f2;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct NumberSequential
+{
+ public Int64 i64;
+ public UInt64 ui64;
+ public Double d;
+ public int i32;
+ public uint ui32;
+ public short s1;
+ public ushort us1;
+ public Int16 i16;
+ public UInt16 ui16;
+ public Single sgl;
+ public Byte b;
+ public SByte sb;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct S3
+{
+ public bool flag;
+ public string str;
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
+ public int[] vals;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct S4
+{
+ public int age;
+ public string name;
+}
+
+public enum Enum1 { e1 = 1, e2 = 3 };
+
+[StructLayout(LayoutKind.Sequential)]
+public struct S5
+{
+ public S4 s4;
+ public Enum1 ef;
+}
+
+[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+public struct StringStructSequentialAnsi
+{
+ public string first;
+ public string last;
+}
+
+[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+public struct StringStructSequentialUnicode
+{
+ public string first;
+ public string last;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct S8
+{
+ public string name;
+ public bool gender;
+ [MarshalAs(UnmanagedType.Error)] //In ProjectN, MarshalAsError isnt supported in V1
+ public int i32;
+ [MarshalAs(UnmanagedType.Error)]
+ public uint ui32;
+ [MarshalAs(UnmanagedType.U2)]
+ public UInt16 jobNum;
+ [MarshalAs(UnmanagedType.I1)]
+ public sbyte mySByte;
+}
+
+public struct S9
+{
+ [MarshalAs(UnmanagedType.Error)]
+ public int i32;
+ public TestDelegate1 myDelegate1;
+}
+
+public delegate void TestDelegate1(S9 myStruct);
+
+[StructLayout(LayoutKind.Sequential)]
+public struct IntergerStructSequential
+{
+ public int i;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct OuterIntergerStructSequential
+{
+ public int i;
+ public IntergerStructSequential s_int;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct IncludeOuterIntergerStructSequential
+{
+ public OuterIntergerStructSequential s;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public unsafe struct S11
+{
+ public int* i32;
+ public int i;
+}
+
+[StructLayout(LayoutKind.Explicit)]
+public struct U
+{
+ [FieldOffset(0)]
+ public int i32;
+ [FieldOffset(0)]
+ public uint ui32;
+ [FieldOffset(0)]
+ public IntPtr iPtr;
+ [FieldOffset(0)]
+ public UIntPtr uiPtr;
+ [FieldOffset(0)]
+ public short s;
+ [FieldOffset(0)]
+ public ushort us;
+ [FieldOffset(0)]
+ public Byte b;
+ [FieldOffset(0)]
+ public SByte sb;
+ [FieldOffset(0)]
+ public long l;
+ [FieldOffset(0)]
+ public ulong ul;
+ [FieldOffset(0)]
+ public float f;
+ [FieldOffset(0)]
+ public Double d;
+}
+
+[StructLayout(LayoutKind.Explicit, Size = 2)]
+public struct ByteStructPack2Explicit
+{
+ [FieldOffset(0)]
+ public byte b1;
+ [FieldOffset(1)]
+ public byte b2;
+}
+
+[StructLayout(LayoutKind.Explicit, Size = 4)]
+public struct ShortStructPack4Explicit
+{
+ [FieldOffset(0)]
+ public short s1;
+ [FieldOffset(2)]
+ public short s2;
+}
+
+[StructLayout(LayoutKind.Explicit, Size = 8)]
+public struct IntStructPack8Explicit
+{
+ [FieldOffset(0)]
+ public int i1;
+ [FieldOffset(4)]
+ public int i2;
+}
+
+[StructLayout(LayoutKind.Explicit, Size = 16)]
+public struct LongStructPack16Explicit
+{
+ [FieldOffset(0)]
+ public long l1;
+ [FieldOffset(8)]
+ public long l2;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct ComplexStruct
+{
+ public int i;
+ [MarshalAs(UnmanagedType.I1)]
+ public bool b;
+ public string str;
+ public IntPtr pedding;
+ public ScriptParamType type;
+}
+
+[StructLayout(LayoutKind.Explicit)]
+public struct ScriptParamType
+{
+ [FieldOffset(0)]
+ public int idata;
+ [FieldOffset(8)]
+ public bool bdata;
+ [FieldOffset(8)]
+ public double ddata;
+ [FieldOffset(8)]
+ public IntPtr ptrdata;
+}
diff --git a/tests/src/Interop/common/xplatform.h b/tests/src/Interop/common/xplatform.h
index 94a693e384..158961ff19 100644
--- a/tests/src/Interop/common/xplatform.h
+++ b/tests/src/Interop/common/xplatform.h
@@ -142,12 +142,14 @@ size_t strcpy_s(char *dest, size_t n, char const *src)
return snprintf(dest, n, "%s", src);
}
+#ifndef wcslen
size_t wcslen(const WCHAR *str)
{
size_t len = 0;
while ('\0' != *(str + len)) len++;
return len;
}
+#endif
int wcsncpy_s(LPWSTR strDestination, size_t size1, LPCWSTR strSource, size_t size2)
{