Help converting struct w/function pointers to .NET

T

Thomas Connolly

Hello list,
No one seems to be replying to my request on the interop group so I thought I would try here.
Can someone please help me with this? I have a C struct containing function pointers like so:

typedef struct _tagLiffeResponseHandlerList
{

void (*OnAccessTransfer) (LiffeStatus eStatus, const char* pszTrader, LiffeBoolean bContinuationFlag,

int nNumOrders, const LiffeOrderEntryList* pcLiffeOrderEntryList, time_t nTimeStamp);

****** other function pointers omitted for brevity *******

} LiffeResponseHandlerList;

Would the following be correct?

public delegate void OnAccessTransfer(LiffeStatus eStatus, [MarshalAs(UnmanagedType.LPStr)] string pszTrader, LiffeBoolean bContinuationFlag, int nNumOrders, ref LiffeOrderEntryList pcLiffeOrderEntryList, uint nTimeStamp);

[StructLayout(LayoutKind.Sequential)]
public class LiffeResponseHandlerList
{
public OnAccessTransfer OnAccessTransfer;
}

Thanks for the help
 
R

Richard Grimes [MVP]

Thomas Connolly wrote:

You don't define LiffeStatus, LiffeBoolean or LiffeOrderEntryList. I am
guessing that LiffeStatus and LiffeBoolean are 32-bit integers and
LiffeOrderEntryList is a structure, but without more information its
difficult to know. What do you use LiffeResponseHandlerList for, do you pass
it to another C function through interop?
Would the following be correct?

public delegate void OnAccessTransfer(LiffeStatus eStatus,
[MarshalAs(UnmanagedType.LPStr)] string pszTrader, LiffeBoolean
bContinuationFlag, int nNumOrders, ref LiffeOrderEntryList
pcLiffeOrderEntryList, uint nTimeStamp);
[StructLayout(LayoutKind.Sequential)]
public class LiffeResponseHandlerList
{
public OnAccessTransfer OnAccessTransfer;
}

use struct, not class.

Define your managed LiffeOrderEntryList as a struct with
LayoutKind.Sequential too. If LiffeStatus and LiffeBoolean are 32-bit
integers then you can use integers in the delegate instead of them.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top