Compilation on 64-bit system for 32 bit system - compatibility - visual-studio-2010

i have a 64-bit machine with 64-bit OS...
how can i compile programs with Visual Studio 2010 so that they work on 32-bit system
if i install 32-bit OS on my 64-bit machine than i thinks it won't be a problem

If you are talking about .NET applications simply verify that you are targeting x86 in the properties of your project (this is the default setting) or Any CPU:

This is a nice property of just-in-time compiled code. It runs just as well on a 32-bit machine (using the x86 jitter) as a 64-bit machine (x64 jitter). The only time you get in trouble is when you need to use legacy unmanaged code that's only available as 32-bit machine code. Not uncommon with old dbase providers (like Jet) and COM servers. You've got the right kind of machine to detect these problems early.
Emphasizing: you don't have a problem if the target machine is 32-bit, only if it is a 64-bit machine.

Related

How to run a 32-bit vb.net program in a 64-bit Windows 7?

I have Visual Studio 2010 in a 32-bit Windows 7. I need to compile my created vb.net program (lets call it myprogram.exe) to be able to run in a 64-bit Windows 7 environment.
I have set my VS2010 project to "Any CPU" and even so myprogram.exe doesn't run on a 64-bit Windows 7. However, it does on a 32-bit Windows 7.
Could be possible it's because I'm using System.Data.OracleClient for database connection?
Error message in 64-bit Windows 7:
"The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher"
The 64-bit Windows 7 has Framework v2 installed. I attach some picture to show that.
Supposedly, WOW64 should run automatically but will not work on all applications.
In this case, should I install on my 64-bit Windows 7 some "Windows virtual PC"?
EDIT:
My VS2010 Premium is in a 32-bit Windows7 environment, and only see "Any CPU" option available. I don't see any other one else.
Should I install in the 64-bit Windows7 PC some "32-bit virtual Windows7 "? Which one would you recommend?
If you compile your program with the target platform set to AnyCPU then, when you run you executable on a 64bit OS the JIT compiler emits code for 64bit systems and, on 32bit OS, code for 32bit systems.
From your error it is clear that something between your references is a 32bit only library and thus cannot be called from 64bit code.
You could switch back to 32bit setting the x86 target platform in your Build Configuration or try to identify the library responsible and check if a 64bit version exists.
However, if you don't have specific reasons to use AnyCPU then you could still use x86 because in some cases the performances are better than 64bit code
You could read about the PROS and CONS of AnyCPU in this a little old, but still valuable, article
Try instead setting it from "Any CPU" to "x86" to force it to run on the 32-bit architecture. The problem might be that your program is relying on DLLs that aren't supported on the 64-bit architecture.

Should I use windbg_x86 for debugging 32bit applications in 64bit windows?

I use windows 7 x64 with intel cpu. which windbg works fine and should I use for debugging x86 apps ?
and another similar question, I install windows XP x86 as vmware guest for kernel debugging.My host is x64 windows 7.which windbg should I use?, windbg x86 or x64 for kernel debugging ?
I don't want to say RTFM, but in this case that's where the answer is.
This is an extract from WinDbg help:
Host computer running a 32-bit version of Windows
If your host computer is running a 32-bit version of Windows, use the 32-bit debugging tools. (This situation applies to both x86-based and x64-based targets.)
x64-based host computer running a 64-bit version of Windows
If your host computer uses an x64-based processor and is running a 64-bit version of Windows, the following rules apply:
If you are analyzing a dump file, you can use either the 32-bit debugging tools or the 64-bit debugging tools. (It is not important whether the dump file is a user-mode dump file or a kernel-mode dump file, and it is not important whether the dump file was made on an x86-based or an x64-based platform.)
If you are performing live kernel-mode debugging, you can use either the 32-bit debugging tools or the x64 debugging tools. (This situation applies to both x86-based and x64-based targets.)
If you are debugging live user-mode code that is running on the same computer as the debugger, use the 64-bit tools for debugging 64-bit code and 32-bit code running on WOW64. To set the debugger for 32-bit or 64-bit mode, use the .effmach command.
If you are debugging live 32-bit user-mode code that is running on a separate target computer, use the 32-bit debugging tools.
It is usually best to match the debugger to the architecture of the application being debugged (sometimes even required). For debugging 32-bit applications, even on a 64-bit windows OS I would suggest the x86 version of WinDbg. I would use the x64 version of WinDbg only if I wanted to debug part of the WOW64 part of the 32-bit application, which shouldn't happen often.

What is the purpose of setting the platform target for a Visual Studio application?

