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 8906787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:44:36+00:00 2026-06-15T02:44:36+00:00

I am trying to return a function instance from a FARPROC address given by

  • 0

I am trying to return a function instance from a FARPROC address given by another function that calls GetProcAddress. Came up with an interesting issue. Here’s the function:

template<class FT>
std::function<FT> to_function(FARPROC address) {
    return address;
}

Later on I would create a no input function without any issues:

auto try1 = to_function<int()>(addr1);

However when the function takes an input, the visual c++ 11 compiler explodes:

auto try2 = to_function<int(int)>(addr2);

It rightfully returns:

Error C2197: ‘int (__stdcall *)(void)’ : too many arguments for call

The type in question is equivalent to FARPROC which is what is returned by GetProcAddress regardless of the argument list of the function.

My question, to get to the point, is how would I get around this issue by casting FARPROC to an appropriate type for std::function given the simple function prototype of to_function? Cheers in advance.

  • 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-06-15T02:44:37+00:00Added an answer on June 15, 2026 at 2:44 am

    I would suggest you first cast your pointer, and then wrap it into a std::function:

    template<Signature>
    std::function<Signature> to_function(FARPROC f)
    {
        return std::function<Signature>(reinterpret_cast<Signature*>(f));
    }
    

    IMHO it would be a good idea to name such a function cast_to_function. Its name should sound dangerous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to return the ajax success array from one function to another. For
Im trying to return the value that a $ajax call returns, from a function
I'm trying to return a string from a function. Which basically adds some chars
I'm trying to return a value from (transport) to the calling function, but can't
I'm trying to get my function to return the data it got into another
I'm trying to make a notification area that will show alerts. return this.each(function() {
I'm trying to write a function that will remove a query argument from a
I'm trying to return an instance of a class in a function, but I'm
I'm trying to return a json result from a jQuery Form instance - but
I am trying to create a static method that would return an instance of

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.