In VC++ I'm struggling with calls to decorated functions in an external DLL which I did not create. The undecorated functions I'm trying to use are:
bool Orc::cCodecHuffman::fixedTable_decode_decompress(void *,unsigned int,void const *,unsigned int)
unsigned int Orc::cCodecHuffman::fixedTable_decode_getuncompressedlength(void const *,unsigned int)
void Orc::cCodecHuffman::fixedTable_decode_init(void const *,unsigned int)
An example of my function prototypes is:
int (__stdcall *_GetUncompressedLength) (int, int);
HMODULE hMyDLL = LoadLibrary("my.dll");
*(void**)&_GetUncompressedLength = GetProcAddress(hMyDLL, " -- decorated name -- ");
FUNC(unsigned int, GetUncompressedLength, (void* source, unsigned int sourceSz));
.. where the macro 'FUNC' is defined as:
#define FUNC(ret, name, args) \
extern "C" typedef ret (__stdcall *raw_##name) args; \
raw_##name* name = (raw_##name*)&_##name;
An example of calling these functions:
unsigned int NUMuBytes = (*GetUncompressedLength)( (void*)sourceBytes, csize );
With this, I'm happy that I'm no longer getting
(a) access violations, and
(b) the debug error "The value of ESP was not properly saved across a function call".
But in fact the code above is way over my head.
1.) Should I create class prototypes for 'Orc' and 'cCodecHuffman' ?
2.) If I use a template to 'force_cast' the function pointers (according to the example http://www.codeguru.com/cpp/w-p/dll/importexportissues/article.php/c123), I seem to lose the '__stdcall' convention, because I get a Debug error "The value of ESP was not properly saved across a function call". How can I avoid this?
3.) I'm not sure whether I'm interpreting the output of 'GetUncompressedLength' correctly, because the number is much too high.
Am I receiving a pointer?
Please note that I'm trying to call C++ member functions:
(".. There are two problems. The first problem is that C++ member function names are decorated names (Specifying extern "C" does not help). The second problem is that C++ language specifications do not allow pointer to member functions to be converted into other types..")