Problem sending image from ASP to C++ application

Discussion in 'ASP General' started by Lee, Jul 10, 2003.

  1. Lee

    Lee Guest

    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();
    }
    Lee, Jul 10, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,321
  2. Luke
    Replies:
    2
    Views:
    4,662
    Nigel Wade
    Mar 15, 2007
  3. Santosh
    Replies:
    7
    Views:
    368
    Santosh
    Mar 26, 2007
  4. Peter Haider

    Problem by sending a fax via ASP Application

    Peter Haider, Aug 29, 2003, in forum: ASP General
    Replies:
    3
    Views:
    177
    Peter Haider
    Aug 29, 2003
  5. Ariel
    Replies:
    0
    Views:
    282
    Ariel
    Feb 1, 2012
Loading...

Share This Page