2

I have an application that includes some CNG (Bcrypt.dll) code. I want to be able to build my app on windows 7 and have the bcrypt funcitonality compile and run, but I want to "skip" it if I am building on a windows XP machine (at compile time) (i want to printout "skipping encryption" or something if i compiled it under XP).

is there a way at compile time know if my machine is windows 7 or XP so it will compile the appropriate code? I don't really want to change my build target/makefile/project file based on this (I dont want to /D anything) , I want anyone who builds this to just build and it will generate whatever their computer supports...

Is this possible?

Thanks!

Daniel Scire
  • 221
  • 1
  • 9
  • 1
    Why do you want to do this? Wouldn't it be a better practice to detect at run time? That way, you compile once, and support multiple platforms. – Kyle Trauberman Mar 09 '12 at 02:55
  • Ahh this is the sort of thing `configure` scripts are useful for. – Mike Kwan Mar 09 '12 at 03:56
  • The reason i cant do it at runtime is i am statically linking bcrypt.dll which doesn't exist in windows XP.i really want to #ifdef around all bcrypt references based on being on a windows7 platform . – Daniel Scire Mar 09 '12 at 05:00
  • I am going to try dynamically loading bcrypt.dll and if it fails, using that failure to guide me through the bypassing of the missing functionality. – Daniel Scire Mar 09 '12 at 15:40
  • Related, Crypto++ has this problem too since it supports back to Windows 2000. They use CNG when `WINVER >= 0x0602` or `_WINNT_VER >= 0x0602` (Windows 8 and above). Also see [`config_os.h`](https://github.com/weidai11/cryptopp/blob/master/config_os.h). – jww Aug 19 '19 at 10:21

0 Answers0