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

  • Home
  • SEARCH
  • 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 7901051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:07:20+00:00 2026-06-03T09:07:20+00:00

Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful

  • 0

Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
callback which one can use for that:

rsa=RSA_generate_key(bits,RSA_F4,progressCallback,NULL);

with

static void callback(int p, int n, void *arg) {
    .. stuff

However I want to call this from ObjectiveC without too much ado:

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeAnnularDeterminate;
    hud.labelText = @"Generating CSR";

    [self genReq:^(int p,int n,void *arg) {
            hud.progress = --heuristic to guess where we are --
    } completionCallback:^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];

With Genrec: as an objC method:

-(void)genReq:(void (^)(int,int,void *arg))progressCallback 
      completionCallback:(void (^)())completionCallback 
{
    .....
    rsa=RSA_generate_key(bits,RSA_F4,progressCallback,NULL);
    assert(EVP_PKEY_assign_RSA(pkey,rsa));
    rsa=NULL;
    ....

   completionCallback();
}

Now completionCallback(); works splendidly and as expected. But I get a compiler warning/error which I cannot quell for the progress callback:

 Passing 'void (^__strong)(int, int, void *)' to parameter of incompatible type 'void (*)(int, int, void *)'

So am curious — what is the appropriate way to do this ?

Thanks,

Dw.

  • 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-03T09:07:21+00:00Added an answer on June 3, 2026 at 9:07 am

    All code is just typed into this answer, test carefully before using!

    Function pointers and blocks are not the same thing; the former is just a reference to code, the latter is a closure containing both code and an environment; they are not trivially interchangeable.

    You can of course use function pointers in Objective-C, so that is your first option.

    If you wish to use blocks then you need to find a way to wrap a block and pass it as a function reference…

    The definition of RSA_generate_key is:

    RSA *RSA_generate_key(int num,
                          unsigned long e,
                          void (*callback)(int,int,void *),
                          void *cb_arg);
    

    The fourth argument can be anything and is passed as the third argument to the callback; this suggests we could pass the block along with a pointer to a C function which calls it:

    typedef void (^BlockCallback)(int,int);
    
    static void callback(int p, int n, void *anon)
    {
       BlockCallback theBlock = (BlockCallback)anon; // cast the void * back to a block
       theBlock(p, n);                               // and call the block
    }
    
    - (void) genReq:(BlockCallback)progressCallback 
             completionCallback:(void (^)())completionCallback 
    {
       .....
       // pass the C wrapper as the function pointer and the block as the callback argument
       rsa = RSA_generate_key(bits, RSA_F4, callback, (void *)progressCallback);
       assert(EVP_PKEY_assign_RSA(pkey,rsa));
       rsa = NULL;
       ....
    
       completionCallback();
    }
    

    And to invoke:

    [self genReq:^(int p, int n)
                 {
                    hud.progress = --heuristic to guess where we are --
                 }
          completionCallback:^{
                                [MBProgressHUD hideHUDForView:self.view animated:YES];
                              }
    ];
    

    Whether you need any bridge casts (for ARC) is left as an exercise!

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

Sidebar

Related Questions

The question is a very simple one, can you have more than one index
I have a simple one-to-many relationship. I would like to select rows from the
This is probably a basic html/css question... I have a simple one-button form that
I have one simple app that suppose to get information from user and send
I know zero javascript, and have one simple task: Find all text in the
I have an Asp .net page like this simple one http://issamsoft.com/app2/page1.aspx and I want
Im sure this will be a simple one but have a project that started
This might be a simple one, but since I don't have much knowledge about
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
My rails app has a simple model Links which tracks all the Urls associated

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.