I didn't look closely, but since you used the "long" type my guess is that's the problem. long in D is always 64 bit, but in C is sometimes 32 bit and sometimes 64 bit. On the D side, instead of writing "long", import core.stdc.config; and use c_long. Or just use int on both sides, that should work too.