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
1439 Views

Similar Articles

[PageSpeed] 49

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:

MFC Database programming
Hi! I have an MFC project, which use an MS-ACCESS db. is there any control, which brings capability the same as DataGrid of a Windows Form, to Dialog forms of MFC? Okay, I've been searching for a control that you can use instead of the DataGrid and I think the "Microsoft FlexGrid control version 6.0" will work. Just add it to your toolbox (right_click then costumize_toolbox...) and try it. You can useIf not, you can use the DataGrid control and all the .Net frame Libraries but with the managed C++ language extention in a Windows Forms Application (.Net) and not an...

MFC App nor handling std::exception
Hi, Im using VS 2005. I have an MFC app using a few classes that solely use STL etc. Some of these throw exceptions of std::exception type, but MFC is not handling these? In debug mode it breaks where exception thrown with message about 'unhandled exception at....' What is my problem? Thanks in advance. PRMARJORAM wrote: > Hi, > > Im using VS 2005. > I have an MFC app using a few classes that solely use STL etc. > Some of these throw exceptions of std::exception type, but MFC is not > handling these? > > In debug mode it breaks where exception thrown...

MFC Dlls between VS 6, and VS 7.1
Hi there, quick question about MFC dlls. If I compile a simple "hello world" app in Visual C++ 6, and I type in at the command prompt: dumpbin /dependents hello.exe I get a list of the DLLs that hello.exe depends on: MFC42.DLL MSVCRT.dll KERNEL32.dll USER32.dll GDI32.dll COMCTL32.dll OLEAUT32.dll I do not have visual studio.net installed on my machine (yet). Could someone compile a simple MFC hello world app using VS 7.1 and see what DLLs it depends on using dumpbin? I'm asking because I know my clients only have MFC42.dll on their machines and I...

Advanced GUI library for MFC-based application
My company is looking now for an advanced GUI library to make its product's look and feel modern and fresh. We used the Stingray library up to now, but it is not satisfy our needs any more. Can anybody provide me with information about available libraries? I use Xtreme Toolkit Pro from CodeJock (www.codejock.com) and it works really well. They just recently added Office 2003 look and feel to the list of themes. It's a little pricey, but it saves enough in programming time to make up for the price pretty quickly. There are some free libraries on www.codejock.com and www.code...

MFC and OSX?
We're getting ready to do a Mac OSX port of our MFC applciation, and managaement wants to consider a direct port, via some sort of framework that will use MFC code to create native OSX binaries. Are there any toolkits that willl support Windows code in a Mac environment? Please note that - I am not asking about emulators (WINE, etc); these are known quantites and not what we're asking about. - No need to mention the ancient and execreble Mac toolkit that Microsoft produced in the 4.x days; I've used it; it's not relevant. TIA -- Jim Johnson My Mac programmer say: *...

HELP: MFC ODBC SQL Server problems
I got a problem where in SQL Server a table has a column of type REAL & size (precision) 4. It's meant to store double types for C++ variable values. In SQL Server, the value 1E+10 translates to 10000000000 in C++ fine, via MFC's CRecordset class (DBCORE.CPP). However any numbers above this value translates to wrong numbers. Such as: 1.1E+10 => 10000000512 1.00001E+10 => 10000001024 1.01E+10 => 10099999744 1.0000001E+10 => 10000100352 Strange huh? Has anybody experienced this before? Does anyone know what is wrong? I tried upgrading my SQL Server 2000 to SP4 and ...

Generate Controls Dynamically,FormView-Scroll,Default,MFC
Hai I am looking to generate Edit controls Dynamically in a FormView and when the no of edit controls increases the Size Of the Horizantal ScrollBar increeases and should be able to scroll and is there any other way of doing other that "SetScrollSizes" as i want the FormView to handle that scrolling and not forcibly Thanks and Regards suresh suresh at his best wrote: > Hai > I am looking to generate Edit controls Dynamically in a FormView and when > the no of edit ...

Tab order under MFC?
I created some controls (CButtons) with the WS_TABSTOP style but in spite of this, nothing happens when I use TAB and Shift-TAB. Am I expecting a bit too much automation (A la VB), perhaps instead I have to build this logic myself by trapping the keys using OnKeyDown? I am not using the wusiwug dialog editor in VS, so modifying the order of my controls in the .res file is not an option! And finally, making a CButton control default by the BS_DEFPUSHBUTTON syle doesn't seem to have much effect either except for the raised/marked visual style. Do I likewise have to control this myself by t...

