08-09-2011 04:14 PM
I keep geeting the error "Type error in argument 1 to `DLLStruct'; found 'pointer to struct parameters' expected 'pointer to incomplete struct parameters "
I'm trying to pass a pointer to a struct as an argument to a function in a DLL. This is just some test code to see if it works but all it does is pass the struct pointer to DLLStruct() and it is supposed to update a,b,c to the values of 1,2,3). Here is my code:
void __stdcall DLLStruct (struct parameters *tester_params);
struct parameters
{
int a;
int b;
int c;
}tester_params;
int main (int argc, char *argv[])
{
char resultstr[256];
struct parameters *structPtr;
structPtr = &tester_params;
structPtr->a = 0;
structPtr->b = 0;
structPtr->c = 0;
DLLStruct(structPtr);
sprintf(resultstr,"a = %i",structPtr->a);
MessagePopup ("Test...", resultstr);
sprintf(resultstr,"b = %i",structPtr->b);
MessagePopup ("Test...", resultstr);
sprintf(resultstr,"c = %i",structPtr->c);
MessagePopup ("Test...", resultstr);
return 0;
}
Here is the DLL function:
void __stdcall DLLStruct (struct parameters *tester_params)
{
tester_params->a = 1;
tester_params->b = 2;
tester_params->c = 3;
}
Solved! Go to Solution.
08-09-2011 05:52 PM
If the code is written as it is reported in your post, this error depends on the fact that when defining your DLLStruct function the structure is not yet defined. After function declaration, you define the struct and use it when calling DLLStruct: in that moment you are passing a completely defined structure to a function that was expecting an incomplete struct (i.e. the structure not yet defined).
Moving structure definition before function definition should eliminate the error.