.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;
}

qmake tutrial failed with “QPushButton: No such file or directory”

Add following line at the top of your hello.pro.

QT += widgets

Reading EPWING dictionaries with Dicregate

1,Obtain any EPWING dictionaries.
2,Open Dicregate.exe
3,Select [Dictionary]->[Add Dictionary]->[Electronic Dictionary]

4,Choose the dictionary folder, the folder that includes a file named “CATALOGS”

How to use VB regex in VC6

1,Open “OLE/COM object viewer” from Tool menu of VC6.
2,Find “Microsoft VBScript Regular Expressions 5.5” under “Type Libraries”.

3, Double click the node to open with “ITypeLib Viewer”.
4, Choose “Save As” and save as “vbscript.IDL”.

5, Run “midl vbscript.idl” in Command Propmt. midl.exe is typically located under “C:\Program Files\Microsoft Visual Studio\VC98\Bin”.

This creates “vbscript.tlb”.
6, Move this file into your VC6’s project directory.

7, By coding #import “vbscript.tlb” in your source file, VB regex will be available.

#include "stdafx.h"
 
#import "vbscript.tlb" no_namespace named_guids
 
_bstr_t vbregReplace(LPCTSTR source,
					 LPCTSTR replace, 
					 LPCTSTR regex,
					 BOOL bGlobal,
					 BOOL bCaseInsensitive)
{
	IRegExpPtr pReg;
	pReg.CreateInstance(CLSID_RegExp);
 
	_bstr_t bstrSource(source);
	_bstr_t bstrReplace(replace);
	_bstr_t bstrRegex(regex);
 
	pReg->put_Global(bGlobal?VARIANT_TRUE:VARIANT_FALSE); 
	pReg->put_IgnoreCase(bCaseInsensitive?VARIANT_TRUE:VARIANT_FALSE); 
	pReg->put_Pattern(bstrRegex); 
 
	_bstr_t bstrRet = pReg->Replace(bstrSource, bstrReplace);
 
	return bstrRet;
}
 
int main(int argc, char* argv[])
{
	CoInitialize(NULL);
	_bstr_t t = vbregReplace(
		"abcdefg",
		"x",
		"[aceg]",
		TRUE,
		TRUE);
 
	puts(t);
	CoUninitialize();
	return 0;
}

How to create a C++ function that can take argment of both char* and wchar_t*

Source.
Create a traits class that is used as specialized template. Specialize it for char and wchar_t. Generic template is not defined because this function is only for char and wchar_t.

#include <wchar.h>
#include <stdio.h>
 
template<typename T> struct kansuu_traits;
template<> struct kansuu_traits<char>
{
	static FILE* open(const char* p)
	{
		return fopen(p, "r");
	}
};
template<> struct kansuu_traits<wchar_t>
{
	static FILE* open(const wchar_t* p)
	{
		return _wfopen(p, L"r");
	}
};
 
template<typename cT> void kansuu(const cT* p)
{
	FILE* f = kansuu_traits<cT>::open(p);
	fclose(f);
}
 
int main(int argc, char* argv[]){
	kansuu(L"C:\\TEST\\Text.txt");
	kansuu("C:\\TEST\\Text.txt");
 
	return 0;
}