Click here to Skip to main content
15,889,909 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: EditBox with focus but no cursor Pin
BadJerry8-Dec-08 1:25
BadJerry8-Dec-08 1:25 
GeneralRe: EditBox with focus but no cursor Pin
Code-o-mat8-Dec-08 1:35
Code-o-mat8-Dec-08 1:35 
QuestionRe: EditBox with focus but no cursor Pin
bob169728-Dec-08 1:52
bob169728-Dec-08 1:52 
AnswerRe: EditBox with focus but no cursor Pin
BadJerry8-Dec-08 1:57
BadJerry8-Dec-08 1:57 
GeneralRe: EditBox with focus but no cursor Pin
bob169728-Dec-08 3:41
bob169728-Dec-08 3:41 
GeneralRe: EditBox with focus but no cursor Pin
BadJerry8-Dec-08 3:43
BadJerry8-Dec-08 3:43 
QuestionNeed help on WinCE remote database connection Pin
sribachana7-Dec-08 23:29
sribachana7-Dec-08 23:29 
QuestionFollowing code unable to write/upload file on a HTTP Server Pin
Dhiraj kumar Saini7-Dec-08 23:25
Dhiraj kumar Saini7-Dec-08 23:25 
My following code is unable to upload/write file on the server.
Please tell me whats wrong or how can i upload it in a different way on an HTTP Server.
I am using MFC.


INTERNET_BUFFERS BufferIn = {0};
	DWORD dwBytesRead;
	DWORD dwBytesWritten;
	BYTE pBuffer[1024]; // Read from file in 1K chunks
	BOOL bRead, bRet;
	HANDLE hFile;




	HINTERNET hSession = InternetOpen(NULL,
                                      INTERNET_OPEN_TYPE_PRECONFIG,
                                      NULL,
                                      NULL,
                                      0);
    HINTERNET hConnection = InternetConnect(hSession, 
                                            _T("www.crmpanel.com"),  // Server
                                            INTERNET_DEFAULT_HTTP_PORT,
                                            NULL,     // Username
                                            NULL,     // Password
                                            INTERNET_SERVICE_HTTP,
                                            0,        // Synchronous
                                            NULL);    // No Context


	

     BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );

     HINTERNET hRequest = HttpOpenRequest(hConnection,
											_T("PUT"),
											_T("cp3/wn_fupload-oo.php"),
											NULL,
											NULL,
											NULL,
											0,
											0);
     if (!hRequest)
     {
       //printf("Failed to open request handle: %lu\n", GetLastError ());
		 MessageBox(_T("Failed to open request handle:"),NULL,MB_OK);
       return ;
     }

	//HttpAddRequestHeaders(hRequest, _T("Content-Type: multipart/form-data;sid=52501;"), -1, HTTP_ADDREQ_FLAG_ADD);




	 hFile = CreateFile (_T("c:\\Image1.gif"),
						GENERIC_READ,
						FILE_SHARE_READ,
						NULL,
						OPEN_EXISTING,
						FILE_ATTRIBUTE_NORMAL,
						NULL);

     if (hFile == INVALID_HANDLE_VALUE)
     {
       //printf("\nFailed to open local file.");
	    MessageBox(_T("Failed to open local file"),NULL,MB_OK);
       return ;
     }



     BufferIn.dwBufferTotal = GetFileSize(hFile, NULL);
	 MessageBox(_T("File size is"),NULL,MB_OK);
     //printf ("File size is %d\n");//, BufferIn.dwBufferTotal );

	// CString h = _T("Content-Type: multipart/form-data");
	
	//CString s = _T("filename=Iamge1.xml&filetype=gif&filesize=70204&sid=52501&csesid=111");

	//BOOL bo = HttpSendRequest(hRequest,(LPCTSTR)&h, h.GetLength(),(LPVOID)&s ,s.GetLength());



	 

     if(!HttpSendRequestEx(hRequest, &BufferIn, NULL, HSR_INITIATE, 0))
     {
		 MessageBox(_T("Error on HttpSendRequestEx"),NULL,MB_OK);
		 DWORD err = GetLastError();
		//printf( "Error on HttpSendRequestEx %lu\n");//,GetLastError() );
       return ;
     }
	 


     DWORD sum = 0;
     do
     {
       if  (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer),
           &dwBytesRead, NULL)))
       {
		 MessageBox(_T("ReadFile failed on buffer"),NULL,MB_OK);
         //printf ("\nReadFile failed on buffer %lu.");//,GetLastError());
         break;
       }
       if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
           &dwBytesWritten)))
       {
		 MessageBox(_T("InternetWriteFile failed"),NULL,MB_OK);
         //printf ("\nInternetWriteFile failed %lu");//, GetLastError());
         break;
       }
       sum += dwBytesWritten;
     }
     while (dwBytesRead == sizeof(pBuffer)) ;

     CloseHandle (hFile);
	 MessageBox(_T("Actual written bytes:"),NULL,MB_OK);
     //printf ("Actual written bytes: %d\n");//, sum);

     if(!HttpEndRequest(hRequest, NULL, 0, 0))
     {
	   MessageBox(_T("Error on HttpEndRequest"),NULL,MB_OK);
       //printf( "Error on HttpEndRequest %lu \n");//, GetLastError());
       return ;
     }


