Error messages

This is a discussion on Error messages within the Windows Programming forums, part of the Platform Specific Boards category; This is a part of my code: Code: void openfile(void *P){ GetWindowText(dropdown,tfile,260); file=FtpOpenFile(say,tfile,GENERIC_READ,FTP_TRANSFER_TYPE_ASCII,0); InternetReadFile(file,file_contents,100000,&car); InternetCloseHandle(file); add=file_contents; std::string::size_type pos = -1; ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Error messages

    This is a part of my code:
    Code:
    void openfile(void *P){
        GetWindowText(dropdown,tfile,260);
        file=FtpOpenFile(say,tfile,GENERIC_READ,FTP_TRANSFER_TYPE_ASCII,0);
        InternetReadFile(file,file_contents,100000,&car);
        InternetCloseHandle(file);
        add=file_contents;
        std::string::size_type pos = -1;
        while((pos=add.find("\n",pos+1))!=std::string::npos){ 
        add.replace(pos,1,"\r\n");
        }
        *(std::copy(add.begin(), add.end() - add.begin() < 256 ? add.end() : add.begin() + 255, file_contents)) = 0;
        SetWindowText(edit,file_contents);
        return;
    }
    And when this runs I always get illegal operation message or "abnormal program termination" message.

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    try to run in debug mode and see what line fails

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I can't use Dev-C++ debug, because I always get BSOD then.
    But I think it's about the "add.replace..." line, because when I change the 1 to 2, I don't get any errors, but the text is totally messed up(the first '\n' keep repeating).
    I think you understand what I am trying to do and maybe you can give me an alternative way to do the same thing.

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I think your problem is that the indexes get thrown off since you are adding another character to the string each iteration. Try increasing pos by 1 at the end of the loop.

    Also, you can see if string is throwing any errors:
    Code:
    try
    {
    openfile();
    }
    catch (std::exception& error)
    {
      MessageBox(NULL,error.what(),"Caugh Exception:",MB_OK);
    }
    Gotta run
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    try changing
    Code:
    add.find("\n",pos+1)
    to
    Code:
    add.find("\n",pos+2)
    you keep removing "\n" at pos n, then you add "\r\n" at pos n, then you check again for "\n" at pos n+1 which is where the \n in the \r\n is.

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Thanks, I didn't really need to use replace in my code...

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21