Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Please Help!! File Transfer!!!

Please Help!! File Transfer!!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++lounge
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pett
    wrote on last edited by
    #1

    Hi, I posted this before, but no one responded. :(( I'm new to C ++/mfc and I'm trying to modify a chat program to have the capability to transfer files as well as messages. I found help from with code to send the file from this forum, but when I implemented it, I keep getting an error, "Unknown error while accessing unnamed file". I put a button on the client side, and when the person clicks on it, the file dialog box is supposed to open, and the person can choose the file to send. I get the dialog box, but I get the error right after I choose the file. I put messages throughout the code to see where the program has reached, and it seems to be going through fine! It's also reading the data! I'm really confused!! :confused::confused::confused: I'm pasting the code below. If anyone has any idea what I'm doing wrong please respond. :((:((:(( ------------------------------------------------- void CMainFrame::OnSFile() { MessageBox("File Transfer"); CSocket cSocket; cSocket.Create(); cSocket.Connect((LPCTSTR(m_strServerIP)),m_iFTPort); csocketfile sf(&cSocket); CArchive ar(&sf, CArchive::store); /*code for CFileDialog goes here*/ static char BASED_CODE szFilter[] = "All Files (*.*)|*.*||"; CString strPath; CFileDialog m_ldFile(TRUE,".*","*.*",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter); // Initialize the starting directory //m_ldFile.m_ofn.lpstrInitialDir = _T("C:\\"); // Show the file open dialog and captures the result //if IDOK if (m_ldFile.DoModal() == IDOK) { strPath = m_ldFile.GetPathName(); CFile myFile(strPath, CFile::modeRead | CFile::typeBinary); MessageBox("here"); //get file info DWORD length = myFile.GetLength(); MessageBox("here2"); char *data = new char[length]; MessageBox("here3"); myFile.Read(data, length); MessageBox("here4"); //send it across ar << myFile.GetFileName(); ar << length; ar.Write(data, length); delete[] data; myFile.Close(); } MessageBox("here5"); } ----------------------------------------------------------------

    C 1 Reply Last reply
    0
    • P Pett

      Hi, I posted this before, but no one responded. :(( I'm new to C ++/mfc and I'm trying to modify a chat program to have the capability to transfer files as well as messages. I found help from with code to send the file from this forum, but when I implemented it, I keep getting an error, "Unknown error while accessing unnamed file". I put a button on the client side, and when the person clicks on it, the file dialog box is supposed to open, and the person can choose the file to send. I get the dialog box, but I get the error right after I choose the file. I put messages throughout the code to see where the program has reached, and it seems to be going through fine! It's also reading the data! I'm really confused!! :confused::confused::confused: I'm pasting the code below. If anyone has any idea what I'm doing wrong please respond. :((:((:(( ------------------------------------------------- void CMainFrame::OnSFile() { MessageBox("File Transfer"); CSocket cSocket; cSocket.Create(); cSocket.Connect((LPCTSTR(m_strServerIP)),m_iFTPort); csocketfile sf(&cSocket); CArchive ar(&sf, CArchive::store); /*code for CFileDialog goes here*/ static char BASED_CODE szFilter[] = "All Files (*.*)|*.*||"; CString strPath; CFileDialog m_ldFile(TRUE,".*","*.*",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter); // Initialize the starting directory //m_ldFile.m_ofn.lpstrInitialDir = _T("C:\\"); // Show the file open dialog and captures the result //if IDOK if (m_ldFile.DoModal() == IDOK) { strPath = m_ldFile.GetPathName(); CFile myFile(strPath, CFile::modeRead | CFile::typeBinary); MessageBox("here"); //get file info DWORD length = myFile.GetLength(); MessageBox("here2"); char *data = new char[length]; MessageBox("here3"); myFile.Read(data, length); MessageBox("here4"); //send it across ar << myFile.GetFileName(); ar << length; ar.Write(data, length); delete[] data; myFile.Close(); } MessageBox("here5"); } ----------------------------------------------------------------

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Pett wrote: I'm new to C ++/mfc and I'm trying to modify a chat program to have the capability to transfer files as well as messages. If you're really new to C++, you need to forget MFC and Windows, and do some console programming until you've had a chance to learn the core language properly. Do you know how to use the debugger ? Do you know what line is breaking ? Do you know if you have a connection first ? Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

      P 1 Reply Last reply
      0
      • C Christian Graus

        Pett wrote: I'm new to C ++/mfc and I'm trying to modify a chat program to have the capability to transfer files as well as messages. If you're really new to C++, you need to forget MFC and Windows, and do some console programming until you've had a chance to learn the core language properly. Do you know how to use the debugger ? Do you know what line is breaking ? Do you know if you have a connection first ? Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

        P Offline
        P Offline
        Pett
        wrote on last edited by
        #3

        Thank you for responding. :) I actually have to do this for an assignment in one of my MSc classes.. Networking. So, I have no choice but to dive into everything at once.. Also, I have tried putting messages in the code to see if the program is actually reaching that part of the code... and it goes through fine... then I get the error. I'm not sure if I'm using debugger properly, but I put a break point at several places, and it went through again... then the error. I showed this to my professor yesterday, and he said it was puzzeling as well. You asked if I had a connection. You mean to the server right? Yes I do... If I am sending a file, but there is no receiving code on the server side, what will happen? I'm wondering now if it is my sending that is the problem. Maybe I'm not doing something with CArchive...:confused: Thanks a lot for your input.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups