}
#ifndef CROSSGEN_COMPILE
+
+#ifdef TARGET_WINDOWS
FARPROC NDirectMethodDesc::FindEntryPointWithMangling(NATIVE_LIBRARY_HANDLE hMod, PTR_CUTF8 entryPointName) const
{
CONTRACTL
}
CONTRACTL_END;
-#ifndef TARGET_UNIX
FARPROC pFunc = GetProcAddress(hMod, entryPointName);
-#else
- FARPROC pFunc = PAL_GetProcAddressDirect(hMod, entryPointName);
-#endif
#if defined(TARGET_X86)
return pFunc;
}
+#endif
//*******************************************************************************
LPVOID NDirectMethodDesc::FindEntryPoint(NATIVE_LIBRARY_HANDLE hMod) const
char const * funcName = GetEntrypointName();
- FARPROC pFunc = NULL;
-
-#ifndef TARGET_UNIX
+#ifndef TARGET_WINDOWS
+ return reinterpret_cast<LPVOID>(PAL_GetProcAddressDirect(hMod, funcName));
+#else
// Handle ordinals.
if (funcName[0] == '#')
{
long ordinal = atol(funcName + 1);
return reinterpret_cast<LPVOID>(GetProcAddress(hMod, (LPCSTR)(size_t)((UINT16)ordinal)));
}
-#endif
- // Just look for the user-provided name without charset suffixes. If it is unicode fcn, we are going
+ // Just look for the user-provided name without charset suffixes.
+ // If it is unicode fcn, we are going
// to need to check for the 'W' API because it takes precedence over the
// unmangled one (on NT some APIs have unmangled ANSI exports).
- pFunc = FindEntryPointWithMangling(hMod, funcName);
+ FARPROC pFunc = FindEntryPointWithMangling(hMod, funcName);
if ((pFunc != NULL && IsNativeAnsi()) || IsNativeNoMangled())
{
return reinterpret_cast<LPVOID>(pFunc);
}
return reinterpret_cast<LPVOID>(pFunc);
+#endif
}
#endif // CROSSGEN_COMPILE
using System;
using System.Runtime.InteropServices;
+using TestLibrary;
class ExactSpellingTest
{
public static extern int Marshal_Int_InOut2([In, Out] int intValue);
}
- public static int Main(string[] args)
+ private static void ExactSpellingTrue()
{
- int failures = 0;
int intManaged = 1000;
int intNative = 2000;
int intReturn = 3000;
-
+
Console.WriteLine("Method Unicode.Marshal_Int_InOut: ExactSpelling = true");
int int1 = intManaged;
int intRet1 = Unicode.Marshal_Int_InOut(int1);
- failures += Verify(intReturn, intManaged, intRet1, int1);
-
+ Verify(intReturn, intManaged, intRet1, int1);
+
Console.WriteLine("Method Unicode.MarshalPointer_Int_InOut: ExactSpelling = true");
int int2 = intManaged;
int intRet2 = Unicode.MarshalPointer_Int_InOut(ref int2);
-
- failures += Verify(intReturn, intNative, intRet2, int2);
+
+ Verify(intReturn, intNative, intRet2, int2);
Console.WriteLine("Method Ansi.Marshal_Int_InOut: ExactSpelling = true");
int int3 = intManaged;
int intRet3 = Ansi.Marshal_Int_InOut(int3);
- failures += Verify(intReturn, intManaged, intRet3, int3);
+ Verify(intReturn, intManaged, intRet3, int3);
Console.WriteLine("Method Ansi.MarshalPointer_Int_InOut: ExactSpelling = true");
int int4 = intManaged;
int intRet4 = Ansi.MarshalPointer_Int_InOut(ref int4);
- failures += Verify(intReturn, intNative, intRet4, int4);
+ Verify(intReturn, intNative, intRet4, int4);
+ }
+ private static void ExactSpellingFalse_Windows()
+ {
+ int intManaged = 1000;
+ int intNative = 2000;
int intReturnAnsi = 4000;
int intReturnUnicode = 5000;
Console.WriteLine("Method Unicode.Marshal_Int_InOut2: ExactSpelling = false");
int int5 = intManaged;
int intRet5 = Unicode.Marshal_Int_InOut2(int5);
- failures += Verify(intReturnUnicode, intManaged, intRet5, int5);
-
+ Verify(intReturnUnicode, intManaged, intRet5, int5);
+
Console.WriteLine("Method Unicode.MarshalPointer_Int_InOut2: ExactSpelling = false");
int int6 = intManaged;
int intRet6 = Unicode.MarshalPointer_Int_InOut2(ref int6);
- failures += Verify(intReturnUnicode, intNative, intRet6, int6);
+ Verify(intReturnUnicode, intNative, intRet6, int6);
Console.WriteLine("Method Ansi.Marshal_Int_InOut2: ExactSpelling = false");
int int7 = intManaged;
int intRet7 = Ansi.Marshal_Int_InOut2(int7);
- failures += Verify(intReturnAnsi, intManaged, intRet7, int7);
+ Verify(intReturnAnsi, intManaged, intRet7, int7);
Console.WriteLine("Method Ansi.MarshalPointer_Int_InOut2: ExactSpelling = false");
int int8 = intManaged;
int intRet8 = Ansi.MarshalPointer_Int_InOut2(ref int8);
- failures += Verify(intReturnAnsi, intNative, intRet8, int8);
+ Verify(intReturnAnsi, intNative, intRet8, int8);
Console.WriteLine("Method Auto.Marshal_Int_InOut: ExactSpelling = false. Verify CharSet.Auto behavior per-platform.");
int int9 = intManaged;
int intRet9 = Auto.Marshal_Int_InOut2(int9);
-#if TARGET_WINDOWS
- failures += Verify(intReturnUnicode, intManaged, intRet9, int9);
-#else
- failures += Verify(intReturnAnsi, intManaged, intRet9, int9);
-#endif
-
- return 100 + failures;
+ Verify(intReturnUnicode, intManaged, intRet9, int9);
+ }
+
+ private static void ExactSpellingFalse_NonWindows()
+ {
+ int intManaged = 1000;
+ int intNative = 2000;
+ Console.WriteLine("Method Unicode.Marshal_Int_InOut2: ExactSpelling = false");
+ int int5 = intManaged;
+ Assert.Throws<EntryPointNotFoundException>(() => Unicode.Marshal_Int_InOut2(int5));
+
+ Console.WriteLine("Method Unicode.MarshalPointer_Int_InOut2: ExactSpelling = false");
+ int int6 = intManaged;
+ Assert.Throws<EntryPointNotFoundException>(() => Unicode.MarshalPointer_Int_InOut2(ref int6));
+
+ Console.WriteLine("Method Ansi.Marshal_Int_InOut2: ExactSpelling = false");
+ int int7 = intManaged;
+ Assert.Throws<EntryPointNotFoundException>(() => Ansi.Marshal_Int_InOut2(int7));
+
+ Console.WriteLine("Method Ansi.MarshalPointer_Int_InOut2: ExactSpelling = false");
+ int int8 = intManaged;
+ Assert.Throws<EntryPointNotFoundException>(() => Ansi.MarshalPointer_Int_InOut2(ref int8));
}
- private static int Verify(int expectedReturnValue, int expectedParameterValue, int actualReturnValue, int actualParameterValue)
+ public static int Main(string[] args)
{
- int failures = 0;
- if (expectedReturnValue != actualReturnValue)
+ try
{
- failures++;
- Console.WriteLine($"The return value is wrong. Expected {expectedReturnValue}, got {actualReturnValue}");
+ ExactSpellingTrue();
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ ExactSpellingFalse_Windows();
+ }
+ else
+ {
+ ExactSpellingFalse_NonWindows();
+ }
}
- if (expectedParameterValue != actualParameterValue)
+ catch (System.Exception ex)
{
- failures++;
- Console.WriteLine($"The parameter value is changed. Expected {expectedParameterValue}, got {actualParameterValue}");
+ Console.WriteLine(ex.ToString());
+ return 101;
}
+ return 100;
+ }
- return failures;
+ private static void Verify(int expectedReturnValue, int expectedParameterValue, int actualReturnValue, int actualParameterValue)
+ {
+ Assert.AreEqual(expectedReturnValue, actualReturnValue);
+ Assert.AreEqual(expectedParameterValue, actualParameterValue);
}
}