window has to close error

This is a discussion on window has to close error within the C++ Programming forums, part of the General Programming Boards category; I get a windows error message saying the proces has to end with this code: Code: void SendFile() { /* ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    window has to close error

    I get a windows error message saying the proces has to end with this code:

    Code:
    void SendFile()
    {
    	/*
    	LPOVERLAPPED overlapped;
    	overlapped->Offset = 0;
    	*/
    	LPTRANSMIT_FILE_BUFFERS buffers;
    	buffers->Head = "File";
    	buffers->HeadLength = sizeof("File");
    	MessageBox(NULL, "sdfds", "sdfsd", MB_OK);
    	
    	HANDLE file = CreateFile("C:/Documents and Settings/Alex/Desktop/Lake.zip", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
    	
    	if (file == INVALID_HANDLE_VALUE)
    	{
    		ApendText(textbox_status, "Error opening file");
    		ApendText(textbox_status, GetLastError());
    	}
    
    	if (TransmitFile(main_socket, file, NULL, NULL, NULL/*overlapped*/, buffers, NULL))
    	{
    		ApendText(textbox_status, "Transmiting file");
    	}
    	else
    	{
    		ApendText(textbox_status, "Error transmiting file");
    		ApendText(textbox_status, WSAGetLastError());
    	}
    }
    I figured out the error is when I declare LPTRANSMIT_FILE_BUFFERS buffers and try to fill it. I'm completely loss on how this is done, if I use . instead of-> I get error during compilertion.

    If you need more info please ask.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Generally, when windows functions want a pointer as a parameter, you pass a reference to an object. So instead of using a pointer:
    Code:
    TRANSMIT_FILE_BUFFERS buffers;
    buffers.Head = "File";
    buffers.HeadLength = sizeof("File");
    //...
    TransmitFile(main_socket, file, NULL, NULL, NULL/*overlapped*/, &buffers, NULL)
    I can't guaruntee the rest of your code is right, though (never used TransmitFile)
    "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

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    You could also allocate memory for your LPTRANSMIT_FILE_BUFFERS. This way, it points to availible space, which you can then assign to the appropriate variables. Then you just pass the pointer. This is an unecessary wierd way however. It's probably better just creating the regular local variable, and then passing the reference as JaWiB said.

    Code:
    	LPTRANSMIT_FILE_BUFFERS buffers = new TRANSMIT_FILE_BUFFERS;
    
    	buffers->...
    	buffers->...
    
    	...
    
    	TransmitFile(.., buffers, ...)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

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