Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mono/mono/metadata/marshal-lightweight.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,7 @@ emit_managed_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_s
case MONO_TYPE_SZARRAY:
case MONO_TYPE_CLASS:
case MONO_TYPE_VALUETYPE:
case MONO_TYPE_PTR:
mono_emit_marshal (m, i, invoke_sig->params [i], mspecs [i + 1], tmp_locals [i], NULL, MARSHAL_ACTION_MANAGED_CONV_OUT);
break;
default:
Expand Down
25 changes: 25 additions & 0 deletions src/tests/Interop/MarshalAPI/FunctionPointer/FunctionPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ static class FunctionPointerNative

[DllImport(nameof(FunctionPointerNative))]
public static extern bool CheckFcnPtr(IntPtr fcnptr);

[DllImport(nameof(FunctionPointerNative))]
static unsafe extern void FillOutPtr(IntPtr* p);
}

delegate void VoidDelegate();
Expand Down Expand Up @@ -56,12 +59,34 @@ void VoidVoidMethod()
}
}


[DllImport(nameof(FunctionPointerNative))]
static unsafe extern void FillOutPtr(IntPtr* p);

private unsafe delegate void DelegateToFillOutPtr([Out] IntPtr* p);

public static void RunGetDelForOutPtrTest()
{
Console.WriteLine($"Running {nameof(RunGetDelForOutPtrTest)}...");
IntPtr outVar = 0;
int expectedValue = 60;
unsafe
{
DelegateToFillOutPtr d = new DelegateToFillOutPtr(FillOutPtr);
IntPtr ptr = Marshal.GetFunctionPointerForDelegate(d);
DelegateToFillOutPtr OutPtrDelegate = Marshal.GetDelegateForFunctionPointer<DelegateToFillOutPtr>(ptr);
OutPtrDelegate(&outVar);
}
Assert.Equal(expectedValue, outVar);
}

public static int Main()
{
try
{
RunGetDelForFcnPtrTest();
RunGetFcnPtrSingleMulticastTest();
RunGetDelForOutPtrTest();
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdio.h>
#include <xplatform.h>
#include <platformdefines.h>
#include <stdint.h>

namespace
{
Expand All @@ -29,3 +30,8 @@ extern "C" DLL_EXPORT bool CheckFcnPtr(bool(STDMETHODCALLTYPE *fcnptr)(long long
return fcnptr(999999999999);
}
}

extern "C" DLL_EXPORT void FillOutPtr(intptr_t *p)
{
*p = 60;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="*.cs" />
Expand Down