problem to create dll containing libmodbus function

28 views
Skip to first unread message

f mariani

unread,
Mar 25, 2015, 5:37:51 AM3/25/15
to libm...@googlegroups.com
Hi all,
I'm pretty a newbie in dll writing and I'm fining problem to pass modbus_t type form the program to dll.
My code is similar to that you can see below:
extern "C" //Functions List
{
__declspec
(dllimport) int    ModBus_init(modbus_t *ctx);
__declspec
(dllimport) int    ModBus_READ(modbus_t *ctx, int addr, int nb, uint16_t *dest);
}

int main (){

modbus_t
*ctx = NULL;

err_temp
= ModBus_init(ctx); printf("\n\n ModBus => %d", err_temp);
err_temp = ModBus_READ(ctx, addr, nb, dest);

}

I think that the problem is pass the struct pointer ctx of modbus_t type from dll to program and back again. This because all libmodbus functions in modbus_init work fine but when I try to run the same function in modbus_READ problem occur.
e.g. libmodbus function "modbus_read_registers" in Modbus_READ return "invalid argument".

Thank you in advance.
Best regards,
Federico.

Reply all
Reply to author
Forward
0 new messages