Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How to marshal two parameters from a C function in a C# delegate method?

$
0
0

Hello all,

The following work on a 32-bit machine:

The signature of a C call back function is

      foreign_t (f)(term_t t0, int a))  // with foreign_t, term_t is int on 32-bit

in C# I have:

public delegate bool DelegateParameterVarArgs(PlTermV termVector);

public struct PlTermV
{
    private readonly uintptr_t _a0; // term_t
    private readonly int _size;
    ....
}

public void t_callback()
{
    Delegate d = new DelegateParameterVarArgs(my_callback);
    // ...
}

public static bool my_callback(PlTermV tv)
{ ... }
As said this work perfect on a 32-Bit environment.

Anyway if I move to 64-bit I'll got a NullReferenceException. The reason seems to be uintptr_t which is Int64 on 64-bit environment.

It also work on 64-Bit if I use something like:

      delegate bool DelegateParameterVarArgs(uintptr_t term, int size);

My question is How can I access the two C parameters in the C# delegate method by the struct in the 64-bit environment as it works on 32-bit?

Thank you in advance

Uwe Lesta


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>