MFC to Console.

Hello Group. I need to convert the code of WiniNet Async Demo from microsoft 
samples
from MFC to a console function..

Someone can help me with the changes..

The code is posted here

Regards

/* Microsoft Corporation Copyright 1999-2002 */

/********************************************************************

ProjectName : AsyncDemo

Purpose : This sample demonstrates how to submit two

WinInet requests, using InternentOpenUrl,

asynchronously.

Notes : This sample does not handle any authentication.

To properly handle authentication, the

functions that handle specific protocols (like

HttpOpenRequest/HttpSendRequest) would need to

be used instead of InternetOpenUrl.

Last Updated: February 2, 1998




*********************************************************************/



#include <windows.h>

#include <iostream>

#include <string.h>

#include <stdio.h>

#include <wininet.h>

#include <strsafe.h>

#include "resource.h"

//*******************************************************************

// Global Variable Declarations

//*******************************************************************

LPSTR lpszAgent = "Asynchronous WinInet Demo Program";

//root HINTERNET handle

HINTERNET hOpen;

//instance of the callback function

INTERNET_STATUS_CALLBACK iscCallback;

//structure to be passed as the dwContext value

typedef struct {

HWND hWindow; //main window handle

int nURL; //ID of the Edit Box w/ the URL

int nHeader; //ID of the Edit Box for the header info

int nResource; //ID of the Edit Box for the resource

HINTERNET hOpen; //HINTERNET handle created by InternetOpen

HINTERNET hResource; //HINTERNET handle created by InternetOpenUrl

char szMemo[512];//string to store status memo

HANDLE hThread; //thread handle

DWORD dwThreadID; //thread ID

} REQUEST_CONTEXT;



//two instances of the structure

static REQUEST_CONTEXT rcContext1, rcContext2;

HWND hButton;

//*******************************************************************

// Function Declarations

//*******************************************************************

//dialog box functions

BOOL CALLBACK AsyncURL(HWND, UINT, WPARAM, LPARAM);

//callback function

void __stdcall Juggler(HINTERNET, DWORD , DWORD , LPVOID, DWORD);

//thread function

DWORD Threader(LPVOID);

//functions

int WINAPI Dump(HWND, int, HINTERNET);

int WINAPI Header(HWND,int, int, HINTERNET);

void AsyncDirect (REQUEST_CONTEXT*, HINTERNET);







//*******************************************************************

// Main Program

//*******************************************************************

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,

LPSTR lpszArgs, int nWinMode)

{

//create the root HINTERNET handle using the systems default

//settings.

hOpen = InternetOpen(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG,

NULL, NULL, INTERNET_FLAG_ASYNC);

//check if the root HINTERNET handle has been created

if (hOpen == NULL)

{

return FALSE;

}

else

{

//sets the callback function

iscCallback = InternetSetStatusCallback(hOpen, 
(INTERNET_STATUS_CALLBACK)Juggler);

//creates the dialog box

DialogBox(hThisInst,"DB_ASYNCDEMO", HWND_DESKTOP,(DLGPROC)AsyncURL);

//closes the root HINTERNET handle

return InternetCloseHandle(hOpen);

}



}



//*******************************************************************

// Dialog Functions

//*******************************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//

//

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

BOOL CALLBACK AsyncURL(HWND hX, UINT message, WPARAM wParam,

LPARAM lParam)

{


switch(message)

{

case WM_INITDIALOG:

//change the cursor to indicate something is happening

SetCursor(LoadCursor(NULL,IDC_WAIT));

//set the default web sites

SetDlgItemText(hX,IDC_URL1,

LPSTR("http://www.microsoft.com"));

SetDlgItemText(hX,IDC_URL2,

LPSTR("http://home.microsoft.com"));

//initialize the first context value

rcContext1.hWindow = hX;

rcContext1.nURL = IDC_URL1;

rcContext1.nHeader = IDC_Header1;

rcContext1.nResource = IDC_Resource1;

StringCchPrintf(rcContext1.szMemo, 512, "AsyncURL(%d)",

rcContext2.nURL);

//initialize the second context value

rcContext2.hWindow = hX;

rcContext2.nURL = IDC_URL2;

rcContext2.nHeader = IDC_Header2;

rcContext2.nResource = IDC_Resource2;

StringCchPrintf(rcContext2.szMemo, 512, "AsyncURL(%d)",

rcContext2.nURL);

//change the cursor back to normal

SetCursor(LoadCursor(NULL,IDC_ARROW));

return TRUE;

case WM_COMMAND:

switch(LOWORD(wParam))

{

case IDC_EXIT:

//change the cursor

SetCursor(LoadCursor(NULL,IDC_WAIT));

//close the dialog box

EndDialog(hX,0);

//return the cursor to normal

SetCursor(LoadCursor(NULL,IDC_ARROW));

return TRUE;

case IDC_Download:

hButton = GetDlgItem(hX, IDC_Download);

EnableWindow(hButton,0);

//reset the edit boxes

SetDlgItemText(hX,IDC_Resource1,LPSTR(""));

SetDlgItemText(hX,IDC_Resource2,LPSTR(""));

SetDlgItemText(hX,IDC_Header1,LPSTR(""));

SetDlgItemText(hX,IDC_Header2,LPSTR(""));

//start the downloads

AsyncDirect(&rcContext1, hOpen);

AsyncDirect(&rcContext2, hOpen);

return TRUE;

}

return FALSE;

case WM_DESTROY:

//change the cursor

SetCursor(LoadCursor(NULL,IDC_WAIT));

//close the dialog box

EndDialog(hX,0);

//return the cursor to normal

SetCursor(LoadCursor(NULL,IDC_ARROW));

return TRUE;

default:

return FALSE;

}

}

//*******************************************************************

// Other Functions

//*******************************************************************

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

AsyncDirect handles the initial download request using

InternetOpenUrl.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void AsyncDirect (REQUEST_CONTEXT *prcContext, HINTERNET hOpen)

