COM Interop Win32 API to C#

Hi,

I have a few questions on COM Interop:

1. How do I translate something like this in C#:
// opaque representation connection statistics
/*
*   This datastructure is accessed by the functions whose
*   names begin with "_stats"  
*/
typedef void *_stats_t;

2. How about this:
typedef union
{
    struct
    {
        uint32_t pad[3];

        // IP address in network order
        struct in_addr addr;
    } ip4;

#ifdef NOT_IMPLEMENTED
    struct
    {
        struct in6_addr addr;
    } ip6;

#endif
} _ip_addr_t;
3. Finally this:
struct _connect_error
{
    _error_t error;
    uint32_t is_remote;
    char * delete_reason;

    uint32_t reserved[2];
};
// State transition callback
typedef void (*_state_change_cb) (_state_t state,
                                     const           _ip_addr_t * peer,
                                     const struct  _connect_error*);

I'd truly appreciate input on this.


Many thanks,

~yamazed
yamazedAsked:
Who is Participating?
 
AlexFMCommented:
There are three types of objects here: union, structure and function pointer. None of them cannot be called from C#. I will not return to this question because this looks useless. If you want to get answer from somebody else, try to provide enough information.
For example, if you want to call Win32 function GetWindowText, you give it's prototype:

int GetWindowText(HWND hWnd, LPTSTR lpString, int nMaxCount);

and get PInvoke declaration for his. Code thst you post DOESN'T CONTAIN ANY FUNCTION PROTOTYPE, try to understand this.
0
 
AlexFMCommented:
Please describe what do you need to do. Do you want to call some unmanaged code from C# client? Or rewrite existing C++ application in C#?
0
 
yamazedAuthor Commented:
Hi,

I would like to interop/marshall/P-Invoke in C#.

Thanks,

Yama
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
AlexFMCommented:
PInvoke starts with unmanaged function prototype, and here I only see structures and typedefs. What function exactly do you want to call?
0
 
yamazedAuthor Commented:
I would like to know how I can translate and use the functions in C#
0
 
AlexFMCommented:
I don't see any function here. Can you give function definition which you want to call?
0
 
yamazedAuthor Commented:
typedef union
{
    struct
    {
        uint32_t pad[3];

        // IP address in network order
        struct in_addr addr;
    } ip4;


    struct
    {
        struct in6_addr addr;
    } ip6;
} _ip_addr_t;



struct _connect_error
{
    _error_t error;
    uint32_t is_remote;
    char * delete_reason;

    uint32_t reserved[2];
};
// State transition callback
typedef void (*_state_change_cb) (_state_t state,
                                     const           _ip_addr_t * peer,
                                     const struct  _connect_error*);

How would you translate this to C#?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.