• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 782
  • Last Modified:

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
0
yamazed
Asked:
yamazed
  • 4
  • 3
1 Solution
 
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
 
AlexFMCommented:
PInvoke starts with unmanaged function prototype, and here I only see structures and typedefs. What function exactly do you want to call?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now