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 3611940
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:56:15+00:00 2026-05-18T21:56:15+00:00

Problem I have been trying all sorts of byte counts trying to get WriteFile

  • 0

Problem

I have been trying all sorts of byte counts trying to get WriteFile to work. The problem is it immediately crashes after writing to the file. All the text is in the file but yet the “A program has crashed, send to Microsoft??” Error Dialog pops up.

When commenting out invoke WriteFile and everything below it, the program runs fine and does not crash. However when I just uncomment WriteFile and leave all the code below it commented out it again rears it’s ugly head. The code is below and if anybody can see something that I missed it is much appreciated 🙂

Byte Lengths I have tried.

I have tried byte lengths of 23, 24 (string length + null), 25 (Maybe I forgot a byte), and also just using SIZEOF WriteText and all of them failed :-(.

Code

.386 
.model flat,stdcall 
option casemap:none ; Case Sensitive

; Windows
include \masm32\include\windows.inc 

; Kernel32
include \masm32\include\kernel32.inc 
includelib \masm32\lib\kernel32.lib 

.data 
FilePath         db "C:\test.txt",0
WriteText        db "This is some test text."

.code 
start: 

; Edit a file

invoke CreateFile, addr FilePath, GENERIC_WRITE, FILE_SHARE_WRITE or FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
push eax ; save the file handle

; This works other than the crashing, any number less then 23
; and the file has some of the text clipped
; any larger and NUL is appended until the byte count is matched.
invoke WriteFile, eax, addr WriteText, 23, NULL, NULL

pop eax
push eax

invoke CloseHandle, eax

invoke ExitProcess, 0
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-05-18T21:56:15+00:00Added an answer on May 18, 2026 at 9:56 pm

    According to the documentation for the WriteFile function:

    lpNumberOfBytesWritten [out, optional]
    […]
    This parameter can be NULL only when the lpOverlapped parameter is not NULL.

    You have both lpNumberOfBytesWritten and lpOverlapped as NULL. Pass addr some_writable_variable as lpNumberOfBytesWritten and it should work.

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

Sidebar

Related Questions

I have been trying to tackle this problem , but I am having difficulty
I have been having some problems trying to get my PHP running. When I
I am given a problem where I have been given N nodes in a
Solution to original problem (below) may have been discovered. I commented out <identity> ...
This is a really weird problem that I have been having. When I download
I have been puzzling over a problem this morning with LinqToSQL. I'll try and
We have recently been faced with the problem of porting our C++ framework to
Problem: I have an address field from an Access database which has been converted
I have a tricky problem that I've been messing about with for a few
I've been thinking about this problem for a while and have yet to come

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.