Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Passing on varargs

Passing on varargs

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearningworkspace
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve S
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • S Steve S

      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

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • C Chris Losinger

        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

        S Offline
        S Offline
        Steve S
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups