VC++6 Writefile return 0 bytes written in Windows 7
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: VC++6 Writefile return 0 bytes written in Windows 7

Hybrid View

  1. #1
    Join Date
    Jan 2012
    Posts
    1

    Smile VC++6 Writefile return 0 bytes written in Windows 7

    Hi,
    Part of the codes in my application use Writefile to write to a disk partition. It works in XP but not in Windows 7. The value of TempPos is zero after written. What is wrong? Will there be file access rights problem? Thanks


    __int64 Tmp64 = (((__int64) DriveInfo->NTRelativeSector) + ((__int64) DriveInfo->RelativeSector)) * 512;
    long TempPos = Tmp64 & 0xFFFFFFFF;
    long TempPosHi = (Tmp64 >> 32);
    SetFilePointer(MyDisk[DriveInfo->Drive], TempPos, &TempPosHi, FILE_BEGIN);
    TempPos = 0;
    WriteFile(MyDisk[DriveInfo->Drive], Buffer, DriveInfo->NumSectors * 512, (DWORD *) &TempPos, NULL);

  2. #2
    Join Date
    Aug 2002
    Posts
    581

    Re: VC++6 Writefile return 0 bytes written in Windows 7

    Hi,
    Where are you trying to write? Is it some kind of a system folder?
    Can you read file in that folder? Can you make a file in that folder?

    Thank you.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,427

    Re: VC++6 Writefile return 0 bytes written in Windows 7

    Quote Originally Posted by KevinA View Post
    Hi,
    Part of the codes in my application use Writefile to write to a disk partition. It works in XP but not in Windows 7. The value of TempPos is zero after written. What is wrong? Will there be file access rights problem? Thanks
    Your mistake is assuming that all your calls will be successful without checking them.

    Where is your check for SetFilePointer() and WriteFile() return codes? In addition, did you call GetLastError()?

    Pay attention to "Return Value" in the links below.

    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Regards,

    Paul McKenzie

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: VC++6 Writefile return 0 bytes written in Windows 7

    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center