I have a DLL with interface
struct modeegPackage
{
uint8_t version; // = 2
uint8_t count; // packet counter. Increases by 1 each pack
The answer marked as an "ANSWER" before mine is not really correct and it has been 1.5 years.
The reason the OP got that error is indeed just what the error description says, "Method's type signature is not PInvoke compatible"
When you have a C/C++ function such as the one declared below,
__declspec(dllexport) struct modeegPackage __cdecl getPackage();
Since the function returns a value of struct which is bigger than any register can hold, GCC compiler will try to optimize it(Return Value Optimize), so the actual implementation looks like the following,
__declspec(dllexport) void __cdecl getPackage(struct* modeegPackage);
So your P/Invoke declaration should be,
[DllImport(DLL, EntryPoint = "_Z10getPackagev", CallingConvention = CallingConvention.Cdecl)]
public static extern GetPackage(out modeegPackage);
I hope my answer help any other developers who may have similar issue in the future.