Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2004

Tip: Looking for answers? Try searching our database.

C# Interop of C dll passing a struct

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Little Gazer - 16 Jul 2004 00:38 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.