Thanks in Advance

Dhiraj
QuestionRe: Following code unable to write/upload file on a HTTP Server Pin
David Crow8-Dec-08 3:07
David Crow8-Dec-08 3:07 
QuestionHow to change the appearence of mouse pointer to sand Time Pin
kapardhi7-Dec-08 23:03
kapardhi7-Dec-08 23:03 
AnswerRe: How to change the appearence of mouse pointer to sand Time Pin
Code-o-mat7-Dec-08 23:14
Code-o-mat7-Dec-08 23:14 
AnswerRe: How to change the appearence of mouse pointer to sand Time Pin
K. Sushilkumar7-Dec-08 23:15
K. Sushilkumar7-Dec-08 23:15 
AnswerRe: How to change the appearence of mouse pointer to sand Time Pin
Stuart Dootson7-Dec-08 23:17
professionalStuart Dootson7-Dec-08 23:17 
AnswerRe: How to change the appearence of mouse pointer to sand Time Pin
Chandrasekharan P7-Dec-08 23:20
Chandrasekharan P7-Dec-08 23:20 
AnswerRe: How to change the appearence of mouse pointer to sand Time Pin
Iain Clarke, Warrior Programmer8-Dec-08 0:32
Iain Clarke, Warrior Programmer8-Dec-08 0:32 
AnswerRe: How to change the appearence of mouse pointer to sand Time Pin
David Crow8-Dec-08 3:10
David Crow8-Dec-08 3:10 
QuestionMicrosoft Enhanced Cryptographic Provider question Pin
monsieur_jj7-Dec-08 23:02
monsieur_jj7-Dec-08 23:02 
AnswerRe: Microsoft Enhanced Cryptographic Provider question Pin
Chris Losinger8-Dec-08 1:14
professionalChris Losinger8-Dec-08 1:14 
QuestionHow to link the edit box and spin control Pin
Member 46517417-Dec-08 22:19
Member 46517417-Dec-08 22:19 
AnswerRe: How to link the edit box and spin control Pin
Rajesh R Subramanian7-Dec-08 22:36
professionalRajesh R Subramanian7-Dec-08 22:36 
AnswerRe: How to link the edit box and spin control Pin
Code-o-mat7-Dec-08 22:42
Code-o-mat7-Dec-08 22:42 
GeneralRe: How to link the edit box and spin control Pin
Member 46517417-Dec-08 23:03
Member 46517417-Dec-08 23:03 
GeneralRe: How to link the edit box and spin control [modified] Pin
Code-o-mat7-Dec-08 23:12
Code-o-mat7-Dec-08 23:12 
GeneralRe: How to link the edit box and spin control Pin
Member 46517417-Dec-08 23:33
Member 46517417-Dec-08 23:33 
GeneralRe: How to link the edit box and spin control Pin
Code-o-mat7-Dec-08 23:37
Code-o-mat7-Dec-08 23:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.