How to Build Windows Virtual Scanner and Feed Custom Images

Document Acquisition Process

Before getting started, let’s take a glimpse of the workflow of the document acquisition process.


  • Visual Studio 2017 or above
  • Qt 5.12.11 msvc2017
  • Test tools:

How to Build and Debug the TWAIN DS Sample


  1. Get the source code:
  1. Run twacker (32-bit/64-bit) application.
  2. In Visual Studio, set a breakpoint in DS_Entry() and then go to Debug > Attach to Process to find the twacker process.

Feeding Windows Virtual Scanner with Custom Images

I am tired of using the default TWAIN logo as the scanned image, so I am going to modify the source code of the TWAIN DS sample to load custom images.

"folder": "C:/Users/admin/Pictures/barcode"
"index": 0
#include "json.hpp"
using json = nlohmann::json;

#include <filesystem>
#include <fstream>
namespace fs = std::experimental::filesystem;


char sourceConfig[PATH_MAX];
SSNPRINTF(sourceConfig, sizeof(sourceConfig), PATH_MAX, "%s%csource.json", szTWAIN_DS_DIR, PATH_SEPERATOR);
vector<string> images;

if (FILE_EXISTS(sourceConfig))
// Read the image folder from source.json
ifstream stream(sourceConfig);
json source;
stream >> source;

string imageFolder = source["folder"];

if (FILE_EXISTS(imageFolder.c_str()))
// Get the image index
string infoPath = imageFolder + PATH_SEPERATOR + "info.json";
ifstream infoStream(infoPath);
json info;
infoStream >> info;

int index = info["index"];

for (const auto& entry : fs::directory_iterator(imageFolder))
std::string path{ entry.path().u8string() };
string suffix = path.substr(path.length() - 4, 4);
// Get JPEG or PNG files
if (!".jpg") || !".png"))

if (images.size() > 0)
if (index >= images.size()) index = 0;

// Set a custom image
SSNPRINTF(m_szSourceImagePath, sizeof(m_szSourceImagePath), PATH_MAX, images[index].c_str());

// Save image index to info.json
index += 1;
info["index"] = index;
std::ofstream stream(infoPath);
stream << info << std::endl;

// If there's no config file for custom image set, use the default image
if (images.size() == 0)
SSNPRINTF(m_szSourceImagePath, sizeof(m_szSourceImagePath), PATH_MAX, "%s%cTWAIN_logo.png", szTWAIN_DS_DIR, PATH_SEPERATOR);

Source Code



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xiao Ling

Xiao Ling

Manager of Dynamsoft Open Source Projects | Tech Lover