Windows Development: Migrating from x86 to x64

Are there any recommendations for upgrading to x64 with minimal pain?

Suppose I have my own x86 executable written in C ++. The exe works fine by itself, but there is also a dll that is located both in the previous exe and outside the x64 process. With customization like this, which parts do I need to rewrite?

I would appreciate a more general answer, or maybe a link to a link that provides some theoretical background. Thanks

+4
source share
3 answers

All in all, the approach I recommend should be the Unit Test, damn it. Create your tests so that they all go through a 32-bit implementation, and then start building and testing on 64-bit ones. It is worth paying special attention to any parts of your code where you perform one of the following actions:

  • Data flow over the network (especially for types such as size_t , which will now be of a different size. Go through this code and change things like size_t and long to explicit 32 or 64-bit typedefs)
  • Loading / saving binary data to a file (ditto re: size_t / long)
  • Roll up bits with hardcoded values ​​such as 0xFFFFFFFF

Actually there are no shortcuts except to check as many code paths as you can. How easy the work will be done will depend on how portable the code was. You might be lucky ...

+5
source

This article in the SDK article lists considerations for 64-bit Windows. Specific considerations for MSVC ++ are listed here . In general, just compiling your code will save you most of the problems. I can not comment on your specific scenario, it is not detailed enough.

+3
source

I found the best way to get rid of errors is to check your code for any code that performs any of the following actions and fix it in a 32-bit world, and then start the port.

  • Uses untyped containers and castings, not the right container.
  • Uses throws for storing pointers in DWORD for any reason, usually as the final prelude for storing in a container
  • archiving casting

In cases where you really need to perform a DWORD / ptr operation, change the type to DWORD_PTR.

I saw a lot of code using CStringToPtr, not CMap <> with the corresponding types.

All these things are likely to be compiled to 64 bits (without warning due to the actor) and then fall on their face. If they used the correct types and without casting, the code would work for the first time.

Also check for any subclass code that WndProc sets - to set this parameter on 64-bit Windows, you need a different flag.

If you use MFC, you will also (uselessly) find that container sizes now return 64 bits instead of 32 bits, which means that your 32-bit / 64-bit archiving will be violated. You will have to do this when you go. We created our own implementation of MFC with some clever tricks to allow us to de-serialize 32-bit archives on 64-bit blocks and vice versa.

+2
source

Source: https://habr.com/ru/post/1304198/


All Articles