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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:08:37+00:00 2026-05-12T06:08:37+00:00

The current product I work on is a Windows Service written in C++ and

  • 0

The current product I work on is a Windows Service written in C++ and going forward all new functionality will have unit tests written for it. But this creates an interesting problem (for me at least) we do a lot of Win32 calls for various things and behave accordingly, so for the unit tests to be complete it would be nice to test a variety of outputs, not just the current system state.

My question is what is the best way to mock the results of the Win32 calls? I have thought about two different methods:

1) Put all the Win32 calls used into function pointers and pass them into the functions or classes (depending on how many times they are hit) that use them and use this to get mock results.

2) Have lots of #ifdef UNITTEST everywhere and if it is calling my own special methods or have the normal ones called if not.

Am I completely off base here, or missing a fundamental piece of knowledge?

  • 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-12T06:08:37+00:00Added an answer on May 12, 2026 at 6:08 am

    With respect to (2), most Win32 functions which take string parameters already have their common form defined as a macro, e.g. from WinUser.h:

    WINUSERAPI
    int
    WINAPI
    MessageBoxA(
        __in_opt HWND hWnd,
        __in_opt LPCSTR lpText,
        __in_opt LPCSTR lpCaption,
        __in UINT uType);
    WINUSERAPI
    int
    WINAPI
    MessageBoxW(
        __in_opt HWND hWnd,
        __in_opt LPCWSTR lpText,
        __in_opt LPCWSTR lpCaption,
        __in UINT uType);
    #ifdef UNICODE
    #define MessageBox  MessageBoxW
    #else
    #define MessageBox  MessageBoxA
    #endif // !UNICODE
    

    You could certainly add a header to your project which redefines the API functions you want to simulate:

    #ifdef UNITTEST
    #undef MessageBox
    #define MessageBox UnitTestMessageBox
    #endif
    

    By redefining the name, you can avoid scattering lots of conditional compilation throughout your source code.

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

Sidebar

Related Questions

Our current product is based on Eclipse RCP. We are starting to have problems
If I have a query like this: String Category = HttpContext.Current.Request.QueryString[Product].ToString(); IQueryable<ItemFile> pressReleases =
This is what I Have in my WCF service public long Generic_Save(Product p, ObjectSet
I have to implement some scripting capabilities in our product. The scripting will typically
I have a model relationship with Product hasmany Page. When I add a new
Current Application Server Configuration: IIS 6.0 Windows 2003 Server Standard Edition SP2 .NET Framework
I have code code here: //Check current if (parseInt($(#Quantity).val()) < 25) { // If
I have a working Tycho build that produces a working p2 repository. My current
Our product is partially built using Delphi and partially .NET and in our current
I work for a software shop, which has an in house predictive dialer product,

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.