Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4091344
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:21:16+00:00 2026-05-20T19:21:16+00:00

I’ll try to explain better what I want to do. I read a file

  • 0

I’ll try to explain better what I want to do.
I read a file with function signatures, and I want to create a pointer to each function.

For example, a file that looks like this:

something.dll;int  f(char* x, int y, SOMESTRUCT z)
something.dll;void g(void)
something.dll;SOMESTRUCT l(longlong w)

now, during runtime I want be able to create pointers to these functions (by loading something.dll and using GetProcAddress to these functions).

Now, GetProcAddress returns FARPROC which points to an arbitrary functions, but how can I use FARPROC to call these functions during runtime?
From what I know, I need to cast FARPROC to the correct signature, but I can’t do it during runtime (or at least I don’t know how).

Does anyone have any idea how to design do that?

Thanks! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:21:17+00:00Added an answer on May 20, 2026 at 7:21 pm
    1. Function types are compile-time in C++, so it won’t work, unless you can define all the types you’re going to use in advance.

    2. Its a matter of pushing the arguments to the stack (and local vars are like that) and calling the function as void (__cdecl *)(void).

    3. With some other kinds of functions (like fastcall, or thiscall) it can be more problematic.

    Update: I actually made an example, and it works on codepad:
    (Also works with stdcall functions, because of stack restore after aligned stack alloc)

    http://codepad.org/0cf0YFRH

    #include <stdio.h>
    
    #ifdef __GNUC__
     #define NOINLINE __attribute__((noinline))
     #define ALIGN(n) __attribute__((aligned(n)))
    #else
     #define NOINLINE __declspec(noinline)
     #define ALIGN(n) __declspec(align(n))
    #endif
    
    //#define __cdecl
    
    // Have to be declared __cdecl when its available, 
    // because some args may be passed in registers otherwise (optimization!)
    void __cdecl test( int a, void* b ) {
      printf( "a=%08X b=%08X\n", a, unsigned(b) );
    }
    
    // actual pointer type to use for function calls
    typedef int (__cdecl *pfunc)( void );
    
    // wrapper type to get around codepad's "ISO C++" ideas and gcc being too smart
    union funcwrap { 
      volatile void* y; 
      volatile pfunc f; 
      void (__cdecl *z)(int, void*);
    };
    
    // gcc optimization workaround - can't allow it to know the value at compile time
    volatile void* tmp = (void*)printf("\n");
    volatile funcwrap x; 
    int r;
    
    // noinline function to force the compiler to allocate stuff 
    // on stack just before the function call
    NOINLINE
    void call(void) {
      // force the runtime stack pointer calculation
      // (compiler can't align a function stack in compile time)
      // otherwise, again, it gets optimized too hard
    
      // the number of arguments; can be probably done with alloca()
      ALIGN(32) volatile int a[2]; 
      a[0] = 1; a[1] = 2; // set the argument values
      tmp = a; // tell compiler to not optimize away the array
      r = x.f(); // call the function; returned value is passed in a register
    
      // this function can't use any other local vars, because
      // compiler might mess up the order
    }
    
    int main( void ) {
      // again, weird stuff to confuse compiler, so that it won't discard stuff
      x.z = test; tmp=x.y; x.y=tmp;
      // call the function via "test" pointer
      call();
      // print the return value (although it didn't have one)
      printf( "r=%i\n", r );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.