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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:01:36+00:00 2026-05-31T13:01:36+00:00

I have a Visual Studio 2008 C++ project where I’m creating a DLL with

  • 0

I have a Visual Studio 2008 C++ project where I’m creating a DLL with a C interface. I defines two types of callback functions: a regular and an extended that provides additional data.

struct Foo {
    char a[ MAX_A ];
    char b[ MAX_B ];
    char c[ MAX_C ];
};
struct FooEx {
    char a[ MAX_A ];
    char b[ MAX_B ];
    char c[ MAX_C ];
    char d[ MAX_D ];
};
typedef void ( CALLBACK *USERCALLBACK )( const Foo&, DWORD );
typedef void ( CALLBACK *USERCALLBACK_EX )( const FooEx&, DWORD );

I maintain state with a UserData structure. Because I have two types of callbacks, I end up with two structures:

struct UserData {
    DWORD user;
    int zoo;
    std::string bar;
    USERCALLBACK callback;
};

struct UserDataEx {
    DWORD user;
    int zoo;
    std::string bar;
    USERCALLBACK_EX callback;
};

How do I reconcile my API with having two different UserData structures without creating separate EX versions of every function? Is there a way to templatize the callback? Or create a base-class of user data?

DECLARE_HANDLE( HMYAPI );

// this function is agnostic of the callback type
MY_API HMYAPI MyAPI_Create()
{
    return (HMYAPI)new UserData();
}

// This function does not directly use the callback type, but may need to know it to properly deallocate the UserData structure.
MY_API void MyAPI_Close( HMYAPI handle )
{
    delete reinterpret_cast< UserData* >( handle );
}

// this function needs to know about the different callback types
MY_API void MyAPI_Register( HMYAPI handle, USERCALLBACK cb, DWORD user )
{
    UserData* ud = reinterpret_cast< UserData* >( handle );
    ud->cb = cb;
    ud->user = user
}

// this function needs to know about the different callback types
MY_API void MyAPI_RegisterEX( HMYAPI handle, USERCALLBACK_EX cb, DWORD user )
{
    UserData* ud = reinterpret_cast< UserData* >( handle );
    ud->cb = cb;
    ud->user = user
}

// this function is agnostic of the callback type
MY_API void Foo( HMYAPI handle, int x )
{
    UserData* ud = reinterpret_cast< UserData* >( handle );
    ud->bar = "Foo";
    ud->zoo = x;
}
  • 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-31T13:01:39+00:00Added an answer on May 31, 2026 at 1:01 pm

    Not elegant, but it would work:

    • Your UserData and UserDataEx structures are identical other than the pointer types. Combine those two structures into one and replace the callback pointer type with FARPROC. You’d have to cast back and forth when setting and retrieving those function pointers.
    • You’d also need to add some kind of explicit type information to your structure to specify whether to cast the callback to the standard version or the “Ex” version. For example, you could add a flags field and set a USES_EXTENDED_CALLBACK flag.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .DLL that i include in my Visual Studio 2008 project. The
I have a Visual Studio 2008 solution with two projects (a Word-Template project and
I have a Visual Studio 2008 project with some legacy native C++ DLL projects,
I have a Visual Studio 2008 project that has a reference to a dll.
I have a Visual Studio 2008 C++ project for Windows Mobile 6 with two
I have a Visual Studio 2008 C++ project that has support for using multiple
I have a Visual Studio 2008 C++ project that outputs a static library and
I have a bunch of Velocity template files in a Visual Studio 2008 project,
I have a visual studio 2008 solution that includes an asp.net-hosted remoting project in
I have a custom build target in a visual studio 2008 c# project. Is

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.