STandalone Exe File runing on older versions of Windows

So I have a project that compiles and runs great on Windows 8 with Visual Studio 2010.
My problem is that when testing the application on a VMware Windows XP machine it crashes.
So faded in the back of my mind I think I remember a nice little code to make the exe standalone and executable on old and new versions of Windows.

I think its something like.
#ifndef WINVER >= SOMETHING

I have set the Runtime Library to Multi Threaded "/MT".

Am sure someone here as had the same issue but I can`t find any thing on Google.
Help is much appreciated.

Cheers
WetCode.
Last edited on
So after reading msdn.microsoft.com/en-us/library/aa383745(v=vs.85).aspx#setting_winver_or__win32_winnt

i did the following to the stdafx.h in my project.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers

#if WINVER > 0x0501
#define WINVER 0x0501
#endif

#if NTDDI_VERSION > 0x05010000
#define NTDDI_VERSION 0x05010000
#endif

#if _WIN32_WINNT > 0x0501
#define _WIN32_WINNT 0x0501
#endif

// Windows Header Files:
#include <windows.h>

// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h> 


But with no luck can anyone shed some light on this ?
Have you made sure that all of the DLL files you are linking against are the same version? Do we get to see any feed back from the debugger? Is anything popping up on Event Viewer (or whatever it is called in Win 8)?

The data you have here tells cl to compile for Win XP SP 1 so I doubt that the issue is in this file. The program is probably trying to call a function that has changed some thing between the DLL is was compiled against on Win 8 and the DLL it is trying to link to in Win XP. This my friend is called DLL Hell for a very good reason: http://en.wikipedia.org/wiki/DLL_Hell
Last edited on
Thanks for your reply and confirming that the code is correct it made me smile.
I understand now I got a huge job in front of me that's for sure.

BTW Event Viewer gives me this error. (on WIndows XP SP1 (Running under VMware Win 8).
Faulting application Office Box.exe, version 0.0.0.0, 
faulting module unknown, version 0.0.0.0, fault address 0x00000000.
Last edited on
The easy way to confirm my theory would be to compile your code on the XP VM and see if it still crashes. This doesn't solve the issue but it narrows down the problem.
I had the same idea, i found this as well.
Can this be a sulution to the problem?

Snip from: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212%28v=vs.85%29.aspx
If the function might not exist in the DLL module—for example, if the function is available only on Windows Vista but the application might be running on Windows XP—specify the function by name rather than by ordinal value and design your application to handle the case when the function is not available, as shown in the following code fragment.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);

// Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.

   PGNSI pGNSI;
   SYSTEM_INFO si;

   ZeroMemory(&si, sizeof(SYSTEM_INFO));
   
   pGNSI = (PGNSI) GetProcAddress(
      GetModuleHandle(TEXT("kernel32.dll")), 
      "GetNativeSystemInfo");
   if(NULL != pGNSI)
   {
      pGNSI(&si);
   }
   else 
   {
       GetSystemInfo(&si);
   }

or http://msdn.microsoft.com/en-us/library/windows/desktop/ms686944%28v=vs.85%29.aspx

Thanks
Last edited on
closed account (13bSLyTq)
Hi,

In Visual Studio 2010, if you develop on Windows 7 and older it will work on almost all OS except from obvious OS like MS-DOS but on Windows 8, as a development environment - it is best to use VS2012 as it contains XP target.

This thread is bound to help, future developers.

Looking forward to see this thread expand.
WetCode wrote:
I had the same idea, i found this as well.
Can this be a sulution to the problem?


No. If you run the program in an unsupported version of windows you will get "The procedure entry point XXX cannot be found in DLL" error message and it will not run at all.

In this case is is 100% an error in application code.
Install a debugger and see exactly where the application crashes.
@ modoran: That depends on the DLL doesn't it? I had a similar issue to the one OP is describing when I updated MingW. Now if I try to run one of my older binary's without recompiling it the application will crash because it was linked against an older version of "libstdc++-6.dll".
@modoran: Am not following are you saying I have a error in my code.
Preventing the application from running on XP but stile running on Win 8?
@ Wetcode: You didn't by chance compile a 64-bit binary that you are trying to run on a 32-bit OS right?
@Computergeek01: No I did check that btw I will try the the tips from OrionMaster compiling on WIndows 7. But I would like to learn how to solve a issue like this. So I will continue researching the subject. Also I try using the XP (v110_xp) platform toolset in VS 2012 but that failed as well.
I try compiling under WIndows 7 and it stile don`t work.
Can the Function GetProcAddress() or GetModuleHandle() be different in WIndows XP?
Am getting this message in Dependency Walker.
 

00:00:00.140: GetProcAddress(0x7C800000 [c:\windows\system32\KERNEL32.DLL], "FlsAlloc") 
called from "c:\..\OFFICE BOX.EXE" at address 0x004040CE and returned NULL by thread 1. 
Error: The specified procedure could not be found (127).

00:00:00.140: GetProcAddress(0x7C800000 [c:\windows\system32\KERNEL32.DLL], "FlsGetValue") 
called from "c:\..\OFFICE BOX.EXE" at address 0x004040DB and returned NULL by thread 1.
Error: The specified procedure could not be found (127).

00:00:00.156: GetProcAddress(0x7C800000 [c:\windows\system32\KERNEL32.DLL], "FlsSetValue") 
called from "c:\..\OFFICE BOX.EXE" at address 0x004040E8 and returned NULL by thread 1. 
Error: The specified procedure could not be found (127).

00:00:00.156: GetProcAddress(0x7C800000 [c:\windows\system32\KERNEL32.DLL], "FlsFree") 
called from "c:\..\OFFICE BOX.EXE" at address 0x004040F5 and returned NULL by thread 1. 
Error: The specified procedure could not be found (127).

GetProcAddress(0x7C900000 [c:\windows\system32\NTDLL.DLL], 0x00000000) 
called from "c:\..\OFFICE BOX.EXE" at address 0x0040203D and returned NULL by thread 1. 
Error: The parameter is incorrect (87).

Last edited on
If GetProcAddress returns NULL then obviously the application is crashing. What function are you trying to invoke this way ?

The specified procedure could not be found

You should be prepared for this case in your code.
You are so right I should be but if GetProcAddress returns NULL,
That means it can't find the function in the DLL if am not mistaken?

But that don't explain the 4 functions FlsAlloc, FlsGetValue, FlsSetValue, FlsFree.
I never call then in my code only GetProcAddress.
Ok I solved the problem on way its crashing turns out that modoran was very much right on the spot.
I had a error in my code where I was delivering a empty char array instead of the Function name string it was supposed to get. Thank you so much for your help even thou the problem was less complex then first thought.

Its worth mentioning that am now compiling on WIndows 7 as well, but it was definitely the empty char* that made it crasher. But I will not try compiling on WIndows 8 again I will update the results later

Just shows how bad error handling on my part can lead to "extra" debugging.

Thanks again.
Last edited on
Topic archived. No new replies allowed.