How to call dism /apply-image using the dism api?

Masa Yuilki 40 Reputation points
2024-12-15T21:36:21.7633333+00:00

I have installed the Windows ADK and i'm trying to programmatically reproduce the same call from this command:

dism /apply-image /imagefile:E:\sources\install.esd /index:6 /applydir:F:\

Looking at the DISM API Functions and also directly on the dismapi.h i'm not finding the right function to use, theres no "DismApplyImage".

The closest is DismMountImage but theres no compact on the flags.

#include <Windows.h>
#include <dismapi.h>
#pragma comment(lib, "dismapi.lib")


int main(int argc, char *argv[])
{
    DismLogLevel dwLogLevel = DismLogLevel::DismLogErrors;
    HRESULT hr = DismInitialize(dwLogLevel, NULL, NULL);

    DismSession session = NULL;
    // dism /apply-image /imagefile:E:\sources\install.esd /index:6 /applydir:F:\ /compact"
    hr = DismMountDismApplyImageImage(L"E:\sources\install.esd",  L"F:\\", 6, L"", DismImageIndex, ?

    /*
    DismMountImage(
    _In_     PCWSTR                 ImageFilePath,
    _In_     PCWSTR                 MountPath,
    _In_     UINT                   ImageIndex,
    _In_opt_ PCWSTR                 ImageName,
    _In_     DismImageIdentifier    ImageIdentifier,
    _In_     DWORD                  Flags,
    _In_opt_ HANDLE                 CancelEvent,
    _In_opt_ DISM_PROGRESS_CALLBACK Progress,
    _In_opt_ PVOID                  UserData
    );
    */

}
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,815 questions
0 comments No comments
{count} votes

Accepted answer
  1. Darran Rowe 1,316 Reputation points
    2024-12-15T21:49:59.02+00:00

    This is because applying the image is part of the Windows Imaging API (WIMGAPI), not the DISM API. In particular, the WIMApplyImage function.

    For the compact flag, this isn't documented but it is in the headers, defined as WIM_FLAG_APPLY_COMPACT.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.