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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:15:45+00:00 2026-05-28T11:15:45+00:00

I use a 3rd party library, that does callback operations. It has a function

  • 0

I use a 3rd party library, that does callback operations.
It has a function which takes in function pointers.
The problem is that I are unable to pass in pointers to functions that are members of a class.

I am using Qt and C++. The 3rd party library function seems to be a C function.
The example code provided by the third party puts all code in main.
This is undesirable, I need to wrap code in classes.

How can I solve this callback issue?

A.h

#include "ThirdPartyLibrary.h"
class A
{
public:
    QFile* f;

    A(QString filename);
    ~A();

    bool mount();

    BOOL _stdcall OnWriteCallback
    (
        DRIVE_HANDLE h, 
        ULONGLONG WriteOffset, 
        ULONG WriteSize, 
        const void* WriteBuffer, 
        ULONG *BytesWritten
    );

    BOOL _stdcall OnReadCallback
    (
        DRIVE_HANDLE h, 
        ULONGLONG ReadOffset, 
        ULONG ReadSize, 
        void* ReadBuffer, 
        ULONG *BytesRead
    );
};

A.cpp

A::A(QString filename)
{
    f = new QFile(filename);
    f.open(QFile::ReadWrite);
}

~A::A(){
    f.close();
    delete f;
}

bool A::mount()
{
    //THIS IS THE PROBLEM, CreateVirtualDrive does not take MEMBER FUNCTION POINTERS 
    //properly, instead it wants normal function pointers.
    //CreateVirtualDrive is from an external 3rd-party 
    //library, and seems to be a C function.
    g_hDrive = CreateVirtualDrive(driveLetter,DISK_SIZE,
                                  &A::OnReadCallback,
                                  &A::OnWriteCallback);
}

BOOL _stdcall A::OnWriteCallback
(
    DRIVE_HANDLE h, 
    ULONGLONG WriteOffset, 
    ULONG WriteSize, 
    const void* WriteBuffer, 
    ULONG *BytesWritten
){
    //do some work with QFile f !!
    return true;
}

BOOL _stdcall A::OnReadCallback
(
    DRIVE_HANDLE h, 
    ULONGLONG ReadOffset, 
    ULONG ReadSize, 
    void* ReadBuffer, 
    ULONG *BytesRead
){
    //do some work with QFile f !!
    return true;
}

main.cpp

#include "A.h"
int main ()
{
    A a;
    a.mount();

}
  • 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-28T11:15:46+00:00Added an answer on May 28, 2026 at 11:15 am

    There’s a workaround for this described in the C++ FAQ:

     class Fred {
     public:
       void memberFn();
       static void staticMemberFn();  // A static member function can usually handle it
       ...
     };
    
     // Wrapper function uses a global to remember the object:
     Fred* object_which_will_handle_signal;
    
     void Fred_memberFn_wrapper()
     {
       object_which_will_handle_signal->memberFn();
     }
    
     int main()
     {
       /* signal(SIGINT, Fred::memberFn); */   // Can NOT do this
       signal(SIGINT, Fred_memberFn_wrapper);  // OK
       signal(SIGINT, Fred::staticMemberFn);   // OK usually; see below
       ...
     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I was to use a 3rd party library that was not in the
Do we have any free 3rd party library that we can use in asp.net
I have a 3rd party library that I use in my webapp. I need
For my project I have to use a 3rd party Java library which makes
In my project I use a 3rd party library which is constantly changing. I
I want to use an 3rd party library without using its header file. My
I use a 3rd party tool that outputs a file in Unicode format. However,
I am working on a web app which makes use of a 3rd party
I use 3rd party library in my asp.net application. Then application will be deployed
I want to create a shared library that uses functions from a 3rd-party static

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.