MFC under VS2010
I am about to finally *commit* product porting and new development under VS20xx. Currently have VS2005 and successfully recompiled all our projects and MFC applications. 139 of 150 projects in total where moved over. But we never felt good to release it as an update. About VS2010, we definitely going to upgrade to it, and I heard it is the "new VC6 (VS98)" - that excited me. I am not like going to waste time downloading the RC and go thru any hassles installing it. Can people with VS2010 now tell me about about their experiences and reality? Such as: I didn&...

some very strange MFC source code, if not a bug
I see some very strange code in MFC source code like below, CMiniDockFrameWnd::CMiniDockFrameWnd() : m_wndDockBar(TRUE) { m_wndDockBar.m_bAutoDelete = FALSE; } but m_wndDockBar is an object of CDockBar with the a derived class of CControlBar which is derived from CWnd. I think it's very strange to use TRUE to initialize a CDockBar. Any explanations? It is initializing a CDockBar object using the CDockBar(BOOL bFloating = FALSE); constructor. -- Cheers Check Abdoul ------------------ "Fei Xu" <FeiXu@discussions.microsoft.com> wrote in message news:...

black buttons in mfc application under XP
hi, I have some severe problems with CButtons under XP in XP windows themes style. Since I positioned them with DeferWindowPos then sizing a non modal dialog they are all drawn black. Any hints how get the system to display them normally? Thanks Ilmari ...

MFC to launch MsDev
I am running MsDev 7.1 I would like to from a MFC project use automation to launch MsDev then load a text file etc... The problem is that when I use the 'Add Class' and select 'MFC Class from Typelib' and then choose 'Microsoft Development Environment 7.0' type library I cannot determine what interface to generate the class for. There is no _Application interface or similar like there is for each of the Office applications. MSDN documentation regarding MsDev automation has not been updated (shame!), and I am at a loss. Ideas? - Marty ...

how to include "commctrl.h" in a MFC project?
i want to use BTNS_WHOLEDROPDOWN which is defined in commctrl.h , and i add #include "commctrl.h" in my MainFrm.cpp , but the compiler still say BTNS_WHOLEDROPDOWN is undeclared . alex, You need to define _WIN32_IE with value 0x0500 and then include commctrl.h #define _WIN32_IE 0x0500 For more info take a look at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla tform/commctls/toolbar/styles.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla tform/shell/programmersguide/versions.asp -- Regards, Kobi Ben Tzvi "...

MFC Dlls #2
Hi I was written an MFC EX. DLL and use in MFC App - it's working OK, But when I want to use it in C# ( C Style export ) it crash. Why? Thanks Koby Because it is an MFC Extension DLL. This makes a lot of assumptions about the environment in which it is running, which would not be true in a C# environment. Converting it to a conventional (non-extension) DLL should solve the problem. joe On Sat, 17 Jan 2004 11:54:55 -0800, "Koby" <anonymous@discussions.microsoft.com> wrote: >Hi >I was written an MFC EX. DLL and use in MFC App - it's >working OK, >...

Automating Excel with MFC
Hi, I wrote the following function: --------------------------------------------------------- HRESULT CExcelIF::OpenXLApplication(BOOL a_bVisible) { try { _ApplicationPtr pXL("Excel.Application"); m_pXL = pXL; if(a_bVisible) m_pXL->Visible = VARIANT_TRUE; else m_pXL->Visible = VARIANT_FALSE; char buf[256]; GetCurrentDirectory(sizeof(buf), buf); m_pXL->DefaultFilePath = buf; pXL = NULL; g_pLog->WriteLine("Opened Excel"); return S_OK; } catch(_com_error &e) { dump_com_error(e); return S_FALSE; } } ------------...

MFC List View Control Dragging Problem
Hi All, Our application is using two different list controls to view data. 1) ResultList 2) BatchBuilder The ResultList control contains different item columns and the data from ResultList can be dragged to the BatchBuilder control, using the MFC Drag and Drop mechanism. Everything is working fine with dragging, with the exception in the first column in the ResultList control. When i try to drag the items from the ResultList columns from Right to Left or straight down the bottom, the dragging is being done properly, but when i try to drag the items from Right to Left, instead of getting d...

