I have a C dll which interfaces to a voice card. The function call requires a special structure to be passed. I am attempting to wrap the C dll in a C# class so I can use C# instead of C.
The C structure is as follows:
typedef struct
{
TCASGroupIndex firstGroupIndex; /* Index of first CAS channel group. */
PK_U32 numberOfGroups; /* Number of CAS channel group. */
PK_U32 isDigitalLogging;
} TCASGroupInfo;
The C function call is as follows:
PK_STATUS WINAPI PK_CAS_GetCASGroupInfo ( IN TBoardIndex boardID, OUT TCASGroupInfo* info);
The data types are defined as follows:
typedef unsigned PK_BOOL; Unsigned boolean type.
typedef char PK_CHAR,*PK_PCHAR; Standard char type.
typedef unsigned char PK_U8,*PK_PU8; 8-bit unsigned char type.
typedef signed char PK_I8,*PK_PI8; 8-bit signed char type.
typedef unsigned short PK_U16,*PK_PU16; Unsigned short 16-bit type.
typedef signed short PK_I16,*PK_PI16; Signed short 16-bit type.
typedef unsigned long PK_U32,*PK_PU32; Unsigned long 32-bit long type.
typedef signed long PK_I32,*PK_PI32; Signed long 32-bit long type.
typedef double PK_REAL,*PK_PREAL; 64-bit long real type.
typedef unsigned PK_WORD,*PK_PWORD; Unsigned type.
typedef unsigned PK_UINT,*PK_PUINT; Unsigned type.
typedef signed PK_INT,*PK_PINT; Signed type.
typedef void PK_VOID,*PK_PVOID; Void type.
typedef int PK_STATUS; Common status return code.
typedef unsigned long TDeviceHandle,*PDeviceHandle; DSP device handle type.
typedef unsigned long TResourceHandle,*PResourceHandle; Analog trunk, phone and DSP port resource handle type.
typedef PK_U32 TEventId,*PEventId; Event ID type in event handler function.
typedef PK_WORD TBoardIndex; Board index type.
typedef PK_WORD TSwitchIndex; Switch index type.
typedef PK_U16 TDSPIndex; DSP index type.
typedef PK_U16 TSpanIndex; Span index type.
typedef PK_WORD TSwitchStream, *PSwitchStream; Switch stream type.
typedef PK_WORD TSwitchTimeslot, *PSwitchTimeslot; Switch timeslot type.
typedef PK_U32 TResourceMask, *PResourceMask; Resource mask type.
typedef PK_WORD TSwitchPattern, *PSwitchPattern; Switch pattern type.
typedef PK_INT TGainLevel,*PGainLevel; Gain level type.
typedef PK_U32 TTimeDuration,*PTimeDuration; Time duration type.
My Interop function is as follows:
[DllImport("H:\\PIKA\\Debug\\PikaAPI.dll", EntryPoint="PK_CAS_GetCASGroupInfo", CallingConvention=CallingConvention.StdCall)]
public static extern int CASGroupInfo(int nBoard, ref TCASGroupInfo groupInfo);
public int GetCASGroupInfo(int nBoard, ref TCASGroupInfo groupInfo)
{
return CASGroupInfo( nBoard, ref groupInfo );
}
I get the following error:
Cannot marshal parameter #2: The type definition of this type has no layout information.
What's the proper syntax to make my function call work properly?
Thanks.
Tim Gaither
MSDN Subscriber
Little Gazer - 16 Jul 2004 06:05 GMT
I found the answer to my problem in the latest MSDN. I have posted the online url for anyone who has the same problem.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
constructssample.asp
Tim
> I have a C dll which interfaces to a voice card. The function call requires a special structure to be passed. I am attempting to wrap the C dll in a C# class so I can use C# instead of C.
>
[quoted text clipped - 59 lines]
> Tim Gaither
> MSDN Subscriber