For any VS project it is possible to set the platform target in the build properties of that project. You can set this to Any CPU, x86, x64 or Itanium. My question is, if I set this value to x86 does that mean I cannot run that project on a x64 machine? If so, why is this even used? Is it not better to just always use Any CPU?
if I set this value to x86 does that mean I cannot run that project on a x64 machine?
No, 32-bit applications (x86) run just fine on 64-bit Windows (x64). All 64-bit versions of Windows include a 32-bit compatibility layer called Windows on Windows 64 (WOW64). This is usually what you want, in fact, as most applications do not benefit from being complied for 64-bit.
However, compiling for 64-bit (x64) does mean that your app will not run on a 32-bit (x86) machine. You can go backwards (64-bit can run 32-bit), but you cannot go forwards (32-bit cannot run 64-bit).
Compiling for Any CPU is always an option, as you point out. That will allow the application to run as a 32-bit application (x86) on a 32-bit machine, and as a 64-bit application (x64) on a 64-bit machine. This sounds like a panacea, but there are costs. Most notably, you'll need to test your application extensively in both 32-bit and 64-bit environments, whereas if you only target 32-bit environments (including 32-bit environments on a 64-bit host), you only have to test one build. And the additional workload is rarely worth it—most business applications do not benefit from the extra memory space of a 64-bit environment, and probably end up defeating any potential gains by the increased overhead of 64-bit pointers.
Visual Studio itself is a good example of an application that is fully 32-bit. There is no 64-bit version, yet it runs fine on a 64-bit host. This blog post helps to shed some light on why the decision has been made to keep VS 32-bit. You might find the reasoning helpful in making the decision yourself.
Likewise, although Microsoft Office is now available in a 64-bit package, Microsoft is still recommending that most customers stick with the 32-bit version. There are compatibility problems with the 64-bit version, and there just isn't much benefit.
If you do not specify 32 bit platform the Microsoft application compatibility toolkit cannot determine the app is 32 bit and will not allow you to create a 32 bit solution file to allow an application to run without requiring admin credentials when user account control is turned on

C# - mixed assembly (C++/CLI, DirectX native) interplay (32/64bit)

I have a problem related to this question. Two players:
C# application
Mixed assembly used by 1)
The application has to support anything from Windows XP (32bit) to Windows 7 (32 & 64bit). The assembly is complicated in different ways. It contains managed C++/CLI code and some native C++ classes dancing with native DirectX. It also is linked to a few 32bit native dll's w/o source access (containing C++ classes with import libraries).
Things are working well in 32bit environments (XP and 7 tested) including the 32bit subsystem on Windows 7. Havoc happens, as soon as "Any CPU" is used on 64bit systems in order to build the complete solution. The 32bit assembly is unusable than - but seemingly only in debug mode ("cannot load, wrong format" etc.). It seems to work in release. A 64bit assembly build is prevented by the implicit dependencies to the mentioned 32bit third-party dll's.
Is there any way to provide a real native 64bit application able to use the assembly?
Requirement for the assembly isn't that strict. It could be both - 32 or 64bit - but as said above, should be be usable from the application one way or the other.
You are running into a rock hard limitation in the 64-bit version of Windows, a 64-bit process cannot execute any 32-bit machine code in-process. You certainly have a dependency on machine code when you use C++/CLI and work with DirectX. Although it doesn't sound like you could not execute in 64-bit mode, both C++/CLI and DirectX can be compiled/are available in 64-bit.
This then boils down to a build and deployment issue. You have to build the C++/CLI project(s) in 64-bit mode and deploy only 64-bit components on a 64-bit operating system. The main EXE must be built to AnyCPU. Similarly, on a 32-bit operating system you must build and deploy only the 32-bit compiled version. You solve the build issue by adding the x64 configuration to the solution so you build the 32-bit and 64-bit version separately. You solve the deployment issue by creating two installers.
Since you have to support a 32-bit operating system anyway, the simple solution is to change the Target platform setting on your EXE project to x86. Now everything always runs in 32-bit mode and you don't have to bother with the build and deployment headaches. The only thing you miss out on is the larger virtual memory address space that's available in the 64-bit version.
Forget about the C++/CLI project for a minute.
You have third-party 32-bit DLLs. These CANNOT load in a 64-bit process. So your main application will have to be 32-bit. This restriction has nothing to do with the C++/CLI middleman.
The only way you can make use of these DLLs from a 64-bit application is to load them in a separate (32-bit) process and marshal data back and forth.

Can I still develop 32-bit applications using a 64-bit machine?

I'm wondering if I can still develop 32-bit apps using a 64-bit machine (64-bit Windows Vista with Visual Studio 2008 SP1)? Because I am planning to buy a laptop with 64-bit Vista. Im asking just to make sure. Thanks!
64-bit Windows runs 32-bit Visual Studio just fine. Unless you specify you wish you use the x64 development tools, it will still compile 32-bit applications.
Straight from the page:
Visual Studio uses the 32-bit cross
compiler even on a Windows 64-bit
computer. You can, however, use devenv
commands to create a command line
environment to call 64-bit hosted
tools.
Further Information: http://msdn.microsoft.com/en-us/library/ms246588(VS.80).aspx
With Visual Studio you are able to target what platform. By default it will run on "Any CPU" (read 32 or 64 bit), but you can specify if you desire. Look under Project>Properties>Build and look for the "Platform Target" property.
Yes. 64-bit vista will run 32-bit executables, so if you have a 32-bit compiler, it will still work.
Within visual studio you can tell it what to compile to under the Configuration Manager - (Build Menu - Configuration manager) - this allows you to target 32 or 64 bit.
64bit of consumer hardwares is usually "amd64" architecture which can run both 32bit apps and 64bit ones natively. Windows Vista 64bit edition supports both 32bit and 64bit system libraries, so basically you can run both type of applications as well. (Note that IA-64 architecture does not allow this.)
Compiling a program in 64bit is not much related to the platform that the compiler runs. But, of course, to run and test the result binary requires the corresponding architecture.
As many mentioned above, VS2008 let you choose the target architecture, so there's no problem.
I've found that just the setup.exe created by Visual Studio 2012 Express won't work on XP, but if you go ahead load MS 4.0 .NET Framework from the Microsoft Website then the *.application will load and install without using the setup.exe at all.

Resources