MFC naming conventions
What is WM in WM_MOUSEMOUSE, BN in BN_CLICK? Any paper on this thing? -- @~@ Might, Courage, Vision, SINCERITY. / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (Xubuntu 8.04.1) Linux 2.6.26.5 ^ ^ 12:46:01 up 21:36 1 user load average: 1.26 1.27 1.21 ? ? (CSSA): http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa/ Man-wai Chang ToDie (33.6k) wrote: > > What is WM in WM_MOUSEMOUSE, BN in BN_CLICK? Any paper on this thing? > AFAIK, WM stands for Windows Message. BN stands for Button. Regards, Fernando. Fernando A. G�mez F...

MFC error messages
I'm trying to do the following: try { CFile f("somefilename.txt"); .... } catch( CException* e ) { char ebuff[1000]; e->GetErrorMessage(ebuff, sizeof(ebuff)); MessageBox( ebuff ); } (stripped down to its bare essentials) But when I do, the message box is always empty. Tracing it, the call to LoadString using the AfxGetResourceHandle, is always empty. Is there something I'm supposed to do to add the MFC error strings to my statically linked project? -- Jonathan Arnold inSORS "Jonathan Arnold" <jdarnold_online@insors_comm.com> wrote ...

adding FlatAPI Interface to an existing MFC Application
Hi, i'm trying to add a flat API Interface (normal Windows Dll with flat function interface) to an existing MFC Application. Although i added an exports.def file witch should help mapping the function, the exportname is like '?Fuu@@YAHXZ' and not like wanted map to only 'Fuu'. thanks in advance, Klaus Klaus Leppkes schrieb am 23.11.2007 17:17: > Hi, > > i'm trying to add a flat API Interface (normal Windows Dll with flat > function interface) to an existing MFC Application. > > Although i added an exports.def file witch should help mapping th...

Running Graph Query MFC?
Hi I want to implement the <<Windows Task Manager->Performance->cpu Usage History>> in my application. How can i achieve this? Plz provide suggestions? Regards ...

Linking Dialogs to Existing MFC Classes
Hi, I am trying to write an MFC application from 'scratch'. I created an empty Windows application, and linked it to the shared MFC libraries. I created derived classed from CWinApp and CDialog, and a dialog in Studio. I linked the dialog class to the dialog in the CDialog constructor. Problem is, the dialog is not linked to the class in Studio. That is, I can't double click on a button in the dialog editor and get the event handler code. I just get the MFC Class Wizard. This doesn't help me, because the class already exists, I don't want a new one. In any event, even if I...

STL iterators for MFC collections
Has anyone written STL-style iterators for the MFC collections CArray, CList, CMap? Can you point to any freely available implementations? Eric B Eric Beyeler wrote: > Has anyone written STL-style iterators for the MFC collections CArray, > CList, CMap? Can you point to any freely available implementations? > I've seen such adaptors at http://synesis.com.au/software/mfcstl/ (note that I've never actually used that library, so I can't say much about it) -- Regards, Tobias Tobias G�ntner <fatbull@users.sourceforge.net> wrote in message news:<cg31og$5ib$07$1@...

Good MFC Book
I have taken a few courses on C/C++ but they never taught me how to make programs with real GUI. We always used the command prompt. So I've decided that I'd like to learn to use MFC. I have noticed that there are several MFC tutorials and articles online, but I'm really looking for some suggestions on a good book. Nothing aginst the online versions, but they can be rough on they eyes after a while. Can anyone give me a few good book suggesions? I have an excellent understanding of C/C++ control structures, classes, etc. so I am looking for a book that goes right into the g...

MFC version
I use Visual C++ to develop for windows platform. I want to get the version of MFC. How do I do? Thanks. Regards, Miken _____________________________________________________ http://www.msale.net/bbs/ a Chinese-language message board for developers,including palm,ppc,symbian,and etc. http://www.zirong.net/blog/ my private life "Miken" <mikenwonder@msn.com> wrote in message news:OkFShqKPFHA.3156@TK2MSFTNGP15.phx.gbl... >I use Visual C++ to develop for windows platform. > I want to get the version of MFC. > How do I do? > > Thanks. > > > > Regar...

including Managed code ( /CLR ) in MFC app
Hi there, Since I added the managed code ( /CLR ) in my MFC app, in order to use System namespace , every thing is really really slow. Just launching the app takes more than 10 seconds, and opening a "file load/save dialog box" around 5 seconds. Is this "normal", or did I do something wrong? Thanks Using VS2003? Even without using managed code, I find the launching to take far too long, and a file load/safe to take far too long, because it wastes massive amounts of time loading symbols it will never use, for purposes that make no sense whatsoever. joe On Fri, 20 ...