Hello,
I am having a complex problem to solve. Currently stuck and found no way around.
I need to call every exported function of some WIN32 DLL or exposed function of a COM EXE/DLL under some interface at run time(No code generation).
I have extracted function signatures with complete details (i.e return type, all arguments in/out).Now all these types and exposed methods of those types, Interfaces and their exposed methods have been listed in some XML or any text file.
Now for every function i also listed its index or its address in XML or text file, so that When I need to call function i can make assembly call to that function with _asm { call address}.
Its very easy to call function which is taking pointer of some user defined Type e.g say ------------>void CallMethod(int x,int y, SomeUDT *pSomeUDT). Here "SomeUDT" is some user defined type say class or struct of which pointer as incoming parameter. I will scan its details from XML file(i.e what are data members against this type) and will declare a heap block of size (which I will calculate from summing its data types of data members). Next I will fill data on those blocks and will call function . Here void* only be needed to traverse the whole block and on need i will type cast it with some primitive types say with float or int (depends what kind of data i am filling in the block). and finally will call the function accordingly.
HERE THE PROBLEM IS WITH VOID*. It cannot be de-referenced. What if I am having object on recieving side SAy above method would be as
void CallMethod(int x,int y, SomeUDT objSomeUDT) Now I cant call this function as I statted above.
The whole story i am listing here.
<Types>
<MyType>
<Methods name="CallMethod" Address="102">
<params>
<param type="int" name="x"/>
<param type="int" name="y"/>
<param type="SomeUDT" name="a_objSomeUDT"/>
</params>
</Methods>
</MyType>
</Types>
<TypeDictionary>
<Type name="SomeUDT">
<dataMember name = "Data_1" type = "unsigned long*"/>
<dataMember name = "Data_2" type = "unsigned short*"/>
<dataMember name = "Data_3" type="SomeOtherUDT">
<dataMember name="" type = "SomeOtherUDT">
<!--So on so forth--->
</Type>
</TypeDictionary>
Now what I will do I will scan SomeUDT from type dictionary and calculate total size of data mamabers types and allocate a heap block with sum of its member's types. and finally fill the data accordingly. then will do
void *pBlockOfMem = malloc(sizeof(unsigned long+unsigned short+SomeOtherUDT));
unsigned long* pData_1 = (unsigned long*)pBooclOfMem;
*pData_1 = 20;
pData_1++;
unsigned short* pData_2 = (unsigned short*)pData_1;
*pData_2 = 150;
pData_2++;
so on for SomeOtherUDT as well. and fainally whole block will be filled.
_asm
{
push pBooclOfMem
call addressOfFunction ; it will call function whose signature is "void CallMethod(int,int,SomeUDT* pSomeUDT)
}
But here if i have signature "void CallMethod(int,int,SomeUDT oSomeUDT)" .....obj as argument not pointer. Here Void* approach fails.
What's the exact and perfect solution to the above problem . I am stuck here. Need to solve with 100% accurate solution.
Regards
Usman






