Passing on varargs
-
I feel that I really should know this, but I'm having an off-day, and I've just been told my car needs new wheel-bearings, a brake caliper and disc on one of the wheels, which would at least explain why I keep having to turn the radio up :) I have a function int __cdecl xxx(const char* value, ...) which is in a C DLL. I'm writing a wrapper class which loads the DLL and and does a GetProcAddress to retrieve the function address. So far so good. Except that for my wrapper class, I'm providing a wrapper::xxx member which (having checked the DLL is loaded and the proc address isn't null) will call down through the pointer. So I have int xxx(const char*value,...) as a member function, and int (__cdecl *m_pf_xxx)(const char*,...) as a member too. What incantation do I need to get my class function to call via the pointer? If it wasn't for the variable args, it would be (*m_pf_xxx)(format); but of course, I need to pass the other args if there are any... The reason for doing it this way is that the DLL is a 3rd party one (one of a set, in fact), which is loaded at runtime. I can't simply delayload, since the DLL is specified by configuration at runtime, and the wrapper class handles multiple similar ones (think of a codec, for instance). Like I say, I ought to know this; and before anyone suggests it, I can't change the DLLs, since they are 3rd party, and the developers are not interested in changing them (of course). Trouble is, I'm tied to using them in this instance. Steve S Developer for hire
-
I feel that I really should know this, but I'm having an off-day, and I've just been told my car needs new wheel-bearings, a brake caliper and disc on one of the wheels, which would at least explain why I keep having to turn the radio up :) I have a function int __cdecl xxx(const char* value, ...) which is in a C DLL. I'm writing a wrapper class which loads the DLL and and does a GetProcAddress to retrieve the function address. So far so good. Except that for my wrapper class, I'm providing a wrapper::xxx member which (having checked the DLL is loaded and the proc address isn't null) will call down through the pointer. So I have int xxx(const char*value,...) as a member function, and int (__cdecl *m_pf_xxx)(const char*,...) as a member too. What incantation do I need to get my class function to call via the pointer? If it wasn't for the variable args, it would be (*m_pf_xxx)(format); but of course, I need to pass the other args if there are any... The reason for doing it this way is that the DLL is a 3rd party one (one of a set, in fact), which is loaded at runtime. I can't simply delayload, since the DLL is specified by configuration at runtime, and the wrapper class handles multiple similar ones (think of a codec, for instance). Like I say, I ought to know this; and before anyone suggests it, I can't change the DLLs, since they are 3rd party, and the developers are not interested in changing them (of course). Trouble is, I'm tied to using them in this instance. Steve S Developer for hire
you can't pass ... to ... what you need is for the DLL to expose a va_list form of the function: int (__cdecl *m_pf_xxx)(const char*, va_list) then, in your wrapper, you can unpack the ... to a va_list and pass it to the DLL. Cleek | Image Toolkits | Thumbnail maker
-
you can't pass ... to ... what you need is for the DLL to expose a va_list form of the function: int (__cdecl *m_pf_xxx)(const char*, va_list) then, in your wrapper, you can unpack the ... to a va_list and pass it to the DLL. Cleek | Image Toolkits | Thumbnail maker
Thanks Chris, that's exactly what I was afraid of. :( The 3rd party are adamant that they won't change their code, but since the function in question is a 'convenience' one, I think I can emulate what it's doing, making calls to other functions within the DLL anyway. Having looked at stack frames, I can see why it wouldn't be possible. I don't even want to think about playing with the stack frame to try and jump to the code, writing the emulation code in the wrapper would be much easier & faster... Steve S Developer for hire