You are currently browsing the archives for the Uncategorized category


warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification

When you upgraded your VC++ project to Visual Studio 2013 or later(?), this warning appears. It looks like VS failed to upgrade projects properly.

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='UnicodeDebug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <PlatformToolset>v120</PlatformToolset>
    <UseOfMfc>Dynamic</UseOfMfc>

    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>

It needs to add “<UseDebugLibraries>true</UseDebugLibraries>” to your *.vcxproj file. See the following fixed file. In a Release configuration, it needs to set false of this attribute.

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='UnicodeDebug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <PlatformToolset>v120</PlatformToolset>
    <UseOfMfc>Dynamic</UseOfMfc>
    <UseDebugLibraries>true</UseDebugLibraries>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>

BadImageFormatException not handled

This exception occurs when AnyCpu-C# app tries to load X86 assembly in 64bit environment. Change the app configuration to X86 or prepare X64 assembly to load.

Install of VS2017 broke VC#2008 coloader80.dll configuration

Open command prompt with Admin priviledge and do followings.

regsvr32 "%CommonProgramFiles%\Microsoft Shared\VS7Debug\coloader80.dll"

if it fails, do this.

regsvr32 "%CommonProgramFiles(x86)%\Microsoft Shared\VS7Debug\coloader80.dll"

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.

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