I am having problems to use pointers from a NI LabWindows Application in functions from a dynamically linked DLL.
- DLL was build using MinGW 4.7
- NI LabWindows uses a really old LLVM CLang ANSI C Compiler with C89 standards and C90 extensions as far as i can tell
When calling specific DLL functions i use pointers to structs. The problem is, that the pointers given by the LabWindows application are pointing to a memory location 1 byte AHEAD of what the DLL expects them to point to.
So my nasty solution up to now is the following:
int MyFunction(MyStruct* struct) {
char *ptr = (char*) struct;
ptr--;
struct = (MyStruct*) ptr;
// do stuff
ptr = (char*) struct;
ptr++;
struct = (MyStruct*) ptr;
return 0;
}
My questions are: Why ??? And is there a more sophisticated solution to that?
I would expect that a as basic concept as a pointer would not differ from compiler to compiler, but maybe the one LabWindows uses is just too old.
Edit: The solution was to declare the struct the correct way for both compilers and specifiy the padding and alignment. So the correct structure definition to work with both compilers is:
#pragma pack(2)
typedef struct MyStruct{...};