Visual Studio 2017 add a context menu item “Open With Visual Studio” on the shell extension of directory

Remove
HKEY_CLASSES_ROOT\Directory\Background\shell\AnyCode
and
HKEY_CLASSES_ROOT\Directory\shell\AnyCode
from Registry to delete it.

Refresh the taskbar of Windows 10

Sometimes windows 10 taskbar failed to draw the application icon. ie4uinit.exe can fix it. Create the following batch file and run it.

REM @echo off
set "UTIL=%SystemRoot%\System32\ie4uinit.exe"
 
IF NOT EXIST %UTIL% (
set "UTIL=%SystemRoot%\Sysnative\ie4uinit.exe"
)
 
%UTIL% -ClearIconCache
%UTIL% -show

Differences of Command prompt of Visual Studio

There are many kind of shortcuts of command prompt of Visual Studio. Basically the differences are the setting of Host and Target. Host refers to the compiler or linker of which 64bit or 32bit is chosen. Target refers to the resultant exe or dll which is targeted 64bit or 32bit.

Developer Command Prompt for VS 2017 (default)

Host:32bit
Target:32bit

x64 Native Tools Command Prompt for VS 2017

Host:64bit
Target:64bit

x64_x86 Cross Tools Command Prompt for VS 2017

Host:64bit
Target:32bit

x86 Native Tools Command Prompt for VS 2017

Same as the default.

x86_x64 Cross Tools Command Prompt for VS 2017

Host:32bit
Target:64bit

Build ffmpeg-debug with Windows10 64bit

Install msys2

Install the 64bit msys2. I downloaded msys2-x86_64-20161025.exe and installed it on C:\local\msys64.

Install necessary tools

Run msys2-64 and install tools as follows.

$ pacman -S make pkg-config diffutils
$ pacman -S mingw-w64-x86_64-yasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL

Install git and obtain source files

$ pacman -S git
$ git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg

Build with debug option

$ cd ffmpeg
$ ./configure --enable-shared --disable-static --disable-optimizations --disable-mmx --disable-stripping
$ make
$ make install

debug with gdb

$ pacman -S gdb
$ gdb --tui ffmpeg_g.exe

.NET4 installation fails on XP PosReady

It needs WIC.

LoadLibrary(jvm.dll) fails even if the file exists

It needs an appropriate C++ runtime library to load jvm.dll. Install VC++ 20XX Redistributable.

VMWare : Netwoking of Guest OS is not available after restoring

Stopping network related service will fix it.

C:\WINDOWS\system32>net stop bits
The Background Intelligent Transfer Service service is stopping..
The Background Intelligent Transfer Service service was stopped successfully.
 
 
C:\WINDOWS\system32>net stop wuauserv
The Background Intelligent Transfer Service service is stopping..
The Background Intelligent Transfer Service service was stopped successfully.
 
 
C:\WINDOWS\system32>

wuauserv is Windows Update Service, I do not know what will happen if wuauserve stops during this service is actually updating OS.

MessageBox is not shown after Dialog was closed in MFC Dialog Application

In Win32, you can not show MessageBox after calling PostQuitMessage() until calling GetMessage to get out of message loop.

In MFC dialog app, the dialog is set to m_pMainWnd and when dialog is closed, PostQuitMessage is called. If you want to show MessageBox after the dialog closed, there is two method to do this.

Method 1, Keep m_pMainWnd to NULL.
Comment out the following line so that m_pMainWnd is not set.

m_pMainWnd = &dlg;

Method 2, Call PumpMessage to call GetMessage.
Calling PumpMessage until it returns false. After that you can show MessageBox.

while(PumpMessage())
    ;

error MSB8020: The build tools for v120 (Platform Toolset = ‘v120’) cannot be found.

Usually you can fix this error by changing tool-set VS uses. But if the Solution includes a reference which uses old too-set, It also fails.

Check your reference setting.
references

Check whether a file is open or not in Win32

There is no easy way to check file is open. I write simple code to check it but it still has problems.

  1. Like thread, it is not sure the file is actually open or not at the function returns because file is global resource, any other processes can open or close at any moment.
  2. This blocks other process to open file it would succeed if this function not operate.
enum ISFILEOPEN {
	ISFILEOPEN_NO,
	ISFILEOPEN_YES,
	ISFILEOPEN_UNKNOWN,
} ;
 
ISFILEOPEN IsFileOpen(LPCTSTR pFile);
#include 
#include "IsFileOpen.h"
 
ISFILEOPEN IsFileOpen(LPCTSTR pFile)
{
	HANDLE f = CreateFile(
		pFile,
		GENERIC_READ,
		0, // share
		NULL, // sec
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		NULL);
 
	if(f==INVALID_HANDLE_VALUE)
	{
		switch(GetLastError())
		{
		case ERROR_SHARING_VIOLATION:return ISFILEOPEN_YES;
		case ERROR_ACCESS_DENIED:return ISFILEOPEN_UNKNOWN;
		}
		return ISFILEOPEN_NO;
	}
 
	CloseHandle(f);
	return ISFILEOPEN_NO;
}