NO

Author Topic: Converting 32 bit code to 64 bit code  (Read 5272 times)

Offline John Z

  • Member
  • *
  • Posts: 860
Converting 32 bit code to 64 bit code
« on: November 19, 2023, 01:04:28 PM »
Here is a nice summary about things to consider and do to convert 32 bit into 64 bit code.
It is from Oracle, June 2016 - yes I know I'm way behind  :) :) :)

John Z

Offline Vortex

  • Member
  • *
  • Posts: 864
    • http://www.vortex.masmcode.com
Re: Converting 32 bit code to 64 bit code
« Reply #1 on: November 19, 2023, 01:13:10 PM »
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Converting 32 bit code to 64 bit code
« Reply #2 on: December 17, 2023, 12:52:36 PM »
When upgrading another program to 64 bit I ran into this -
strlen() in 32 bit returns size_t which seems to be DWORD
strlen() in 64 bit returns size_t which seems to be unsigned long long int

so far so good - however in fileapi.h the WriteFile function
WINBASEAPI BOOL WINAPI WriteFile(HANDLE, LPCVOID, DWORD, LPDWORD, LPOVERLAPPED);
doesn't change parm 3 so when compiling for 64 bits you get
Log_To_File.c(101): warning #2215: Conversion from 'unsigned long long int' to 'unsigned long int'; possible loss of data or unexpected result.

The only way I can see is either suppress the #2215 warning or cast (DWORD)strlen()

Doesn't seem to be a WriteFile64 .... and WriteFile is not marked as depreciated..

Thoughts?

John Z

So far upgrading from my old 32 bit programs to 64 bit has been relatively simple.  Benefit is questionable other than future proofing against 32 bit support disappearing.

Offline WiiLF23

  • Member
  • *
  • Posts: 89
Re: Converting 32 bit code to 64 bit code
« Reply #3 on: December 18, 2023, 01:14:23 AM »
"If your application needs to handle large files and you want to work with 64-bit sizes, you might consider using the WriteFileEx function, which has a different signature that includes a LARGE_INTEGER parameter for the file offset. This function is designed to work with large files on 64-bit systems."

Code: [Select]
WINBASEAPI BOOL WINAPI WriteFileEx(
    HANDLE hFile,
    LPCVOID lpBuffer,
    DWORD nNumberOfBytesToWrite,
    LPOVERLAPPED lpOverlapped,
    LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Converting 32 bit code to 64 bit code
« Reply #4 on: December 18, 2023, 10:32:21 AM »
Thanks WiiLF23,

Appreciate the input - I did look at that and it seems overly complex for the simple log file entry.

There are other file methods of course, and it is just a warning, but to me it points out that 64 bit seems to not be fully implemented across the winbaseapi by Microsoft.

John Z

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Converting 32 bit code to 64 bit code
« Reply #5 on: December 18, 2023, 04:50:33 PM »
When upgrading another program to 64 bit I ran into this -
strlen() in 32 bit returns size_t which seems to be DWORD
Yes because a DWORD can cover a string long the whole addressing space 32bits => 4Gb.
strlen() in 64 bit returns size_t which seems to be unsigned long long int
Once again address whole memory 64bits => 16 exibytes (18'446'744'073'709'551'616 bytes)
so far so good - however in fileapi.h the WriteFile function
WINBASEAPI BOOL WINAPI WriteFile(HANDLE, LPCVOID, DWORD, LPDWORD, LPOVERLAPPED);
doesn't change parm 3 so when compiling for 64 bits you get
Log_To_File.c(101): warning #2215: Conversion from 'unsigned long long int' to 'unsigned long int'; possible loss of data or unexpected result.
Yes there could be a loss of data if your record is bigger than 4Gb. Indeed you need to write so much data?
The only way I can see is either suppress the #2215 warning or cast (DWORD)strlen()
The cast doesn't harm in 32 or 64bits. Unless you have to write more than 4Gb in one write...
Doesn't seem to be a WriteFile64 .... and WriteFile is not marked as depreciated..
Thoughts?
Probably if you need to transfer such big amount of data, an operation that will take time anyway despite how fast is your disk, you'll not use this simple technique. So don't seems to be a really need for WriteFile64...
To keep contained buffers extensions and manage the update of transfer data more appropriately you'll use an asynchronous transfer, overlapped, to keep running code and updating transfer buffers on the fly.

Do you really need to transfer more than 4Gb at once?   ;)
« Last Edit: December 18, 2023, 06:21:33 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Converting 32 bit code to 64 bit code
« Reply #6 on: December 18, 2023, 10:40:15 PM »
In the spirit in which the thoughts were given, I thank you frankie!  ;)

No, of course not, I do not have even a minuscule fraction of 4Gb to deal with.

John Z