none
About set user-agent RRS feed

  • Pertanyaan

  • I'm sorry for my poor English. In My win32 application, it's a custiom browser, I wanted change http head use agent, coding like this:


    STDMETHODIMP CAXwindow::Invoke( DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexecinfo, unsigned int* puArgErr )
    {

      switch (dispid)
     {
     case DISPID_AMBIENT_USERAGENT:
      {
       BSTR vtUserAgent=SysAllocString( L"test app");

       VARIANT varUserAgent;
       varUserAgent.vt = VT_BSTR;
       varUserAgent.bstrVal = vtUserAgent;
       pvarResult = &varUserAgent;
       return S_OK;
      }

    ... ...

    }

    this codes can be loaded when the app is run.But the http head user-agent not contain the "test app" information,why?

    Best regards.

     

    Senin, 20 September 2010 06.31

Semua Balasan

  • 这不是一个和Web开发相关的问题。你的pvarResult= &varUserAgent;很有问题。varUserAgent是一个位于栈上的变量,把它的地址直接传出去是不正确而且是非常危险的。正确的做法应该是初始化*pvarResult然后直接向pvarResult赋值。

    Jumat, 10 Desember 2010 11.31