ATL component freezes after destructor

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: TxITGuy (txitguy.nospam_at_earthlink.net)
Date: 03/10/05


Date: Thu, 10 Mar 2005 09:53:06 -0800

This is my first ATL project, and I am encapsulating the WinInet API in a
DLL. So far, everything is working fine ... until I try to unload the DLL
from the test console.

At that point, it calls the destructor function, which clears the callback
function for each cached handle and then closes the handle. This runs
completely without error. Then it goes into assembly code and runs until it
hits "JMP 70ABB2B6", at which point it completely stops executing anything.
I have to use the "Stop Debugging" command to get out of it.

So far, it only fails this way if I call the following method while testing
the component. This method also completes without error, and in stepping
through the code it appears to correctly release all the resources it uses.

STDMETHODIMP CHTTP::GetRequest(BSTR sDomain, BSTR sDocument, BSTR
sQueryString, BSTR sAccept, BOOL bSecure)
{
        char *lpszDomain = _com_util::ConvertBSTRToString(sDomain);
        char *lpszDocument = _com_util::ConvertBSTRToString(sDocument);
        char *lpszQueryString = _com_util::ConvertBSTRToString(sQueryString);
        char *lpszAccept = _com_util::ConvertBSTRToString(sAccept);
        char **lplpszAccepts = NULL; //variable to hold "Accepts:" string array.

        unsigned int uiRows = 0;
        BOOL bRequestSent = FALSE;
        HINTERNET hSession;
        HINTERNET hRequest;
        DWORD dwErrorNum;
        char sError[200] = "";

        m_bSecure = bSecure;

        if(!m_bOpen) return Error("HTTP class not ready, please call Open
method.",GUID_NULL,0xE0000003);

        hSession = GetInetSession(lpszDomain,INTERNET_SERVICE_HTTP,80);

        //assemble and save the current URL string.
        SetCurrentURL((const char *) lpszDomain,(const char *) lpszDocument,
bSecure);

        //concatenate document and querystring for HttpOpenRequest
        CComBSTR sResource;
        sResource.Empty();
        sResource.AppendBSTR(sDocument);
        sResource.AppendBSTR(sQueryString);
        char * lpszResource = _com_util::ConvertBSTRToString(sResource.m_str);

        if(split(lpszAccept,',',&lplpszAccepts,&uiRows))
        {
                //convert "Accepts:" string array to a constant pointer for API.
                hRequest =
HttpOpenRequest(hSession,"GET",lpszResource,"HTTP/1.1","",(const char**)
lplpszAccepts,INTERNET_FLAG_PRAGMA_NOCACHE,(DWORD) this);

                if(hRequest != NULL)
                {
                        bRequestSent = HttpSendRequest(hRequest,0,0,0,0);

                        if(bRequestSent)
                        {
                                freearray(lplpszAccepts,uiRows);
                                return S_OK;
                        }
                        else strcat(sError,"Unable to send request.\r\n");
                }
                else strcat(sError,"Unable to open request.\r\n");

                dwErrorNum = GetLastError();
                strcat(sError,InetErrorDesc(dwErrorNum));
        }
        else
        {
                dwErrorNum = 0xE0000002;
                strcat(sError,"Insufficient memory to complete requested operation.");
        }

        freearray(lplpszAccepts,uiRows);
        return Error(sError,GUID_NULL,dwErrorNum);
}

I'm probably missing something simple here about how to unload a COM DLL
properly. Any help will be greatly appreciated.

Thanks,
Ben



Relevant Pages

  • how to change application base in a mixed com dll?
    ... I have a strange situation and I hope that somebody has ... but the interop system does not handle well the BSTR ... This dll does work. ... It seems like the com object inheriths the AppBase path from the ...
    (microsoft.public.dotnet.framework.interop)
  • Re: about casting
    ... The COM dll that we use is an very old product that was developed for many ... Below you see a signature for method InitRules2 which is a method that is ... BSTR DataSource, BSTR UserId, BSTR Password, BSTR ProductID, BSTR ... Before trying to create some "automatic" code using ATL wizards of Visual ...
    (microsoft.public.vc.mfc)
  • Re: How are strings returned to VB from a C DLL?
    ... Not in the case of BSTR. ... In such a case the actual string manager is OLE, ... For example, you can run into issues with a 'BSTR' in a regular DLL, and OLE ...
    (microsoft.public.vb.general.discussion)
  • Re: howto get c++ strings from visual basic dll
    ... DLLs in VB are almost always ActiveX. ... Navigate to the folder containing the .dll, ... You'll see a list of resources, right-click on TYPELIB ... You'll see the strings declared as BSTR or BSTR pointers. ...
    (microsoft.public.vc.ide_general)
  • Newbee Question: How to return an void* in a VARIANT parameter?
    ... I was told to develop an activeX to wrapper function calls to an c+ ... + dll, in order to make this dll useful to VB 6 applications. ... this dll implements the factory design pattern and these ... STDMETHODIMP CCRS::OpenConfiguration(BSTR tpCtrl, BSTR tpPersist, ...
    (microsoft.public.vc.atl)