Developing a driver for several Windows versions (xp, win7, vista) - visual-studio-2010

We are developing a DLL, which calls generic WinUsb functions from WinDDK. This DLL needs to work in 32-bit and 64-bit versions of Windows, including xp, vista, win7, and possibly win8.
My question is, how can we manage the Visual Studio 2010 solution by targeting all these platforms? WinDDK libraries are different for each OS, so if I reference a library from the code:
#### #pragma comment (lib , "C:\\WinDDK\\7600.16385.1\\lib\\wlh\\i386\\winmm.lib" )
Or by referencing the library from the project options->includes section, this project only becomes correct for a particular target architecture. (In this example, Vista 32-bits, since I am including 'wlh').
Are we supposed to create a different project for each different OS target?

The WDK/DDK version does not constrain the OS version for which you build. You can pass the target OS as a build environment/compile parameter.

I think you should build DLL through DDK and use that in your VS project.
You can write pre-build event for your VS project to run a batch file which will build the DLL and put it in some well-known place for the project.
Also, you may have to create different project configurations for each platform you want to build for (at least different for 32-bit and 64-bit) and run appropriate build command for DLL.

Related

Rust - How to remove the dependency on ucrtbase.dll?

When compiling my Rust app in Windows 10, it is linked against ucrtbase.dll; however, this dll does not exist on some editions of Windows Server 2008 R2 Datacenter, making my app impossible to execute.
I tried setting -Ctarget-feature=+crt-static as found here, but it did not do anything; ldd app.exe still shows this dll.
Is there a way of removing the dependency on this dll?
If your Rust app does not depend on C libraries that specifically require the MSVC toolchain, you can build it for the x86_64-pc-windows-gnu (or i686-pc-windows-gnu, to build for 32-bit CPUs) target instead. This target links to DLLs that are available in all Windows versions.
For more information about the different Windows ABIs, you can check out this documentation page.

Directing an application to find a DLL in a specific location

I'm working with a native C++/Win32/MFC application built using Visual Studio 2010 Pro on Windows 7 x64. The application is linked with some other DLLs using their .lib files.
I'd like to be able to run this application and have it find the DLLs in their respective directories without 1) having to put the DLLs in the application directory or 2) add the DLL directories to the PATH or 3) resort to dynamically loading the DLLs and having to lookup stuff at runtime.
Is this even possible? Is there some way to direct the OS loader to go find the DLLs in an arbitrary location I specify without having to add that to the PATH?
Basics:
In Visual Studio project settings, keep everything default specially in Release configuration.
Ensure that you give Release build to the client (Where VS wouldn't have been installed).
If client OS is 32-bit, you must give 32-bit. Otherwise you can give 64-bit (Release build in any case).
Now comes distribution and VC++ runtime library.
You must install appropriate Visual C++ Runtime on client's machine,
ensuring that:
The version should match (VC7, VC8,.. VC14 etc.)
The bit-ness should match. If your application is 32-bit, you need 32-bit
redistributable, and same for x64.
The service pack version must also
match!
It should be noted that all of them can co-exist! VC10 RTM, VC10 SP2, VC10 x64 RTM.. all can co-exist

Native x64 dll does not work

I have an application that I compile as x86 code but as a separate version, as x64 code as well. The application basically has two parts, a c# managed exe and a c++ unmanaged dll. I have problems with the latter. On my development PC (Windows 7 64-bit, Visual Studio 2008) I create a setup with a deployment project and this setup installs the application in Program Files... as it should and the application runs. I also have a test PC (Windows 7 64-bit with practically nothing else). There the application still installs into Program Files... but it does not run, I get the BadImageFormatException when a function (any function) of the unmanaged dll is called. The problem is that my own project that produces the dll also makes use of quite a few freely available libraries (e.g. glew32, openal, freeimage, etc.) I took as much care is possible to make sure that I use the x64 versions of these libraries, but something still must be wrong. For some reason one of the libraries used by my dll is not available as x64 code on the test PC but it is on the development PC. At least that is the only explanation I have at the moment why my setup works on the development PC but not on the test PC.
My question is: how can I find out where the problem is. The error message I receive does not tell any helpful detail. I tried to analyze my dll with depends but it looks OK. It lists a lot of dependent libraries as X86 (these are probably system files) but all those that I use on purpose are listed as x64.
Is there any way to test why the Windows on my test PC tries to run the DLL as x86 code even though it should be x64?
Thanks.
I noticed something very strange: My application is being deployed in the Program Files folder as it should be for a x64 application but it fails to run. However if I copy all the files in the folder it is installed to to another folder (inside the Documents folder) the application runs perfectly.
Run Fusion Log Viewer in the machine where you want to diagnose the issue. Look carefully at the logs and you'll see exactly which dlls are being loaded, and where from.
You have build your .NET executable (or DLL) with Any CPU configuration, and you have given x64/Win32 native DLL for Win32/x64 (i.e. wrong config).
On x64 systems, your .NET binary will try to load the native DLL as if native DLL is x64.
And on 32-bit systems, it will try to load 32-bit native DLL.
I found the answer. The problem was not the 64-bit dll at all. One of the libraries I did not make but I link to (I do not know which yet, there) seems to try to write a file to the application folder. Of course, this is not allowed inside the Program Files folder unless you run the application as an administrator. Sorry for asking help for the wrong question.

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.

Install different version of merge module depending on processor architecture

I have a Windows .net solution that is deployed with a Visual Studio Deployment project.
My exe is a win32 app that runs fine on either a x86 or x64 windows.
However I included a merge module (*.msm) from a third party vendor which is available in a x86 and x64 version.
Now I could copy my whole deploy project and just change the msm, but I'm a lazy guy and the best thing would be to include both msm's in my installer and only install the module which fits the processor of the client machine.
Is there a way to do this with Visual Deployment projects?
Merge Modules seem to lack a Condition property like included exe / dll files have.

Resources