Hello, I have a complex problem to be solve, as I am stuck and found no way at all to solve this. Here's a code
struct MyStruct
{
int x;
float y;
char c;
};
void foo(MyStruct a_myStruct);
int _tmain(int argc, _TCHAR* argv[])
{
void *pMyStruct = malloc(sizeof(MyStruct));
int* pInt = (int*)pMyStruct;
*pInt = 10;
pInt++;
float *pFloat = (float*)pInt;
*pFloat = 2.545;
pFloat++;
char *pChar = (char*)pFloat;
*pChar = 'c';
_asm
{
pMyStruct
call foo
}
return 0;
}
void foo(MyStruct a_myStruct)
{
}
Here you can see that foo is operating object on stack which is expecting stack object to be mapped when foo gets called. But unfortunately above MyStruct type not known at compile time so I have to create block of memory and then at runtime data is filled with in that block which is then passed when foo get's called with asm as show above.
Now how can i convert heap void pointer to stack type object. Somehow if i get the address location of a_myStruct argument of foo, I can point with void* to that location but again i cant dereference void* so that it get converted into object of MyStruct type.
Any other way around to solve the problem..? As in C++ we can determine type at runtime as well
Regards Hassan