ALERT! The community will be read-only starting on April 19, 8am Pacific as the migration begins. Read more for important details.
ALERT! The community will be read-only starting on April 19, 8am Pacific as the migration begins.Read more for important details.

Checking VC++ Runtime Distribution Installation in 32/64bit Architecture

Absent Member.
Absent Member.
0 0 5,246
0 Likes
In the process of achieving 64bit compatibility, developers usually opt for higher but stable version of compiler. On windows it is Visual C++ compiler version higher than VC++ 98(i.e. VC 6.0). That’s where the technical challenge of finding VC++ runtime installation comes to picture. Why? The answer to this is that, when developer opt for a newer compiler for example Visual Studio 2005, it introduces its own technical issue in deployment. Either VC++ runtime libraries should be shipped with the product or they can be installed similar to any other package installation to fulfill your product dependency.

Now there are situations where the custom installer should determine whether a particular version of VC++ runtime distribution package is installed on deployment system or not.

The code below will help you to determine VC++ runtime distribution as well as architecture check.

#include <msi.h>
#include <windows.h>
#include <stdio.h>

// forward declaration
BOOL Is64BitWindows();

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
INSTALLSTATE install_state;


if(Is64BitWindows())
{
::MessageBox(NULL, "64bit Operating System" ,"Success",MB_OK | MB_ICONINFORMATION);
install_state = MsiQueryProductState("{071c9b48-7c32-4621-a0ac-3f809523288f}"); //for x64 runtime
}
else
{
::MessageBox(NULL, "32bit Operating System" ,"Success",MB_OK | MB_ICONINFORMATION);
install_state = MsiQueryProductState("{7299052b-02a4-4627-81f2-1818da5d550d}"); // for x86 runtime
}

//for IA64
//install_state = MsiQueryProductState("{0f8fb34e-675e-42ed-850b-29d98c2ece08}");


if ( install_state == INSTALLSTATE_DEFAULT )
{
::MessageBox(NULL, "VC++ 2005 SP1 Runtime already installed" ,"Success",MB_OK | MB_ICONINFORMATION);
}
else
{
::MessageBox(NULL, "Please install VC++ 2005 SP1 Runtime package to continue...","Error",MB_OK | MB_ICONERROR);
}

return 0;
}


// Detect whether operating system is 32bit or 64bit
BOOL Is64BitWindows()
{
#if defined(_WIN64)
return TRUE; // 64-bit programs run only on Win64
#elif defined(_WIN32)
// 32-bit programs run on both 32-bit and 64-bit Windows
// so must sniff
BOOL bIsWow64 = FALSE;

fnIsWow64Process= (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");

if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{
::MessageBox(NULL, "Please install VC++ 2005 SP1 Runtime package to continue...","Error",MB_OK | MB_ICONERROR);
}
}

return bIsWow64;
#else
return FALSE; // Win64 does not support Win16
#endif
}




Some tips and tricks on how we achieved this:



The string that you find in above code as a parameter to MsiQueryProductState(..) function is specific to vc++ runtime sp2 version. You will get similar strings for other versions too.

MsiQueryProductState(..) function returns install state of the product . Using which one can determine the state of package installation.

Is64BitWindows(..) function will determine the architecture of the machine where the process is running. It even takes care of process running under WOW64bit emulation mode.

If you need more information feel free to approach me. I would help you in resolving similar issues.
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.