4/16/2015

SideBySide configuration ERROR : MS Visual C++

# Introduction:  Sometimes when you try to run your application on windows XP / VISTA (old systems) or Windows 7 (where Visual C++ shared libraries is not installed, )
your application won't run, instead it gives you an ERROR, like,
configuration error
SideBySide configuration error
Activation context generation failed




# This error is because of missing Visual C++ Shraed runtime libraries. So all you can do is install it.
But sometimes you do not have Admin privileges to install it,
Ok, this is where concept of local manifest comes in play, Now we will write a local manifest file for
required Visual C++ shared libraries.


# Situation First : Running Python Interpreter
Python Interpreter require Microsoft.VC90.CRT Shraed libraries, So we have to write Microsoft.VC90.CRT.manifest file,
this is basically a XML file and you can write this file using Notepad, Nodepad++ ( If you have installed. )



=> Open notepad and write this XML code and save it as Microsoft.VC90.CRT.manifest
into the same directory where you have your application, in this case python.exe
=> Now you should have these three DLLs, listed in manifest file,
msvcm90.dll , msvcp90.dll , msvcr90.dll
copy and paste these three DLLs into application folder, in this case %PYTHONHOME%

## Microsoft.VC90.CRT.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright (c) Microsoft Corporation.  All rights reserved. -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <noInheritable/>
    <assemblyIdentity
        type="win32"
        name="Microsoft.VC90.CRT"
        version="9.0.21022.8"
        processorArchitecture="x86"
        publicKeyToken="1fc8b3b9a1e18e3b"
    />
<file name="msvcm90.dll"/>
<file name="msvcp90.dll"/>
<file name="msvcr90.dll"/>
</assembly>


# Situation Second : Running WinHTtrack 
winhttrack.exe require Microsoft.VC90.MFC shared libraries,



=> Open notepad and write this XML code into it, and save it as Microsoft.VC90.MFC.manifest file,
into the same directory, where you have winhttrack.exe executable file.
=> Now copy these DLLs into Application root directory, (as listed in manifest file)
mfc90.dll , mfc90u.dll, mfcm90.dll , mfcm90u.dll

## Microsoft.VC90.MFC.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright (c) Microsoft Corporation.  All rights reserved. -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <noInheritable/>
    <assemblyIdentity
        type="win32"
        name="Microsoft.VC90.MFC"
        version="9.0.21022.8"
        processorArchitecture="x86"
        publicKeyToken="1fc8b3b9a1e18e3b"
    />
<file name="mfc90.dll"/>
<file name="mfc90u.dll"/>
<file name="mfcm90.dll"/>
<file name="mfcm90u.dll"/>
</assembly>


# List of Visual C++ Shraed libraries and their dependent DLL files.
# Active Template Library
Microsoft.VC90.ATL
atl90.dll

# C Runtime Library, release DLLs
Microsoft.VC90.CRT
msvcr90.dll
msvcp90.dll
msvcm90.dll

# C Runtime Library, debug DLLs
Microsoft.VC90.DebugCRT
msvcr90d.dll
msvcp90d.dll
msvcm90d.dll

# Microsoft Foundation Classes, release DLLs
Microsoft.VC90.MFC
mfc90.dll
mfcm90.dll
mfc90u.dll
mfcm90u.dll

# Microsoft Foundation Classes, debug DLLs
Microsoft.VC90.DebugMFC
mfc90d.dll
mfcm90d.dll
mfc90ud.dll
mfcm90ud.dll

# Microsoft Foundation Classes, localized resources
Microsoft.VC90.MFCLOC
mfc90chs.dll
mfc90deu.dll
mfc90esp.dll
mfc90ita.dll
mfc90kor.dll
mfc90cht.dll
mfc90enu.dll
mfc90fra.dll
mfc90jpn.dll

# OpenMP Library, release DLLs
Microsoft.VC90.OpenMP
vcomp.dll

# OpenMP Library, debug DLLs
Microsoft.VC90.DebugOpenMP
vcompd.dll


# Development model of Visual C++ :=>  Concepts of Isolated Applications and Side-by-side Assemblies
In Visual C++ 2005, the ATL, MFC, Standard C++, and CRT libraries support the new deployment model available on Windows XP,  Windows Server 2003, and Windows Vista. The DLLs corresponding to all Visual C++ libraries have been grouped into several shared side-by-side assemblies and are installed into the native assembly cache, also called the WinSxS folder, under the operating system root directory.

# If you want to know more, look for it,
https://msdn.microsoft.com/en-us/library/ms235624(v=vs.90).aspx


pip.exe runtime error : Python

# Introduction : Fatal error in launcher, Unable to create process using 'C:\Python27\python.exe'   'C:\Python27\Scripts\pip.exe'
This error is because of change in Python environment, to fix it, all you have to do is, tell every program which is not running about this new python environment.

like LINUX command line applications, first line is for program selection, for example,
=> If you are writing a bash script, first line of script will be,
#!/usr/bin/env bash
OR
#!/bin/bash

=> If you are writing a python executable script, first line of script will be,
#!/usr/bin/env python2.7
OR
#!/usr/opt/python27/python2.7
OR
#!/usr/local/bin/python2.7

So, this first line is about, how and using which program, you want to execute it, and where is that program , which you installed.
If you had changed path of this program executable, you also have to tell all your scripts about it, If path to this program is absolute.

#!/usr/bin/env python
This line of code is going to ask  env  program, about absolute location of python executable, if python executable is inside System PATH environment variable (Directories).

# General Solution:-
=> If your python script (like, pip.exe, pip2.exe, easy_install.exe, ipython.exe) do not know about, new location of python interpreter,
then you are going to tell it about python, either by embedding new location of python interpreter or invoking that script with python interpreter.



# Method 1:-
=> Using Python Interpreter (invoke python script with python script executable )
(After adding, python.exe into System PATH environment variable)
You can invoke any python module, using python interpreter, like this

python -m pip install ipython

(select python module named, pip and pass two command line arguments, install, and ipython)

# Method 2:-
=> Using Hex Editor to update new location/path for Python Interpreter.
If all you have is pip.exe (, pip2.exe, easy_install.exe, ipython.exe) instaed of pip.py
then, How your python script knows about python interpreter location/path.
Well, location/path of python interpreter is embeded into it, and you are going to edit it using Hex editor,
A good Hex Editor is Neo Hex Editor, that is Free for personal/limited use.

=> Open  pip.exe using Hex Editor of your choice.
Look for  Python  string inside pip.exe
Program will locate something like this,
#!C:\Python27\python.exe

<Image>
__python_error_before_hex_editing



All you have to do is,
Either change this path to new absolute path to python interpreter.
OR
Edit it like so, (You are telling this script to look for a program name python.exe, which is inside system path environment variable Directories)
#!python.exe


<Image>
__python_error_after_hex_editing


# Method 3:-
=> Using 7zip program to extract __main__.py script from pip.exe (or other similar program, which is showing this runtime error)
=> type __main__.py

# -*- coding: utf-8 -*-
import re
import sys

from pip import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

=> save as this file to pip.py in Script Directory.
=> If you want to invoke this program, use python interpreter.
python pip.py install ipython

=> If you like then you can also create a Batch file ( pip.bat )
@echo off
python %~dp0pip.py %*

# Remember,
%cd%    => expands to current working directory
after expanf   =>  example ,    ( D:\cmder\bin )
%~dp0   => expands to script directory ( where script file in resides on file-system )
after expand   =>  example ,   ( D:\cmder\bin\ )