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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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#?
yamazedAuthor Commented:
Hi,

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

Thanks,

Yama
AlexFMCommented:
PInvoke starts with unmanaged function prototype, and here I only see structures and typedefs. What function exactly do you want to call?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

yamazedAuthor Commented:
I would like to know how I can translate and use the functions in C#
AlexFMCommented:
I don't see any function here. Can you give function definition which you want to call?
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#?
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.