Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8420705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:56:07+00:00 2026-06-10T02:56:07+00:00

I came across a strange problem with ReadFile(). The textfile is opened correctly but

  • 0

I came across a strange problem with ReadFile(). The textfile is opened correctly but it reads only 4 bytes instead of number of bytes declared in MemorySize. The same code in C is executed properly. Somebody knows what’s wrong?

Regards

.DATA
FileName DB "test.txt",0
MemorySize  DWORD 10

.DATA?
hFile    HANDLE ?
pMemory  DWORD  ?
SizeR    DWORD  ?

.CODE
start:

INVOKE CreateFile, ADDR FileName,\ 
    GENERIC_READ, 0, NULL,\
    OPEN_EXISTING, 0, NULL
mov hFile, eax
INVOKE GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, MemorySize+1
mov pMemory, eax
INVOKE ReadFile, hFile, ADDR pMemory, MemorySize, ADDR SizeR, NULL
INVOKE MessageBox, 0, ADDR pMemory, 0, 0
INVOKE LocalFree, pMemory
INVOKE CloseHandle, hFile
ret
end start
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:56:09+00:00Added an answer on June 10, 2026 at 2:56 am
    INVOKE ReadFile, hFile, ADDR pMemory, MemorySize, ADDR SizeR, NULL
    INVOKE MessageBox, 0, ADDR pMemory, 0, 0
    

    In these two lines, you are passing a pointer to a pointer for pMemory. GlobalAlloc returns a pointer to memory and ReadFile expects a pointer NOT a pointer to a pointer. Remove ADDR and it should work.

    INVOKE GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, MemorySize+1
    

    This is wrong also. You cannot do MemorySize + 1 as you would to in a High Level Language. In this case you need to do:

    inc     MemorySize
    

    before your call to GlobalAlloc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across a strange problem today. I created a subclass of UIView and
recently i came across strange problem while uploading files to my new server. I
I came across a strange problem with html anchor tags. I have an anchor
Today, I came across quite strange problem. I needed to calculate string length of
I came across a rather strange problem with linq-to-sql. In the following example, var
I came across a strange problem with encryption/decryption in PHP. Look at the code
I came across a strange problem today that i could understand the reason. Take
I came across a strange problem today where an anchor appears to merge (for
I came accross a very strange problem with tr1::regex (VS2008) that I can't figure
I came across a strange behavior while theming Drupal. I turned a few modules

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.