简体   繁体   English

P从用C编译的DLL调用函数

[英]PInvoke a function from a DLL compiled in C

I have the following C function 我有以下C函数

typedef struct ekeycore_ctx_ ekeycore_ctx;

typedef struct ekeycore_enum_ ekeycore_enum;

typedef struct ekeycore_device_ {
    char *serial;
    char *portname;
    char *node;
    BOOL present;
    BOOL used;
} ekeycore_device;

typedef struct ekeycore_simple_ ekeycore_simple;

typedef enum {
    EKEYCORE_OK = 0,              /* everything was fine */
    EKEYCORE_NOMEM = 1,           /* out of memory */
    EKEYCORE_NODEVICE = 2,        /* no devices are available */
    EKEYCORE_TIMEOUT = 3,         /* key did not respond to request */
    EKEYCORE_FAULTY = 4,          /* device has reported faulty/attacked */
    EKEYCORE_UNKNOWN = 5          /* unknown error */
} ekeycore_result;

EKEYCORE_API ekeycore_result ekeycore_simple_get(ekeycore_simple *ctx, unsigned char *buff, size_t buffz)

I need to call this function (ekeycore_simple_get) from C#, how would I go about it? 我需要从C#调用此函数(ekeycore_simple_get),我将如何处理? How would the variable types above convert? 上面的变量类型将如何转换?

You're probably asking a bit much of StackOverflow for someone to work all that out for you, but there is good information about marshalling structs on MSDN (see link below) 您可能会问很多StackOverflow来让某人为您解决所有问题,但是有关在MSDN上编组结构的很好信息(请参阅下面的链接)

These are the places I use for reference to P/invoke techniques: 这些是我用来引用P /调用技术的地方:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM