views:

1233

answers:

2

I have a very simple DLL written in unmanaged C++ that I access from my application. I recently switch to Visual Studio 2010, and the DLL went from 55k down to 35k with no code changes, and now it will no longer load in Windows 2000. I didn't change any code or compiler settings. I have my defines setup for 0x0500, which should include Windows 2000 support. Has anyone else run into this, or have any ideas of what I can do?

+6  A: 

Visual Studio 2010 cannot build binaries that run on Windows 2000. It's actually even worse than that, they won't run on Windows XP RTM or Windows XP Service Pack 1 either. This is because VS2010's C runtime library requires the EncodePointer API which is not available until SP2. I've asked about this already and nobody has yet provided a good answer. It appears you're stuck building with VS2008 if you want to support earlier versions of Windows.

Billy ONeal
Thanks for the link, that is some unfortunate news. :(
Jon Tackabury
@Jon Tackabury: I know -- I really really would like to use `auto` :(
Billy ONeal
I just don't want to have VS 2008 and 2010 both installed. :(
Jon Tackabury
Why not? They work fine when installed side-by-side.
Paul Baker
@Paul: True, it just seems a waste to have both installed just to build 1 DLL.
Jon Tackabury
@Jon: you don't need the entire VS2008 IDE. If you have the compiler, linker, headers and libs, you can target the VS2008 C++ toolchain from within VS2010. see http://blogs.msdn.com/vcblog/archive/2009/12/08/c-native-multi-targeting.aspx and http://blogs.msdn.com/vcblog/archive/2010/03/02/visual-studio-2010-c-project-upgrade-guide.aspx
sean e
@Sean: You rock, this works perfectly. Thanks!
Jon Tackabury
+2  A: 

The solution is probably to provide EncodePointer (and DecodePointer, obviously) in a seperate lib, and link that preferentially to KERNEL32.LIB. This is a perfectly supported scenario. In the past, libs like "LIBCTINY" and "UNICOWS" have used this preferential link mechanism to add/replace selected but not all functions from another lib.

MSalters
Exactly. Unfortunatelly I did not see your answer before writing my own in the linked topic, otherwise I would not spent that much time experimenting with it. Still, as my answer contains ready to use and tested code, I hope it may be of some use - see http://stackoverflow.com/questions/2484511/can-i-use-visual-studio-2010s-c-compiler-with-visual-studio-2008s-c-runtime/3502056#3502056
Suma
One important implementation note: you do not provide the EncodePointer / DecodePointer (the functions from DLL) directly. You need to replace their import vectors, which is what is resolved when liking to .lib. They are called like _imp__FunctionName.
Suma