Problem sending image from ASP to C++ application

L

Lee

I am having a problem returning an image that I got from SQL Server from
within an ASP page that got requested from a VC++ application.
Specifically, within my application, I make an HTTP call to my IIS server to
an ASP. The ASP then queries a SQL Server and the field that I want to
return from the resulting Recordset is an image. In the application, I then
make a call to receive the response from the web page but am having no luck
getting anything back. I have included both the ASP page and the code from
wthin the VC++ application. The part in the C++ code that I am debuggin and
noticing that nothing has returned is the while loop that is reading the
CInternetFile.

I hope this is enough for anyone that feels like helping me. In advance,
thanks very much.

Lee

ASP page:
<%
Dim objConn, objRS
Dim strConnect

Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdTable = 2

Set objConn = Server.CreateObject ("ADODB.Connection")
Set objRS = Server.CreateObject ("ADODB.RecordSet")

objConn.Open "ODBC", "sa", ""

strFilter = "ID=" & Request.QueryString ("ID")

'Response.Write ( strFilter )
objRS.Filter = strFilter
objRS.Open "Pic", objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable

If Not objRS.EOF Then
Response.Write ( objRS("Pic") )
Else
End If

objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing

%>


VC++ code:

void GetPicture(CString ID, unsigned long *ulPicLen, byte **bytePic)
{
CString strURL = "http://";
strURL += theApp.HostName;
strURL += "//GetPicture.asp";
strURL += "?ID=";
strURL += ID;

*ulPicLen = -1;
int nRetCode = 0;
DWORD dwAccessType = PRE_CONFIG_INTERNET_ACCESS;
const TCHAR szHeaders[] = _T("Accept: */*\r\nUser-Agent: PDA\r\n");
DWORD dwHttpRequestFlags = INTERNET_FLAG_NO_AUTO_REDIRECT;
BOOL bSuccess = TRUE;

CPerimeterSecurityHttpSession session(_T("HTTP"), (DWORD)this,
dwAccessType);
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;

// check to see if this is a reasonable URL
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;

if (!AfxParseURL(strURL, dwServiceType, strServerName, strObject, nPort) ||
dwServiceType != INTERNET_SERVICE_HTTP)
{
return;
}

session.EnableStatusCallback(TRUE);

pServer = session.GetHttpConnection(strServerName, nPort);

pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject,
NULL, (DWORD)this, NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(szHeaders);

pFile->SendRequest(NULL, 0, NULL, 0 );

DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);

if (dwRet == HTTP_STATUS_DENIED)
{
TRACE0 ("Access to the secured http site is denied!");
return;
}

int ndx = 0;
char *szWEBPage[MAX_WEBPAGE_SIZE+1];
char *sz[BUFFER_SIZE];
int iCurrentRead = 0;
int iTotalRead = 0;
pFile->SetReadBufferSize(BUFFER_SIZE*2);

while ( iCurrentRead = pFile->Read (sz, BUFFER_SIZE ) )
{
memcpy ( &szWEBPage[iTotalRead], sz, iCurrentRead );
iTotalRead += iCurrentRead;
}
*ulPicLen = iTotalRead;
*bytePic = new byte [ *ulPicLen ];
memcpy ( *bytePic, szWEBPage, *ulPicLen );

pFile->Close();
pServer->Close();

if (pFile != NULL)
delete pFile;
if (pServer != NULL)
delete pServer;
session.Close();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top