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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:45:56+00:00 2026-06-10T02:45:56+00:00

I just ported all of my tests from Google Test to Visual Studio 2012’s

  • 0

I just ported all of my tests from Google Test to Visual Studio 2012’s unit test framework. (Long story; Google’s assertions are better but Microsoft’s works with the Dev11 Unit Test Explorer out of the box, which makes getting code coverage really easy …)

I got everything ported over fine, except for the following class, which reads a newline-delimited text file from a Win32 resource, and then allows for quick lookups against that resource:

#include "pch.hpp"
#include "resource.h"
#include <functional>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <windows.h>
#include "Win32Exception.hpp"
#include "Whitelist.hpp"

using Instalog::SystemFacades::Win32Exception;

namespace Instalog {

    Whitelist::Whitelist( __int32 whitelistId , std::vector<std::pair<std::wstring, std::wstring>> const& replacements )
    {
        using namespace std::placeholders;

        HRSRC resourceHandle = ::FindResource(0, MAKEINTRESOURCEW(whitelistId), L"WHITELIST");
        if (resourceHandle == 0)
        {
            Win32Exception::ThrowFromLastError();
        }
        HGLOBAL resourceGlobal = ::LoadResource(0, resourceHandle);
        if (resourceGlobal == 0)
        {
            Win32Exception::ThrowFromLastError();
        }
        void * resourceData = ::LockResource(resourceGlobal);
        if (resourceData == 0)
        {
            Win32Exception::ThrowFromLastError();
        }
        wchar_t const* resourceDataCasted = static_cast<wchar_t const*>(resourceData);
        DWORD resourceLen = ::SizeofResource(0, resourceHandle);
        auto sourceRange = boost::make_iterator_range(resourceDataCasted, resourceDataCasted + (resourceLen / sizeof(wchar_t)));
        boost::algorithm::split(innards, sourceRange, std::bind1st(std::equal_to<wchar_t>(), L'\n'));
        std::for_each(innards.begin(), innards.end(), std::bind(boost::algorithm::to_lower<std::wstring>, _1, std::locale()));
        std::for_each(innards.begin(), innards.end(), [&replacements] (std::wstring &a) {
            std::for_each(replacements.begin(), replacements.end(), [&a] (std::pair<std::wstring, std::wstring> const&b) {
                if (boost::algorithm::starts_with(a, b.first))
                {
                    a.replace(a.begin(), a.begin() + b.first.size(), b.second);
                }
            });
        });
        std::sort(innards.begin(), innards.end());
    }

    bool Whitelist::IsOnWhitelist( std::wstring checked ) const
    {
        boost::algorithm::to_lower(checked);
        return std::binary_search(innards.begin(), innards.end(), checked);
    }

    void Whitelist::PrintAll( std::wostream & str ) const
    {
        std::copy(innards.begin(), innards.end(), std::ostream_iterator<std::wstring, wchar_t>(str, L"\n"));
    }

}

Unfortunately, Dev11’s test projects generate DLLs, not EXEs, as under Google Test’s system. So, while before I was able to embed the resource into the EXE and pass NULL to FindResource‘s first parameter, now Visual Studio is loading the DLL into its process during testing. Visual Studio certainly doesn’t have my custom WHITELIST resource type inside, so this code blows up.

Is there some way I can either

  1. Tell this code somehow to look in the right binary, either the testing DLL or the EXE, depending on context? (Currently this code is in a static library which gets linked with both the real EXE and the testing DLL) or
  2. Embed relatively large (a few MB) text files into a C++ program cleanly without using the Win32 resource infrastructure at all?

It should be noted that putting the resource into a satellite DLL (which might have been a reasonable solution) is not an option; a requirement of this project is single EXE xcopy deployment.

  • 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-10T02:45:58+00:00Added an answer on June 10, 2026 at 2:45 am

    Figured it out. I used the GetCurrentModule hack here -> How do I get the HMODULE for the currently executing code? . This gave the the HMODULE I needed to pass into the XxxResource APIs.

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

Sidebar

Related Questions

I've just ported all my arrays to ArrayList (due to my great lack of
(I just posted this in the NUnit discussion group on groups.google.com) Under VS 2008,
I just want to add some extra text on top of input posted from
Is it common to write integration tests before writing unit tests? Is it conventional,
I just ported a .obj loader to objective-C and so far, it works, I
I've got a problem with my universal app that I just recently ported to
I'm having problems with a java.lang.NoClassDefFoundError when trying to run my JUnit tests from
I just posted this question jQuery - passing arrays in post request , where
I just posted a question about whether WPF is a good choice for a
I just posted this question and learned about <see cref=> , however when i

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.