Click here to Skip to main content
15,911,139 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
QuestionHelp me Pin
Amit Battan Ror17-Jul-08 3:47
Amit Battan Ror17-Jul-08 3:47 
QuestionInitialization for OE/ Windows Mail Addin Pin
dolly16-Jul-08 0:14
dolly16-Jul-08 0:14 
Questiontab dialog question Pin
monsieur_jj14-Jul-08 21:48
monsieur_jj14-Jul-08 21:48 
Questionredefinition Enum member on IDL file Pin
iman_kh10-Jul-08 7:32
iman_kh10-Jul-08 7:32 
QuestionHow to set IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit to make DLL DEP compatible with VC 6.0 compiler Pin
dolly8-Jul-08 1:40
dolly8-Jul-08 1:40 
AnswerRe: How to set IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit to make DLL DEP compatible with VC 6.0 compiler Pin
Stuart Dootson8-Jul-08 6:58
professionalStuart Dootson8-Jul-08 6:58 
QuestionRe: How to set IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit to make DLL DEP compatible with VC 6.0 compiler Pin
dolly8-Jul-08 18:06
dolly8-Jul-08 18:06 
AnswerRe: How to set IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit to make DLL DEP compatible with VC 6.0 compiler [modified] Pin
Stephen Hewitt10-Jul-08 19:25
Stephen Hewitt10-Jul-08 19:25 
Here's a program I knocked together which will set the bit for you. It's been tested so I know it works.

// SetNXCompat.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <Imagehlp.h>
#include <shlwapi.h>
#include <malloc.h>
#include <iostream>
#include <string>
#pragma comment(lib, "Imagehlp.lib")
#pragma comment(lib, "shlwapi.lib")
using namespace std;
 
// In case you're using an old SDK that doesn't include the flag.
#ifndef IMAGE_DLLCHARACTERISTICS_NX_COMPAT
#	define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
#endif
 
// We'll be nice and support both ANSI and UNICODE.
#ifdef UNICODE
#	define tcout wcout
#	define tcerr wcerr
	typedef wstring tstring;
#else
#	define tcout cout
#	define tcerr cerr
	typedef string tstring;
#endif
 
void PrintUsage()
{
	tcout << _T("Usage:") << endl;
	tcout << _T("\tSetNXCompat <file>") << endl;
}
 
bool Worker(LPCTSTR pDir, LPCTSTR pFile)
{
	// Load the image.
	LOADED_IMAGE li;
	BOOL ok = MapAndLoad(
			const_cast<LPTSTR>(pFile),	// PSTR ImageName
			const_cast<LPTSTR>(pDir),	// PSTR DllPath
			&li,				// PLOADED_IMAGE LoadedImage
			FALSE,				// BOOL DotDll
			FALSE				// BOOL ReadOnly
			);
	if (!ok)
	{
		return false;
	}
 
	// Set the flag.
	IMAGE_NT_HEADERS *pHeaders = li.FileHeader;
	pHeaders->OptionalHeader.DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
 
	// We'll go the extra mile and set the checksum.
	DWORD org_sum;
	DWORD new_sum;
	IMAGE_NT_HEADERS *pNT = CheckSumMappedFile(
					li.MappedAddress,	// PVOID BaseAddress
					li.SizeOfImage,		// DWORD FileLength
					&org_sum,		// PDWORD HeaderSum
					&new_sum		// PDWORD CheckSum
					);
	if (pNT != NULL)
	{
		pNT->OptionalHeader.CheckSum = new_sum;
	}
	else
	{
		tcerr << "WARNING: Failed to update checksum." << endl;
	}
 
	// Were done!
	ok = UnMapAndLoad(&li);
 
	return (ok) ? true : false;
}
 
int main(int argc, TCHAR* argv[])
{
	if (argc != 2)
	{
		PrintUsage();
		return -1;
	}
 
	// Get the directory.
	tstring dir;
	if (PathIsRelative(argv[1]))
	{
		// Get the current directory.
		DWORD len = GetCurrentDirectory(0, NULL);
		LPTSTR pBuffer = static_cast<LPTSTR>(_alloca((len+1)*sizeof(TCHAR)));
		GetCurrentDirectory(len+1, pBuffer);
		dir = pBuffer;
	}
	else
	{
		dir = argv[1];
		tstring::size_type pos = dir.find_last_of(_T("\\/"));
		if (pos == -1)
		{
			tcerr << "Error in file path!" << endl;
			return -2;
		}
 
		dir.erase(pos);
	}
 
	// Feed the worker.
	if (!Worker(dir.c_str(), argv[1]))
	{
		tcerr << "Failed!" << endl;
		return -3;
	}
 
	return 0;
}


Steve

modified on Friday, July 11, 2008 3:33 AM

GeneralRe: How to set IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit to make DLL DEP compatible with VC 6.0 compiler Pin
Stuart Dootson11-Jul-08 5:24
professionalStuart Dootson11-Jul-08 5:24 
GeneralRe: How to set IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit to make DLL DEP compatible with VC 6.0 compiler Pin
Stephen Hewitt13-Jul-08 14:23
Stephen Hewitt13-Jul-08 14:23 
QuestionRe: How to set IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit to make DLL DEP compatible with VC 6.0 compiler [modified] Pin
dolly17-Jul-08 19:47
dolly17-Jul-08 19:47 
AnswerObviously this will not work! Pin
Elmue2-Jul-20 7:34
Elmue2-Jul-20 7:34 
GeneralRe: Obviously this will not work! Pin
Richard Deeming2-Jul-20 23:20
mveRichard Deeming2-Jul-20 23:20 
AnswerRe: Obviously this will not work! Pin
Elmue3-Jul-20 19:42
Elmue3-Jul-20 19:42 
QuestionNamespace-extension: How to customize "Details" in left-pane Pin
seansu5-Jul-08 1:04
seansu5-Jul-08 1:04 
QuestionC++ ATL COM addin DLL blocked by Vista's DEP Pin
dolly4-Jul-08 1:33
dolly4-Jul-08 1:33 
AnswerRe: C++ ATL COM addin DLL blocked by Vista's DEP Pin
Anna-Jayne Metcalfe7-Sep-08 4:11
Anna-Jayne Metcalfe7-Sep-08 4:11 
QuestionConvert Visual Studio 2005 ATL COM project into Visual C++ 6.0 project Pin
dolly3-Jul-08 1:49
dolly3-Jul-08 1:49 
AnswerRe: Convert Visual Studio 2005 ATL COM project into Visual C++ 6.0 project Pin
hdj83114-Aug-08 21:51
hdj83114-Aug-08 21:51 
QuestionCalendar Control question [modified] Pin
monsieur_jj2-Jul-08 21:59
monsieur_jj2-Jul-08 21:59 
Questionmouse move or click event on Internet Explorer Pin
Dabara1-Jul-08 22:53
Dabara1-Jul-08 22:53 
AnswerRe: mouse move or click event on Internet Explorer Pin
Ju@ncho4-Jul-08 3:23
Ju@ncho4-Jul-08 3:23 
QuestionSDI Form View Application Pin
Robert Payan30-Jun-08 19:33
Robert Payan30-Jun-08 19:33 
QuestionNamespace-extension: How to implement IShellFolder2 Pin
seansu29-Jun-08 8:03
seansu29-Jun-08 8:03 
AnswerRe: Namespace-extension: How to implement IShellFolder2 Pin
KarstenK2-Jul-08 22:15
mveKarstenK2-Jul-08 22:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.