{

//dim a buffer to hold the URL

char szURL[256];

//retrieve the URL from the designated edit box

GetDlgItemText(prcContext->hWindow,prcContext->nURL,szURL,256);


//update the memo in the REQUEST_CONTEXT structure

StringCchPrintf(prcContext->szMemo, 512, "AsyncDirect(%s)(%d):", szURL, 
prcContext->nURL);

//call InternetOpenUrl

prcContext->hResource = InternetOpenUrl(hOpen, szURL, NULL, 0, 0, 
(DWORD)prcContext);


//check the HINTERNET handle for errors

if (prcContext->hResource == NULL)

{

if (GetLastError() != ERROR_IO_PENDING)

{

//reuse the URL buffer for the error information

StringCchPrintf(szURL, 256, "Error %d encountered.",GetLastError());

//write error to resource edit box

SetDlgItemText(prcContext->hWindow, prcContext->nResource,

szURL);

}

}

}



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Juggler is the callback function that is registered using

InternetSetStatusCallback.

Juggler displays the current callback in a list box with the ID,

IDC_CallbackList. The information displayed uses szMemo (which

contains the last function that was called), the

dwStatusInformationLength (to monitor the size of the information

being returned),

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void __stdcall Juggler (HINTERNET hInternet, DWORD dwContext,

DWORD dwInternetStatus,

LPVOID lpvStatusInformation,

DWORD dwStatusInformationLength)

