Diagnose 0xc000007b in a Delphi Windows application
Windows status 0xc000007b is STATUS_INVALID_IMAGE_FORMAT. A common cause is a process trying to load a native dependency built for an incompatible architecture. The status is broader than that one cause, so verify the actual executable and DLL files rather than assuming that every occurrence is a 32-bit versus 64-bit mismatch.
The failure can happen before Delphi initialization code runs. Adding a try/except block to the project source therefore may not catch it. Start by recording the executable path, target platform, deployment contents and exact launch failure.
Inspect the PE machine type
The following read-only PowerShell script reports the architecture stored in a Portable Executable header. Save it as Get-PeMachine.ps1. It works with ordinary native Windows executables and DLLs and does not load or execute the inspected file.
param([Parameter(Mandatory)][string[]]$Path)
foreach ($item in $Path) {
$resolved = (Resolve-Path -LiteralPath $item -ErrorAction Stop).Path
$stream = [System.IO.File]::OpenRead($resolved)
$reader = [System.IO.BinaryReader]::new($stream)
try {
if ($stream.Length -lt 64 -or $reader.ReadUInt16() -ne 0x5A4D) {
throw 'Not an MZ executable.'
}
$stream.Position = 0x3C
$offset = $reader.ReadInt32()
if ($offset -lt 64 -or $offset -gt $stream.Length - 6) {
throw 'Invalid PE header offset.'
}
$stream.Position = $offset
if ($reader.ReadUInt32() -ne 0x00004550) {
throw 'Missing PE signature.'
}
$machine = $reader.ReadUInt16()
$architecture = switch ($machine) {
0x014C { 'x86' }
0x8664 { 'x64' }
0xAA64 { 'ARM64' }
default { 'Other (0x{0:X4})' -f $machine }
}
[pscustomobject]@{ File = $resolved; Architecture = $architecture }
} finally {
$reader.Dispose()
$stream.Dispose()
}
}
Run ./Get-PeMachine.ps1 -Path './MyApp.exe','./Vendor.dll' in PowerShell from a directory containing your deployment. A Win64 application should report x64. A native DLL loaded into that process must support the compatible process architecture. A separate helper executable can have a different architecture because it runs in its own process.
The script deliberately reads only the machine field. It does not validate the complete image, its imports, signatures or loader compatibility. A successful header read is evidence about architecture, not proof that Windows can load the file.
Trace the dependency chain
If Visual Studio C++ build tools are installed, use their Developer Command Prompt to run dumpbin /headers MyApp.exe and dumpbin /dependents MyApp.exe. Inspect the corresponding DLLs and their dependencies as well. A directly imported DLL can match while one of its own imports does not.
Check the actual resolved files, not just the files you intended to deploy. Search paths, application-local copies and older installations can select an unexpected DLL with the same name. Delphi runtime packages also need to match the compiler generation, platform and package set used for the application.
Distinguish missing dependencies from malformed or incompatible images. Record the loader evidence and file versions rather than replacing every DLL in the directory at once. A corrupt or truncated file can require restoring the correct vendor artifact even when the machine field looks right.
Repair one proven mismatch
Rebuild the application and owned native dependencies for one intended platform, or obtain the matching supported vendor binaries. Deploy into a clean application directory with the required matching runtime packages. Preserve the previous deployment so the comparison is reproducible.
Do not copy arbitrary downloaded DLLs into Windows system directories. That changes shared machine state and does not establish the correct dependency graph. Install an official runtime package only when the application's dependencies require it.
Verify by launching the repaired application under its normal account and exercising the code that loads optional DLLs. Static imports can fail at startup, while delayed or explicit loads may fail later. This diagnostic script is executable independently, but a complete repair still requires testing the affected deployment.
References




Question provenance
This article addresses The application was unable to start correctly (0xc000007b) , asked by Mawg on Stack Overflow. The source question is licensed under CC BY-SA 3.0 . The explanation and examples here are newly authored for current Delphi. No answer text or code is reproduced.
Author: Herman Schoenfeld