CfExecute function usage
Diakov Dmytro
1
Reputation point
Hi!
I am using CfExecute function in my .Net Core application.
For this purpose I have marshalled it this way:
[DllImport(Lib.CldApi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfapi.h", MSDNShortId = "6AC8958D-B060-4468-9811-9BAB0E6A06D3")]
public static extern HRESULT CfExecute(in CF_OPERATION_INFO OpInfo, ref CF_OPERATION_PARAMETERS OpParams);
I have noticed that it does not working correctly with arrays. When I am trying to pass an array of placeholders to it I got memory corrupt error.
var transferPlaceholders = new CF_OPERATION_PARAMETERS.TRANSFERPLACEHOLDERS();
transferPlaceholders.CompletionStatus = completionStatus;
transferPlaceholders.PlaceholderArray = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CF_PLACEHOLDER_CREATE_INFO)) * aPlaceholders.Length);
transferPlaceholders.PlaceholderArray.Write<CF_PLACEHOLDER_CREATE_INFO>(aPlaceholders, 0, Marshal.SizeOf(typeof(CF_PLACEHOLDER_CREATE_INFO)) * aPlaceholders.Length);
transferPlaceholders.PlaceholderCount = (uint)aPlaceholders.Length;
transferPlaceholders.PlaceholderTotalCount = (uint)aPlaceholders.Length;
transferPlaceholders.Flags = flags;
var opParams = CF_OPERATION_PARAMETERS.Create<CF_OPERATION_PARAMETERS.TRANSFERPLACEHOLDERS>(transferPlaceholders);
var opInfo = new CF_OPERATION_INFO()
{
StructSize = (uint)Marshal.SizeOf<CF_OPERATION_INFO>(),
Type = operationType,
ConnectionKey = CallbackInfo.ConnectionKey,
TransferKey = CallbackInfo.TransferKey,
RequestKey = CallbackInfo.RequestKey,
CorrelationVector = CallbackInfo.CorrelationVector
//SyncStatus = IntPtr.Zero
};
ThrowIfError(CfExecute(opInfo, ref opParams));
Is there any advices how to fix it ?
Thanks
Sign in to answer