{

REQUEST_CONTEXT *cpContext;

char szBuffer[512];

cpContext= (REQUEST_CONTEXT*)dwContext;



switch (dwInternetStatus)

{

case INTERNET_STATUS_CLOSING_CONNECTION:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: CLOSING_CONNECTION (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_CONNECTED_TO_SERVER:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: CONNECTED_TO_SERVER (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_CONNECTING_TO_SERVER:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: CONNECTING_TO_SERVER (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_CONNECTION_CLOSED:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: CONNECTION_CLOSED (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_HANDLE_CLOSING:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: HANDLE_CLOSING (%d)",

cpContext->szMemo, dwStatusInformationLength);

StringCchPrintf(cpContext->szMemo, 512, "Closed");


//check if the both resource handles are closing

//if so, enable the download button.

if ((strcmp(rcContext1.szMemo,"Closed")) ||

(strcmp(rcContext2.szMemo,"Closed")))

{

hButton = GetDlgItem(cpContext->hWindow, IDC_Download);

EnableWindow(hButton,1);

}

break;

case INTERNET_STATUS_HANDLE_CREATED:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: HANDLE_CREATED (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_INTERMEDIATE_RESPONSE:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: INTERMEDIATE_RESPONSE (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_NAME_RESOLVED:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: NAME_RESOLVED (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_RECEIVING_RESPONSE:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: RECEIVEING_RESPONSE (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_RESPONSE_RECEIVED:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: RESPONSE_RECEIVED (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_REDIRECT:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: REDIRECT (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_REQUEST_COMPLETE:

//check for errors

if (LPINTERNET_ASYNC_RESULT(lpvStatusInformation)->dwError == 0)

{

//check if the completed request is from AsyncDirect

if (strcmp(cpContext->szMemo, "AsyncDirect"))

{

//set the resource handle to the HINTERNET handle

//returned in the callback

cpContext->hResource = HINTERNET(

LPINTERNET_ASYNC_RESULT(lpvStatusInformation)->dwResult);

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: REQUEST_COMPLETE (%d)",

cpContext->szMemo, dwStatusInformationLength);

//create a thread to handle the header and

//resource download

cpContext->hThread = CreateThread(NULL, 0,

(LPTHREAD_START_ROUTINE)Threader,LPVOID(cpContext), 0,

&cpContext->dwThreadID);

}

else

{

StringCchPrintf(szBuffer,512,"%s(%d): REQUEST_COMPLETE (%d)",

cpContext->szMemo,

cpContext->nURL, dwStatusInformationLength);

}

}

else

{

StringCchPrintf(szBuffer,512,

"%s: REQUEST_COMPLETE (%d) Error (%d) encountered",

cpContext->szMemo, dwStatusInformationLength,

GetLastError());

}

break;

case INTERNET_STATUS_REQUEST_SENT:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: REQUEST_SENT (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_RESOLVING_NAME:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: RESOLVING_NAME (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_SENDING_REQUEST:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: SENDING_REQUEST (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

case INTERNET_STATUS_STATE_CHANGE:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: STATE_CHANGE (%d)",

cpContext->szMemo, dwStatusInformationLength);

break;

default:

//write the callback information to the buffer

StringCchPrintf(szBuffer,512,"%s: Unknown: Status %d Given", 
cpContext->szMemo, dwInternetStatus);

break;

}

//add the callback information to the callback list box

SendDlgItemMessage(cpContext->hWindow,IDC_CallbackList,

LB_ADDSTRING,0,(LPARAM)szBuffer);


}





/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Threader is a thread function to handle the retrieval of the header

and resource information. Since the WinInet functions involved in

both of these operations work synchronously, using a separate

thread will help avoid any blocking.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

DWORD Threader(LPVOID lpvContext)

{

REQUEST_CONTEXT *cpContext;


//copy the pointer to a REQUEST_CONTEXT pointer to ease calls

cpContext= (REQUEST_CONTEXT*)lpvContext;

//set szMemo to the name of the function to be called

StringCchPrintf(cpContext->szMemo, 512, "Header(%d)", cpContext->nURL);

//call the header function

Header(cpContext->hWindow, cpContext->nHeader, -1, cpContext->hResource);

//set szMemo to the name of the function to be called

StringCchPrintf(cpContext->szMemo, 512, "Dump(%d)", cpContext->nURL);

//call the dump function

Dump(cpContext->hWindow, cpContext->nResource, cpContext->hResource);

return S_OK;

}



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Header handles the retrieval of the HTTP header information.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

int WINAPI Header(HWND hX,int intControl, int intCustom, HINTERNET hHttp)

{

DWORD dwHeaderType=-1;

DWORD dwSize=0;

LPVOID lpOutBuffer = NULL;

char szError[80];

//change the cursor

SetCursor(LoadCursor(NULL,IDC_WAIT));



//set the header type to be requested, which is all headers in

//this case

dwHeaderType = HTTP_QUERY_RAW_HEADERS_CRLF;





retry:

//call HttpQueryInfo.

//first time with a zero buffer size to get the size of the buffer

//needed and to check if the header exists

if(!HttpQueryInfo(hHttp,dwHeaderType,(LPVOID)lpOutBuffer,&dwSize,NULL))

{

//check if the header was not found

if (GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND)

{

StringCchPrintf(szError,80,"Error %d encountered", GetLastError());

SetDlgItemText(hX,intControl, szError);

SetCursor(LoadCursor(NULL,IDC_ARROW));

return TRUE;

}

else

{

//check if the buffer was insufficient

if (GetLastError()==ERROR_INSUFFICIENT_BUFFER)

{

//allocate the buffer

lpOutBuffer = new char[dwSize+1];

goto retry;

}

else

{

//display other errors in header edit box

StringCchPrintf(szError,80,"Error %d encountered", GetLastError());

SetDlgItemText(hX,intControl, szError);

SetCursor(LoadCursor(NULL,IDC_ARROW));

return FALSE;

}

}

}



SetDlgItemText(hX,intControl,(LPSTR)lpOutBuffer);

delete[]lpOutBuffer;

SetCursor(LoadCursor(NULL,IDC_ARROW));

return 1;

}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

int WINAPI Dump(HWND hX, int intCtrlID, HINTERNET hResource)

{


LPSTR lpszData; // buffer for the data

DWORD dwSize; // size of the data available

DWORD dwDownloaded; // size of the downloaded data

DWORD dwSizeSum=0; // size of the data in the textbox

LPSTR lpszHolding; // buffer to merge the textbox data and buffer

char szError[80]; // buffer for error information

// Set the cursor to an hourglass.

SetCursor(LoadCursor(NULL,IDC_WAIT));

int nCounter; // counter used to display something while

// I/O is pending.



// This loop handles reading the data.

do

{

try_again:

// The call to InternetQueryDataAvailable determines the amount of

// data available to download.

if (!InternetQueryDataAvailable(hResource,&dwSize,0,0))

{

if (GetLastError()== ERROR_IO_PENDING)

{

nCounter = 0;


while(GetLastError()==ERROR_IO_PENDING)

{

nCounter++;

if (nCounter==2000)

break;

InternetQueryDataAvailable(hResource,&dwSize,0,0);

}

goto try_again;

}

StringCchPrintf(szError,80,"Error %d encountered by 
InternetQueryDataAvailable",

GetLastError());

SetDlgItemText(hX,intCtrlID, szError);

SetCursor(LoadCursor(NULL,IDC_ARROW));

break;

}

else

{

// Allocates a buffer of the size returned by InternetQueryDataAvailable

lpszData = new char[dwSize+1];

// Reads the data from the HINTERNET handle.

if(!InternetReadFile(hResource,(LPVOID)lpszData,dwSize,&dwDownloaded))

{

if (GetLastError()== ERROR_IO_PENDING)

{

nCounter = 0;


while(GetLastError()==ERROR_IO_PENDING)

{

nCounter++;

}

goto keep_going;

}

StringCchPrintf(szError,80,"Error %d encountered by InternetReadFile",

GetLastError());

SetDlgItemText(hX,intCtrlID, szError);

delete[] lpszData;

break;

}

else

{

keep_going:

// Adds a null terminator to the end of the data buffer

lpszData[dwDownloaded]='\0';

// Allocates the holding buffer

lpszHolding = new char[dwSizeSum + dwDownloaded + 1];


// Checks if there has been any data written to the textbox

if (dwSizeSum != 0)

{

// Retrieves the data stored in the textbox if any

GetDlgItemText(hX,intCtrlID,(LPSTR)lpszHolding,dwSizeSum);


// Adds a null terminator at the end of the textbox data

lpszHolding[dwSizeSum]='\0';

}

else

{

// Make the holding buffer an empty string.

lpszHolding[0]='\0';

}

// Adds the new data to the holding buffer

StringCchCat(lpszHolding,dwSizeSum + dwDownloaded + 1,lpszData);

// Writes the holding buffer to the textbox

SetDlgItemText(hX,intCtrlID,(LPSTR)lpszHolding);

// Delete the two buffers

delete[] lpszHolding;

delete[] lpszData;

// Add the size of the downloaded data to the textbox data size

dwSizeSum = dwSizeSum + dwDownloaded + 1;

// Check the size of the remaining data. If it is zero, break.

if (dwDownloaded == 0)

break;

}

}

}

while(TRUE);

// Close the HINTERNET handle

InternetCloseHandle(hResource);

// Set the cursor back to an arrow

SetCursor(LoadCursor(NULL,IDC_ARROW));

// Return

return TRUE;

}






//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//

//

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


0
lhdelamare (10)
12/8/2004 3:22:11 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
1135 Views

Similar Articles

[PageSpeed] 41

i think you have some work to do... as do most of us on this group, so don't
expect free programming services on here.  if you have some general
questions you might get an answer, but don't expect someone to do it for
you.

"Leandro Delamare" <lhdelamare@uol.com.br> wrote in message
news:%231$BBnT3EHA.2568@TK2MSFTNGP11.phx.gbl...
> Hello Group. I need to convert the code of WiniNet Async Demo from
microsoft
> samples
> from MFC to a console function..
>
> Someone can help me with the changes..
>
> The code is posted here
>
> Regards
>
> /* Microsoft Corporation Copyright 1999-2002 */
>
> /********************************************************************
>
> ProjectName : AsyncDemo
>
> Purpose : This sample demonstrates how to submit two
>
> WinInet requests, using InternentOpenUrl,
>
> asynchronously.
>
> Notes : This sample does not handle any authentication.
>
> To properly handle authentication, the
>
> functions that handle specific protocols (like
>
> HttpOpenRequest/HttpSendRequest) would need to
>
> be used instead of InternetOpenUrl.
>
> Last Updated: February 2, 1998
>
>
>
>
> *********************************************************************/
>
>
>
> #include <windows.h>
>
> #include <iostream>
>
> #include <string.h>
>
> #include <stdio.h>
>
> #include <wininet.h>
>
> #include <strsafe.h>
>
> #include "resource.h"
>
> //*******************************************************************
>
> // Global Variable Declarations
>
> //*******************************************************************
>
> LPSTR lpszAgent = "Asynchronous WinInet Demo Program";
>
> //root HINTERNET handle
>
> HINTERNET hOpen;
>
> //instance of the callback function
>
> INTERNET_STATUS_CALLBACK iscCallback;
>
> //structure to be passed as the dwContext value
>
> typedef struct {
>
> HWND hWindow; //main window handle
>
> int nURL; //ID of the Edit Box w/ the URL
>
> int nHeader; //ID of the Edit Box for the header info
>
> int nResource; //ID of the Edit Box for the resource
>
> HINTERNET hOpen; //HINTERNET handle created by InternetOpen
>
> HINTERNET hResource; //HINTERNET handle created by InternetOpenUrl
>
> char szMemo[512];//string to store status memo
>
> HANDLE hThread; //thread handle
>
> DWORD dwThreadID; //thread ID
>
> } REQUEST_CONTEXT;
>
>
>
> //two instances of the structure
>
> static REQUEST_CONTEXT rcContext1, rcContext2;
>
> HWND hButton;
>
> //*******************************************************************
>
> // Function Declarations
>
> //*******************************************************************
>
> //dialog box functions
>
> BOOL CALLBACK AsyncURL(HWND, UINT, WPARAM, LPARAM);
>
> //callback function
>
> void __stdcall Juggler(HINTERNET, DWORD , DWORD , LPVOID, DWORD);
>
> //thread function
>
> DWORD Threader(LPVOID);
>
> //functions
>
> int WINAPI Dump(HWND, int, HINTERNET);
>
> int WINAPI Header(HWND,int, int, HINTERNET);
>
> void AsyncDirect (REQUEST_CONTEXT*, HINTERNET);
>
>
>
>
>
>
>
> //*******************************************************************
>
> // Main Program
>
> //*******************************************************************
>
> int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
>
> LPSTR lpszArgs, int nWinMode)
>
> {
>
> //create the root HINTERNET handle using the systems default
>
> //settings.
>
> hOpen = InternetOpen(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG,
>
> NULL, NULL, INTERNET_FLAG_ASYNC);
>
> //check if the root HINTERNET handle has been created
>
> if (hOpen == NULL)
>
> {
>
> return FALSE;
>
> }
>
> else
>
> {
>
> //sets the callback function
>
> iscCallback = InternetSetStatusCallback(hOpen,
> (INTERNET_STATUS_CALLBACK)Juggler);
>
> //creates the dialog box
>
> DialogBox(hThisInst,"DB_ASYNCDEMO", HWND_DESKTOP,(DLGPROC)AsyncURL);
>
> //closes the root HINTERNET handle
>
> return InternetCloseHandle(hOpen);
>
> }
>
>
>
> }
>
>
>
> //*******************************************************************
>
> // Dialog Functions
>
> //*******************************************************************
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> //
>
> //
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> BOOL CALLBACK AsyncURL(HWND hX, UINT message, WPARAM wParam,
>
> LPARAM lParam)
>
> {
>
>
> switch(message)
>
> {
>
> case WM_INITDIALOG:
>
> //change the cursor to indicate something is happening
>
> SetCursor(LoadCursor(NULL,IDC_WAIT));
>
> //set the default web sites
>
> SetDlgItemText(hX,IDC_URL1,
>
> LPSTR("http://www.microsoft.com"));
>
> SetDlgItemText(hX,IDC_URL2,
>
> LPSTR("http://home.microsoft.com"));
>
> //initialize the first context value
>
> rcContext1.hWindow = hX;
>
> rcContext1.nURL = IDC_URL1;
>
> rcContext1.nHeader = IDC_Header1;
>
> rcContext1.nResource = IDC_Resource1;
>
> StringCchPrintf(rcContext1.szMemo, 512, "AsyncURL(%d)",
>
> rcContext2.nURL);
>
> //initialize the second context value
>
> rcContext2.hWindow = hX;
>
> rcContext2.nURL = IDC_URL2;
>
> rcContext2.nHeader = IDC_Header2;
>
> rcContext2.nResource = IDC_Resource2;
>
> StringCchPrintf(rcContext2.szMemo, 512, "AsyncURL(%d)",
>
> rcContext2.nURL);
>
> //change the cursor back to normal
>
> SetCursor(LoadCursor(NULL,IDC_ARROW));
>
> return TRUE;
>
> case WM_COMMAND:
>
> switch(LOWORD(wParam))
>
> {
>
> case IDC_EXIT:
>
> //change the cursor
>
> SetCursor(LoadCursor(NULL,IDC_WAIT));
>
> //close the dialog box
>
> EndDialog(hX,0);
>
> //return the cursor to normal
>
> SetCursor(LoadCursor(NULL,IDC_ARROW));
>
> return TRUE;
>
> case IDC_Download:
>
> hButton = GetDlgItem(hX, IDC_Download);
>
> EnableWindow(hButton,0);
>
> //reset the edit boxes
>
> SetDlgItemText(hX,IDC_Resource1,LPSTR(""));
>
> SetDlgItemText(hX,IDC_Resource2,LPSTR(""));
>
> SetDlgItemText(hX,IDC_Header1,LPSTR(""));
>
> SetDlgItemText(hX,IDC_Header2,LPSTR(""));
>
> //start the downloads
>
> AsyncDirect(&rcContext1, hOpen);
>
> AsyncDirect(&rcContext2, hOpen);
>
> return TRUE;
>
> }
>
> return FALSE;
>
> case WM_DESTROY:
>
> //change the cursor
>
> SetCursor(LoadCursor(NULL,IDC_WAIT));
>
> //close the dialog box
>
> EndDialog(hX,0);
>
> //return the cursor to normal
>
> SetCursor(LoadCursor(NULL,IDC_ARROW));
>
> return TRUE;
>
> default:
>
> return FALSE;
>
> }
>
> }
>
> //*******************************************************************
>
> // Other Functions
>
> //*******************************************************************
>
> /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> AsyncDirect handles the initial download request using
>
> InternetOpenUrl.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
>
> void AsyncDirect (REQUEST_CONTEXT *prcContext, HINTERNET hOpen)
>
> {
>
> //dim a buffer to hold the URL
>
> char szURL[256];
>
> //retrieve the URL from the designated edit box
>
> GetDlgItemText(prcContext->hWindow,prcContext->nURL,szURL,256);
>
>
> //update the memo in the REQUEST_CONTEXT structure
>
> StringCchPrintf(prcContext->szMemo, 512, "AsyncDirect(%s)(%d):", szURL,
> prcContext->nURL);
>
> //call InternetOpenUrl
>
> prcContext->hResource = InternetOpenUrl(hOpen, szURL, NULL, 0, 0,
> (DWORD)prcContext);
>
>
> //check the HINTERNET handle for errors
>
> if (prcContext->hResource == NULL)
>
> {
>
> if (GetLastError() != ERROR_IO_PENDING)
>
> {
>
> //reuse the URL buffer for the error information
>
> StringCchPrintf(szURL, 256, "Error %d encountered.",GetLastError());
>
> //write error to resource edit box
>
> SetDlgItemText(prcContext->hWindow, prcContext->nResource,
>
> szURL);
>
> }
>
> }
>
> }
>
>
>
> /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Juggler is the callback function that is registered using
>
> InternetSetStatusCallback.
>
> Juggler displays the current callback in a list box with the ID,
>
> IDC_CallbackList. The information displayed uses szMemo (which
>
> contains the last function that was called), the
>
> dwStatusInformationLength (to monitor the size of the information
>
> being returned),
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
>
> void __stdcall Juggler (HINTERNET hInternet, DWORD dwContext,
>
> DWORD dwInternetStatus,
>
> LPVOID lpvStatusInformation,
>
> DWORD dwStatusInformationLength)
>
> {
>
> REQUEST_CONTEXT *cpContext;
>
> char szBuffer[512];
>
> cpContext= (REQUEST_CONTEXT*)dwContext;
>
>
>
> switch (dwInternetStatus)
>
> {
>
> case INTERNET_STATUS_CLOSING_CONNECTION:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: CLOSING_CONNECTION (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_CONNECTED_TO_SERVER:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: CONNECTED_TO_SERVER (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_CONNECTING_TO_SERVER:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: CONNECTING_TO_SERVER (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_CONNECTION_CLOSED:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: CONNECTION_CLOSED (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_HANDLE_CLOSING:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: HANDLE_CLOSING (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> StringCchPrintf(cpContext->szMemo, 512, "Closed");
>
>
> //check if the both resource handles are closing
>
> //if so, enable the download button.
>
> if ((strcmp(rcContext1.szMemo,"Closed")) ||
>
> (strcmp(rcContext2.szMemo,"Closed")))
>
> {
>
> hButton = GetDlgItem(cpContext->hWindow, IDC_Download);
>
> EnableWindow(hButton,1);
>
> }
>
> break;
>
> case INTERNET_STATUS_HANDLE_CREATED:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: HANDLE_CREATED (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: INTERMEDIATE_RESPONSE (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_NAME_RESOLVED:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: NAME_RESOLVED (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_RECEIVING_RESPONSE:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: RECEIVEING_RESPONSE (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_RESPONSE_RECEIVED:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: RESPONSE_RECEIVED (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_REDIRECT:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: REDIRECT (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_REQUEST_COMPLETE:
>
> //check for errors
>
> if (LPINTERNET_ASYNC_RESULT(lpvStatusInformation)->dwError == 0)
>
> {
>
> //check if the completed request is from AsyncDirect
>
> if (strcmp(cpContext->szMemo, "AsyncDirect"))
>
> {
>
> //set the resource handle to the HINTERNET handle
>
> //returned in the callback
>
> cpContext->hResource = HINTERNET(
>
> LPINTERNET_ASYNC_RESULT(lpvStatusInformation)->dwResult);
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: REQUEST_COMPLETE (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> //create a thread to handle the header and
>
> //resource download
>
> cpContext->hThread = CreateThread(NULL, 0,
>
> (LPTHREAD_START_ROUTINE)Threader,LPVOID(cpContext), 0,
>
> &cpContext->dwThreadID);
>
> }
>
> else
>
> {
>
> StringCchPrintf(szBuffer,512,"%s(%d): REQUEST_COMPLETE (%d)",
>
> cpContext->szMemo,
>
> cpContext->nURL, dwStatusInformationLength);
>
> }
>
> }
>
> else
>
> {
>
> StringCchPrintf(szBuffer,512,
>
> "%s: REQUEST_COMPLETE (%d) Error (%d) encountered",
>
> cpContext->szMemo, dwStatusInformationLength,
>
> GetLastError());
>
> }
>
> break;
>
> case INTERNET_STATUS_REQUEST_SENT:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: REQUEST_SENT (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_RESOLVING_NAME:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: RESOLVING_NAME (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_SENDING_REQUEST:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: SENDING_REQUEST (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> case INTERNET_STATUS_STATE_CHANGE:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: STATE_CHANGE (%d)",
>
> cpContext->szMemo, dwStatusInformationLength);
>
> break;
>
> default:
>
> //write the callback information to the buffer
>
> StringCchPrintf(szBuffer,512,"%s: Unknown: Status %d Given",
> cpContext->szMemo, dwInternetStatus);
>
> break;
>
> }
>
> //add the callback information to the callback list box
>
> SendDlgItemMessage(cpContext->hWindow,IDC_CallbackList,
>
> LB_ADDSTRING,0,(LPARAM)szBuffer);
>
>
> }
>
>
>
>
>
> /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Threader is a thread function to handle the retrieval of the header
>
> and resource information. Since the WinInet functions involved in
>
> both of these operations work synchronously, using a separate
>
> thread will help avoid any blocking.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
>
> DWORD Threader(LPVOID lpvContext)
>
> {
>
> REQUEST_CONTEXT *cpContext;
>
>
> //copy the pointer to a REQUEST_CONTEXT pointer to ease calls
>
> cpContext= (REQUEST_CONTEXT*)lpvContext;
>
> //set szMemo to the name of the function to be called
>
> StringCchPrintf(cpContext->szMemo, 512, "Header(%d)", cpContext->nURL);
>
> //call the header function
>
> Header(cpContext->hWindow, cpContext->nHeader, -1, cpContext->hResource);
>
> //set szMemo to the name of the function to be called
>
> StringCchPrintf(cpContext->szMemo, 512, "Dump(%d)", cpContext->nURL);
>
> //call the dump function
>
> Dump(cpContext->hWindow, cpContext->nResource, cpContext->hResource);
>
> return S_OK;
>
> }
>
>
>
> /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Header handles the retrieval of the HTTP header information.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
>
> int WINAPI Header(HWND hX,int intControl, int intCustom, HINTERNET hHttp)
>
> {
>
> DWORD dwHeaderType=-1;
>
> DWORD dwSize=0;
>
> LPVOID lpOutBuffer = NULL;
>
> char szError[80];
>
> //change the cursor
>
> SetCursor(LoadCursor(NULL,IDC_WAIT));
>
>
>
> //set the header type to be requested, which is all headers in
>
> //this case
>
> dwHeaderType = HTTP_QUERY_RAW_HEADERS_CRLF;
>
>
>
>
>
> retry:
>
> //call HttpQueryInfo.
>
> //first time with a zero buffer size to get the size of the buffer
>
> //needed and to check if the header exists
>
> if(!HttpQueryInfo(hHttp,dwHeaderType,(LPVOID)lpOutBuffer,&dwSize,NULL))
>
> {
>
> //check if the header was not found
>
> if (GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND)
>
> {
>
> StringCchPrintf(szError,80,"Error %d encountered", GetLastError());
>
> SetDlgItemText(hX,intControl, szError);
>
> SetCursor(LoadCursor(NULL,IDC_ARROW));
>
> return TRUE;
>
> }
>
> else
>
> {
>
> //check if the buffer was insufficient
>
> if (GetLastError()==ERROR_INSUFFICIENT_BUFFER)
>
> {
>
> //allocate the buffer
>
> lpOutBuffer = new char[dwSize+1];
>
> goto retry;
>
> }
>
> else
>
> {
>
> //display other errors in header edit box
>
> StringCchPrintf(szError,80,"Error %d encountered", GetLastError());
>
> SetDlgItemText(hX,intControl, szError);
>
> SetCursor(LoadCursor(NULL,IDC_ARROW));
>
> return FALSE;
>
> }
>
> }
>
> }
>
>
>
> SetDlgItemText(hX,intControl,(LPSTR)lpOutBuffer);
>
> delete[]lpOutBuffer;
>
> SetCursor(LoadCursor(NULL,IDC_ARROW));
>
> return 1;
>
> }
>
>
> /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
>
> int WINAPI Dump(HWND hX, int intCtrlID, HINTERNET hResource)
>
> {
>
>
> LPSTR lpszData; // buffer for the data
>
> DWORD dwSize; // size of the data available
>
> DWORD dwDownloaded; // size of the downloaded data
>
> DWORD dwSizeSum=0; // size of the data in the textbox
>
> LPSTR lpszHolding; // buffer to merge the textbox data and buffer
>
> char szError[80]; // buffer for error information
>
> // Set the cursor to an hourglass.
>
> SetCursor(LoadCursor(NULL,IDC_WAIT));
>
> int nCounter; // counter used to display something while
>
> // I/O is pending.
>
>
>
> // This loop handles reading the data.
>
> do
>
> {
>
> try_again:
>
> // The call to InternetQueryDataAvailable determines the amount of
>
> // data available to download.
>
> if (!InternetQueryDataAvailable(hResource,&dwSize,0,0))
>
> {
>
> if (GetLastError()== ERROR_IO_PENDING)
>
> {
>
> nCounter = 0;
>
>
> while(GetLastError()==ERROR_IO_PENDING)
>
> {
>
> nCounter++;
>
> if (nCounter==2000)
>
> break;
>
> InternetQueryDataAvailable(hResource,&dwSize,0,0);
>
> }
>
> goto try_again;
>
> }
>
> StringCchPrintf(szError,80,"Error %d encountered by
> InternetQueryDataAvailable",
>
> GetLastError());
>
> SetDlgItemText(hX,intCtrlID, szError);
>
> SetCursor(LoadCursor(NULL,IDC_ARROW));
>
> break;
>
> }
>
> else
>
> {
>
> // Allocates a buffer of the size returned by InternetQueryDataAvailable
>
> lpszData = new char[dwSize+1];
>
> // Reads the data from the HINTERNET handle.
>
> if(!InternetReadFile(hResource,(LPVOID)lpszData,dwSize,&dwDownloaded))
>
> {
>
> if (GetLastError()== ERROR_IO_PENDING)
>
> {
>
> nCounter = 0;
>
>
> while(GetLastError()==ERROR_IO_PENDING)
>
> {
>
> nCounter++;
>
> }
>
> goto keep_going;
>
> }
>
> StringCchPrintf(szError,80,"Error %d encountered by InternetReadFile",
>
> GetLastError());
>
> SetDlgItemText(hX,intCtrlID, szError);
>
> delete[] lpszData;
>
> break;
>
> }
>
> else
>
> {
>
> keep_going:
>
> // Adds a null terminator to the end of the data buffer
>
> lpszData[dwDownloaded]='\0';
>
> // Allocates the holding buffer
>
> lpszHolding = new char[dwSizeSum + dwDownloaded + 1];
>
>
> // Checks if there has been any data written to the textbox
>
> if (dwSizeSum != 0)
>
> {
>
> // Retrieves the data stored in the textbox if any
>
> GetDlgItemText(hX,intCtrlID,(LPSTR)lpszHolding,dwSizeSum);
>
>
> // Adds a null terminator at the end of the textbox data
>
> lpszHolding[dwSizeSum]='\0';
>
> }
>
> else
>
> {
>
> // Make the holding buffer an empty string.
>
> lpszHolding[0]='\0';
>
> }
>
> // Adds the new data to the holding buffer
>
> StringCchCat(lpszHolding,dwSizeSum + dwDownloaded + 1,lpszData);
>
> // Writes the holding buffer to the textbox
>
> SetDlgItemText(hX,intCtrlID,(LPSTR)lpszHolding);
>
> // Delete the two buffers
>
> delete[] lpszHolding;
>
> delete[] lpszData;
>
> // Add the size of the downloaded data to the textbox data size
>
> dwSizeSum = dwSizeSum + dwDownloaded + 1;
>
> // Check the size of the remaining data. If it is zero, break.
>
> if (dwDownloaded == 0)
>
> break;
>
> }
>
> }
>
> }
>
> while(TRUE);
>
> // Close the HINTERNET handle
>
> InternetCloseHandle(hResource);
>
> // Set the cursor back to an arrow
>
> SetCursor(LoadCursor(NULL,IDC_ARROW));
>
> // Return
>
> return TRUE;
>
> }
>
>
>
>
>
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> //
>
> //
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>


0
noone1 (387)
12/8/2004 4:13:45 PM
Reply:

Similar Artilces:

A strange problem with MFC
Hi, Rencently I met a strange problem. The code like below: CWinThread* pThread = AfxBeginThread(ThreadFunc, (LPVOID)this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); if(pThread->m_hThread != NULL){ pThread->m_bAutodelete = FALSE; pThread->ResumeThread(); } After the statement "pThread->m_bAutodelete = FALSE" executed, I found the value of pThread->m_hThread is 0. While pThread->m_bAutodelete is still 1! The code section located in a win32 static library, with /Md option.The host application(exe) is a win32 console application, with /Md option. There...

Unicode in MFC
Hi, I am new to MFC programming and I have a problem: when I try to write the caption of a button or something else in my own language(Farsi), in the design mode it shows the correct string but when I compile it it shows a '?' instead of every character. Can anyone please help me with that. > I am new to MFC programming and I have a problem: > when I try to write the caption of a button or something else in my > own language(Farsi), in the design mode it shows the correct string > but when I compile it it shows a '?' instead of every character. Can > anyone ple...

return int value to OS in MFC App
Hi, Everybody. I have to make A MFC app to return int value to Operatiing System.. if i could use WinMain() function, this is not matter. but MFC does not reveal WinMain().... How can i solve this problem? Can Anybody help me with this problem? <flybluewing@bcline.com> wrote in message news:1189386249.923483.59250@y42g2000hsy.googlegroups.com... > Hi, Everybody. > > I have to make A MFC app to return int value to Operatiing System.. > > if i could use WinMain() function, this is not matter. > but MFC does not reveal WinMain().... > How can i solve this problem?...

mfc and IE activeX
I'm using VS 2003 and trying to use Internet Explorer in my MFC application but encountering problems If I built a very simple test dialog-application and drop in the IE it works exactly as expected. However, when I create a similar dialog box in my MFC application and call the ...DoModal() nothing appears at all - not even the dialog box itself. It's as if my application does not want to use ActiveX components - I also tried a couple of other Microsoft ActiveX controls and they have the same problem. I must be missing something obvious - any one with any ideas will be much ...

Need Help with MFC!!
Hi all, need help esp. with Graphic part. When you right click on any drive on your machine and click properties, you get a tabbed dialog. I want to know how can I embed graphic image (pie chart) into my MFC Dialog? I have written code which displays the Disk Usage right now but don't know how to display that info as a PIE CHART!!!!!! besides what type of MFC Dialog application should I look fwd to build? I want exactly as the DRIVE properties. TIA -- ======== Regards Vai ======== Have you looked at the CDC::Pie method? joe On Wed, 12 May 2004 23:07:11 -0400, "Vai2000"...

MFC to Console.
Hello Group. I need to convert the code of WiniNet Async Demo from microsoft samples from MFC to a console function.. Someone can help me with the changes.. The code is posted here Regards /* Microsoft Corporation Copyright 1999-2002 */ /******************************************************************** ProjectName : AsyncDemo Purpose : This sample demonstrates how to submit two WinInet requests, using InternentOpenUrl, asynchronously. Notes : This sample does not handle any authentication. To properly handle authentication, the functions that handle specific protocols (like Ht...

SBS 2008 Console crashes on Startup
I have a SBS 2008 server that was working fine. I went to install a program (VMWare server) on it and now the SBS 2008 console has quit working. It crashes out immediately upon bootup. The server also put all of the standard text into italics. This server did it once before when I first went to set it up after trying to install their business app on it. It wasn't anything special and didn't require alot of resources. To fix it then, I just wiped it and reloaded it. Well now I have the server in place and a simple wipe and reload really isn't an option. The ser...

XML and MFC
Hello guys, What source of knowledge would you point me to if you were about to integrate XML with MFC? Of course if there's any Microsoft documentation anywhere, please post me a link to it. Thank you in advance! :-) Yea, I wanna know it too. Who would give a hand? > What source of knowledge would you point me to if you were about to > integrate XML with MFC? Of course if there's any Microsoft documentation > anywhere, please post me a link to it. After digging left and right, I remained with two main options: - MSXML - MS, proprietary, COM, with all the implications:...

Sending Window Messages from an MFC app to a Windows Firm tray application
Hello, I have an MFC MDI application and a Windows Forms (2.0) Tray Icon application. I want to run a command on the tray application via my MFC application. There is a "Register" context menu command on the tray icon application. I want to call the Register command from my MFC MDI application. I thought of a windows message. How do I do it? Is there any other better mechanism to do so? Thanks, Janiv Ratson. If you know the class of the window on the tray application you can use FindWindow() to get the window for the class. Then you can use either PostMessage() or SendMessag...

dynamically managing of layout in MFC + GridBagLayout in MFC or C++
Hi, can anybody tell me how can I make or find a function in MFC to manage layout of a dialog that dynamically has been create and also the controls in the dialog? I am new in MFC, what I am lokking for is something like GridBagLayout in java? is there something like this in C++ MFC ? any idea plz? Thank u There is nothing like GridBagLayout in MFC. However, you can achieve the same functionality thru various means. You have to move the controls manually on resize of the dialog or window. Please see the following examples: http://www.codeproject.com/dialog/easysize.asp http://www.codepr...

Console output from MFC dialog based app
Dear All, I have developed a MFC dialog based application. Now when I execute this app from command prompt, I need to write some text back to console. In console application we achieve this using functions like printf(), puts(), etc. Please let me know how do I achieve same in dialog based application since printf() and other functions are not working here. Thanks, Ajay You can't write to the same console window that you were ran from, but you can create a console window and write to that. Take a look at AllocConsole, ReadConsole, and WriteConsole. Here is an example: http://www....

Reporting back crashes in MFC-based products
Hello, We have a product written in MFC using Visual Studio 7.1. We are now planning to implement a feature that will detect a crash and report to us the cause of the crash and other meaningful information. The plan is to provide something similar to Window's error reporting tool. I found a 3rd party tool for Delphi that instruments the source code. When the program crashes, it provides information like the name of the function, module etc.. Is there something similar that I can use with MFC? The other option is to use MFC's Structured Exception Handling and try to get a memory dump...

Access and MFC
I would like to use some MFC capabilities from within Access. In PDC05/PRS313, Nick Kramer gave examples of using HWND's to create mixed Win32/Windows Presentation Foundation applications. I remember reading recently somewhere that Microsoft has released the MFC for general use. Can anyone provide information about (or even verify) the MFC release? Thanks, James A. Fortune CDMAPoster@FortuneJames.com MPAPoster@FortuneJames.com Microsoft Cabinet SDK: http://msdn2.microsoft.com/en-us/library/ms974336.aspx ...

bug of MFC ActiveX Control?
i create a default MFC activex control by wizard, i just check the windowlessActivate option, because i want to create a transparent control. but when i use the control in vb, the form_keydown event will be triger twice. i recompile the control after comment the follow line: dwFlags |= windowlessActivate; all things is ok. can someone confirm this "bug"? -- ף���ˣ� Maybe my english is so poor? Or something else? "sPhinX" <s5689412@163.com> д���ʼ� news:eQ$NrxkcFHA.4040@TK2MSFTNGP14.phx.gbl... > i create a default MFC activex control by wizard, > i just ch...

Static variables initialization problem with MFC DLL
Hi, I have the following code, working well in my MFC app, where a static member variable is initialized with the result of a static method, as this : int MyClass::anInt = MyClass::InitTheInt(); The problem is when this code is used in a DLL -using MFC in a shared DLL-, the initialization is simply ignored !!!! What's going on? Thx. Herbert wrote: >Hi, > >I have the following code, working well in my MFC app, where a >static member variable is initialized with the result of a static >method, as this : > > int MyClass::anInt = MyClass::InitTheInt(); &g...

Formatting Excell doc from within MFC app
Hello. I'm developing an application using MFC - VC++ 6.0 I'm wondering if there is an ActiveX control or other component that would make possible to make simple editing and formatting MS EXCELL doc from rithin application. The operations i would like to perform: - opening .xls file - inserting values into cells and simple formatting the cells (alliginig,, etc) - save the file - printing and displaying (not necessary) Thank You all for any help Sincerelly, magic ...

MFC Application has encountered a problem and needs to close. HELP
This is driving me nuts. Whenever I run my program in release configuraiton it always crashes with the above error message offering me an option to send a message to Microsoft. I have discovered it is an access violation (code 5). Whenever I run the program in debug configuration it runs OK. I have two main questions: 1 How can the program behave so differently in the two configurations? I can find no explanation of this in the help files. 2 How can I get useful information about the access violation? I cannot save the crash dump produced which the exception handler offers to send to ...

Is GDI+ Integrate with MFC?
Apparently, GDI+ is not intended to be used with MFC as GDI is. Is GDI+ a more stand-alone technology? Granted it can be used in MFC apps but the MFC classes do not seem to wrap GDI+. Is it resonable to use GDI+ without MFC at all? Thank You It's just another API. Why wouldn't it be reasonable to use without MFC? joe On Tue, 13 Feb 2007 21:54:49 -0800, Coder <Coder@discussions.microsoft.com> wrote: >Apparently, GDI+ is not intended to be used with MFC as GDI is. Is GDI+ a >more stand-alone technology? Granted it can be used in MFC apps but the MFC >classes...

Regular MFC dll
I created an MFC regular dll with MFC statically linked using MFC Appwizard(dll) and then I compiled the code generated by the AppWizard without adding any code. I got the these compile errors Compiling resources... Compiling... StdAfx.cpp c:\program files\microsoft sdk\include\shobjidl.h(9419) : error C2061: syntax error : identifier 'IXMLDOMDocument' c:\program files\microsoft sdk\include\shobjidl.h(9528) : error C2061: syntax error : identifier 'IXMLDOMDocument' Error executing cl.exe. How can I reomve these error. Thanks ...

Well not exactly MFC....though I am using it in MFC :)
Okay actually I am trying to write a DLL which my MFC dialog imports, but for some reason I cannot get something really simple done. Basically all I want to be able to do is copy a string that is given to a function, and then return it to the user unchanged (as within my program I modified the two strings which are given as parameters). What is weird is simply that I CANNOT delete a char * which I created using NEW??? Here is what I am trying to do.... I have char * tempString; //define in my .h file for the DLL. in the method void ChangeString(char * a, char * b) { tempString = ne...

How to insert a MFC Dialog in a DLL ?
I want to cerate a static DLL. In this DLL I want insert a MFC Dialog. I have made with the MSVisual C++ MFC AppWizard(dll) a DLL . I insert a test function in the DLL. With an other Progarmm I testet the test function the DLL . It works. Now I try insert a MCF- Dialog in the DLL but without success. Two days I was trying but no change. Knows everyone a sample or a link in the web. Thanks A beginner Daniel Daniel, If it is indeed the case that you have successfully created and called a DLL, you are close to your target. You want to check AFX_MANAGE_STATE. If you look t...

Monitor MFC Executable
I have an application that runs 24 hours a day. The problem I have is that it is crashing at random times, e.g 18 hours of usage, 44 hours of usage etc and when it crashes it leaves no message/error box/information. When I start my application, I kill explorer so that the desktop cannot be accessed. Could this be causing the crash in some way? The first time I have started my app by using the debug exe, which reported an error in the event viewer as shown below:- " The Instruction at "0x6dee 14ba" referenced memory at "0x025b8348". The memory could not be &quo...

VC++ MFC to VC++ 7.0 w/ MFC 7
This is a multi-part message in MIME format. ------=_NextPart_000_002E_01C3D9AD.F0EEB050 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm in the process of moving my code base to Visual Studio .Net 2003 = using VC++ w MFC 7.0. The code complies correctly but the linker is not = resolving what appears to be CString entry points, e.g.,=20 CookieField.obj : error LNK2019: unresolved external symbol "public: = void __thiscall CString::MakeLower(void)" (?MakeLower@CString@@QAEXXZ) = referenced in function "protected: vo...

Run SQL Script from Console application
Hello, Is it possible to run a SQL script from a C# Console application? Thanks, Miguel shapper wrote: > Hello, > > Is it possible to run a SQL script from a C# Console application? > Yeah, you make an sproc that contains the script and execute the sproc in the console application using ADO.NET SQL Command object. shapper wrote: > Hello, > > Is it possible to run a SQL script from a C# Console application? > Sure, there isn't any reason why the choice of user interface would affect what libraries you can use. On Nov 17, 10:11=A0pm, &...

Calling an Event in MFC ActiveX
I'm trying to call an event from another class. I get these errors when building: ---------------------------------------------------------------------------- ---- MyConnMngr.cpp(41) : error C2248: 'FireOnConnected' : cannot access protected member declared in class 'CXCtrl' CXCtl.h(65) : see declaration of 'FireOnConnected' MyConnMngr.cpp(41) : error C2352: 'CXCtrl::FireOnConnected' : illegal call of non-static member function CXCtl.h(65) : see declaration of 'FireOnConnected' -------------------------------------------------------...