1

I had to write an simple application with some specific requirements:
1. It should consist of just one exe-file, no installer or external DLL's
2. It should be small
3. It should run on any Windows (Win32) platform (at least on Windows XP), without making any modifications to the Windows installation (no dependencies to .NET, JVM, MFC or Visual Studio redistributables)
4. It should have a simple (dialog based) UI

I decided to do it as a simple Win32 Application in C (C++) and using only the standard win32 api, no fancy stuff. I created the project with Visual Studio 2010 on 64 bit Windows 7 and changed Runtime Library from Multi-threaded DLL to just Multi-threaded. I thought this would produce the most Windows-compatible application possible.

The compiled application works fine on my Windows 7, but I cannot get it to start on any Windows XP PC. I have tried both on Windows XP SP2 and SP3. The strange thing is that I don't get any error message and no rogue processes in the Activity Manager, nothing happens when I double-click the exe-file. And there is no DrWatson log produced.

I have checked the Target Machine in project settings and it is MachineX86.

I have googled a lot on the problem, and one tip was to modify targetver.h, which I have done without result. This is what my targetver.h looks like right now:

#include <WinSDKVer.h>
#define _WIN32_WINNT      _WIN32_WINNT_WINXP
#include <SDKDDKVer.h>

I have also tried dependency walker, but it only shows and error for a delay-loaded DLL called DWMAPI.DLL, which seems to be a Vista DLL. And also warnings for two other delay-loaded DLL's, MPR.DLL and SHLWAPI.DLL. But since they are delay-loaded and I don't think I use anything in them it shouldn't matter (googling on it shows that these warnings should be disregarded).

My goal is to be able to compile an exe that will work on the XP-machines without making any modification to them.

Christoffer
  • 191
  • 2
  • 9
  • possible duplicate of [How do I compile for windows XP under windows 7 / visual studio 2008](http://stackoverflow.com/questions/2581752/how-do-i-compile-for-windows-xp-under-windows-7-visual-studio-2008) – Ken Wayne VanderLinde Feb 03 '12 at 07:14
  • Can you do a "dumpbin /imports yourapp.exe" (where "yourapp.exe" is your EXE name)? That might give some hints about what DLLs are missing. Also, the system event log will usually have some information about why a process failed to start. – selbie Feb 03 '12 at 07:20
  • This should work. You didn't share any code, so it's hard to guess what's wrong. Have you tried building a simple "hello world" console app that is statically linked with the VC runtime (as you describe above). Does that fail to run? It's entirely possible your program is running just fine on XP... bu tyou may have a "bug" that causes it to abort or not display anything on XP. Have you tried debugging your EXE on XP with a debugger? – selbie Feb 03 '12 at 07:24
  • Did you try with an empty app? Just the basic win32 gui template app. – David Heffernan Feb 03 '12 at 07:32
  • Thanks for all the tips. I looked in the event log, but there is no entry at all from the time when I try to launch my app. I tried building the default template Win32 app and it does successfully start on Windows XP. I will try to follow selbies tip and use dumpbin. – Christoffer Feb 03 '12 at 07:46
  • And my first thought was also that it was a simple bug in my code, but I tried to add aMessageBox(NULL, _T("Hello World"), _T("Test"), MB_OK) on the first line in the WinMain and it didn't even reach that... – Christoffer Feb 03 '12 at 07:47

3 Answers3

1

I solved the problem. When I said I did it as plain Win32 without fancy stuff it wasn't completely true. I didn't want the boaring pre-XP look and feel when running on modern operating systems, so I added these lines to stdafx.h (following a tip I found on the net):

#define ISOLATION_AWARE_ENABLED 1
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

The reason I didn't mention this was that I had already tried to remove these lines, but it still didn't work (and I still can't understand why it didn't work when I removed those lines, I tried it more than once).

But after more reading on MSDN articles I found that these lines needs to be before the include of windows.h so I move it and now it works (both with classic and xp style)

So the problem seems to be that I changed to version 6 of ComCtl32 on the wrong side of the include of windows.h, but I still don't know why it didn't work when I removed those lines. Could Windows be caching the manifest in some way?

Christoffer
  • 191
  • 2
  • 9
0

Maybe you need this on XP machine: MSVC 2010 runtime

dbrank0
  • 9,026
  • 2
  • 37
  • 55
  • 1
    That was my first guess.. but he says: "and changed Runtime Library from Multi-threaded DLL to just Multi-threaded". He's statically linking. – selbie Feb 03 '12 at 07:19
  • Ah, I missed that. I'd still install that. Just to exclude possibility, that some of libraries contained here was not statically linked. – dbrank0 Feb 03 '12 at 07:56
0

Try creating a program that is statically linked to the C Runtime library.

Do the following in your project in your solution: Go to Properties | Configuration | C/C++ | Code Generation | Runtime Library.

Release: Change /MD to /MT, Multithreaded. Debug: Change /MDd to /MTd, Debug Multithreaded.

If you want to keep using dynamic linking, then copy the MSVC++ runtime file into your XP machine, as suggested by @dbrank(). However, you stated in your original post that you wanted a standalone .exe with no extra files to copy.

Phillip Ngan
  • 15,482
  • 8
  • 63
  • 79