InetHttpSendBitmap example for C++ 5.0 and later
1. |
Start with the project you created in InetHttpSendForm example for C++ 5.0 and later |
||
2. |
Add a command buttons to the Tutor dialog and name it as follows: |
||
|
ID |
Caption | |
|
IDC_HTTP_BITMAP |
HTTP Bitmap | |
3. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
||
|
a. |
Click the Message Maps tab. |
|
|
b. |
In the Class Name combo box, select CTutorDlg. |
|
|
c. |
In the Object IDs list box, select IDC_HTTP_BITMAP. |
|
|
d. |
In the Messages list box, select BN_CLICKED. |
|
|
e. |
Click the Add function button. Choose OK for the default function name (OnHttpBitmap). |
|
|
f. |
Click the Edit Code button and enter the following code: (you will have to change the IP address to a valid server name or address) |
void CTutorDlg::OnHttpBitmap()
{
short nRet;
nRet = m_pRasterHTTP->InetHttpConnect
("demo.leadtools.com", 80, "", "");
if(nRet == 0)
{
nRet = m_pRasterHTTP->InetHttpOpenRequest (HTTP_RQST_POST,
"/com/tutorial/http/upload.asp", "", "HTTP/1.0");
if(nRet == 0)
{
INAMEVALUEItem* nv=NULL;
CoCreateInstance(CLSID_NAMEVALUEItem,
NULL, CLSCTX_ALL, IID_INAMEVALUEItem, (void**)&nv);
if(!nv)
{
AfxMessageBox(TEXT("Error
creating Name/Value item"));
m_pRasterHTTP->InetHttpCloseRequest ();
m_pRasterHTTP->InetHttpDisconnect ();
return;
}
nv->pszName =
TEXT("Photo");
nv->pszValue =
TEXT("photo1.jpg");
nRet = m_pRasterHTTP->InetHttpSendBitmap (m_LEADRasView1.GetRaster(),
FILE_JFIF, 24, 200, "image/jpg", nv);
nv->Release();
if(nRet != 0)
{
AfxMessageBox(TEXT("Error
Sending Image"));
m_pRasterHTTP->InetHttpCloseRequest ();
m_pRasterHTTP->InetHttpDisconnect ();
return;
}
long nStatus;
m_pRasterHTTP->InetHttpGetServerStatus
(&nStatus);
_bstr_t szResponse
= m_pRasterHTTP->InetHttpGetResponse
();
if(nStatus == HTTP_STATUS_OK)
{
FILE
* fp = _tfopen(TEXT("c:\\output.htm"), TEXT("wb"));
if(fp)
{
fwrite((TCHAR
*)szResponse, szResponse.length(), 1, fp);
fclose(fp);
}
}
else
{
AfxMessageBox(TEXT("Problem
With Server"));
FILE
* fp = _tfopen(TEXT("c:\\error.htm"), TEXT("wb"));
if(fp)
{
fwrite((TCHAR
*)szResponse, szResponse.length(), 1, fp);
fclose(fp);
}
}
m_pRasterHTTP->InetHttpCloseRequest ();
}
m_pRasterHTTP->InetHttpDisconnect
();
}
}
4. |
Rebuild and run the application. |