Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can i post data to certain ASP Page(using IWebBrowser2)

0 views
Skip to first unread message

tae jin yoon

unread,
Jan 21, 2002, 9:57:53 PM1/21/02
to

I make my own BHO,.. but i want to post data to certain
ASP Page ... so i search msdn sample but that do not work
properly...

please help me....

here is my source sample !!

/******************/
void CHook::GoX()
{
CComVariant vtEmpty;
VARIANT vFlag = {0};
VARIANT vFrame = {0};

BSTR url = NULL;
BSTR head = NULL;

url = SysAllocString
(L"http://192.168.0.42/GEN/test3.asp");
head = SysAllocString(L"Content-Type:
application/x-www-form-urlencoded\r\n");
VARIANT vurl,vhead;

V_VT(&vhead) = VT_BSTR;
V_BSTR(&vhead) = head;

V_VT(&vurl) = VT_BSTR;
V_BSTR(&vurl) = url;

VARIANT vArray = {0};

HRESULT hr = GetPostData(&vArray);
hr = m_spWebBrowser2->Navigate
(url,&vFlag,&vFrame,&vArray,&vhead);
}


HRESULT CHook::GetPostData(LPVARIANT pvPostData)
{
HRESULT hr;
LPSAFEARRAY psa;
LPCTSTR cszPostData = "KEY=SM&DIV=1&OLD=MS";
UINT cElems = lstrlen(cszPostData);
LPSTR pPostData;

if (!pvPostData)
{
return E_POINTER;
}

VariantInit(pvPostData);

psa = SafeArrayCreateVector(VT_UI1, 0, cElems);
if (!psa)
{
return E_OUTOFMEMORY;
}

hr = SafeArrayAccessData(psa, (LPVOID*)
&pPostData);
memcpy(pPostData, cszPostData, cElems);
hr = SafeArrayUnaccessData(psa);

V_VT(pvPostData) = VT_ARRAY;

V_ARRAY(pvPostData) = psa;
SafeArrayDestroy(psa);
return NOERROR;
}

Igor Tandetnik

unread,
Jan 22, 2002, 11:56:09 AM1/22/02
to
1) The type of the variant containing an array should be VT_UI1 |
VT_ARRAY. VT_ARRAY is only a flag modifying base type.

2) It makes no sense destroying an array right after you stuff it into a
variant. GetPostData should not destroy it, GoX should - after it has
used it in a call to Navigate. While you are at it, you are also
supposed to free all those BSTRs you have allocated. Just do
VariantClear on all variants.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"tae jin yoon" <hope...@vuemetric.com> wrote in message
news:c52501c1a2f0$9601b6b0$b1e62ecf@tkmsftngxa04...

tae jin yoon

unread,
Jan 22, 2002, 8:02:59 PM1/22/02
to
thanks for your advise .....

but i correct my fault . but that is not working......
so i modify my source...

Navigate(url,&vFlag,&vFrame,&vArray,&vhead);

vFlag : 0x01(New Window)---> Working but Acess Violation
vFrame :(_SELF,_TOP,...)--> Post Working but Acess
Violation

um.....

Now I don't Know What I have to do.....

please help me....


Igor Tandetnik

unread,
Jan 23, 2002, 9:50:55 AM1/23/02
to
What do you mean, working but Access Violation? That's an oxymoron if
I've ever seen one.

What is not working, and in what way? How did you modify your source?
How do you set up vFlag and vFrame? How do you expect me to help you
based on the scant information you provide?


--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"tae jin yoon" <hope...@vuemetric.com> wrote in message

news:bfda01c1a3a9$b3856970$9ee62ecf@tkmsftngxa05...

yoon tae jin

unread,
Jan 23, 2002, 9:57:41 PM1/23/02
to
sorry for my rudness!!

here is my full source....

please advise to me.....

I want to Know How can I Post Data To certain ASP Page with current IE....

* source *
STDMETHODIMP CHook::Invoke(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams,
VARIANT* pvarResult,
EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
USES_CONVERSION;

if (!pDispParams)
return E_INVALIDARG;

switch (dispidMember)
{
case DISPID_BEFORENAVIGATE2:
// strEventInfo << "BeforeNavigate2: ";
if (pDispParams->cArgs >= 5 && pDispParams->rgvarg[5].vt ==
(VT_BYREF|VT_VARIANT))
{
CComVariant varURL(*pDispParams->rgvarg[5].pvarVal);
_variant_t v_url = (_variant_t)varURL;


CString s_url = CString((char*)(_bstr_t)v_url);
CString Dest;

v_url.Clear();
varURL.Clear();

BOOL res = IsNumber(s_url); /* Decide Number Keyword Or
Other*/

if(res)
{
CString NumKey = s_url.Right(s_url.GetLength()-7);
NumKey = NumKey.Left(NumKey.GetLength()-1);


Dest.Format("http://mycom/Resolve/Resolve.asp?KEY=%s&DIV=2&ORG=%s",NumKey,Nu
mKey);

bHook = TRUE;

m_spWebBrowser2->Stop();

Navigate(Dest);

}
else
{

if(s_url.Left(26) == "http://auto.search.msn.com")
{

CString Key;
CString Org;
BOOL res = this->IsEngKey(s_url,Key,Org);
/* Korean KeyWord Or English Keyword */

if(res)

Dest.Format("http://mycom/Resolve/Resolve.asp?KEY=%s&DIV=1&ORG=%s",Key,Org);
else

Dest.Format("http://mycom/Resolve/Resolve.asp?KEY=%s&DIV=0&ORG=%s",Key,Org);

bHook = TRUE;
m_curKey = Key;
m_curOrg = Org;
Navigate(Dest);

}
}

s_url.Empty();

}
break;

case DISPID_ONQUIT:
ManageConnection(Unadvise);
break;

default:
break;

}
}


void CHook::Navigate(CString & szURL)
{
#define _TJ_POST_

#ifndef _TJ_POST_

/* GET Test*/
CComBSTR bstrURL(szURL);

CComVariant vtEmpty;

m_spWebBrowser2->Navigate(bstrURL, &vtEmpty, &vtEmpty,
&vtEmpty/*Post Data부분*/, &vtEmpty);
return;
#else
// POST로 넘기기위해 url,key,divcode,oldkey의 파라미터를 받는다고
가정한다
/* Post Test */


CComVariant vtEmpty;
VARIANT vFlag = {0};
VARIANT vFrame = {0};

BSTR url = NULL;
BSTR head = NULL;

BSTR target = NULL;

target = SysAllocString(L"_SELF");
url = SysAllocString(L"http://mycom/GEN/test3.asp");


head = SysAllocString(L"Content-Type:
application/x-www-form-urlencoded\r\n");

VARIANT vurl={0},vhead={0};

// header setting

V_VT(&vhead) = VT_BSTR;
V_BSTR(&vhead) = head;

// url setting


V_VT(&vurl) = VT_BSTR;
V_BSTR(&vurl) = url;

// new window Flag Setting
V_VT(&vFlag) = VT_I4;
V_I4(&vFlag) = 0x01;

// Name Setting !!
V_VT(&vFrame) = VT_BSTR;
V_BSTR(&vFrame) = target;

VARIANT vArray = {0};

// post data setting
HRESULT hr = GetPostData(&vArray);

m_spWebBrowser2->Quit();

hr = m_spWebBrowser2->Navigate2(&vurl,&vFlag,&vFrame,&vArray,&vhead);

LPSAFEARRAY psa = (LPSAFEARRAY)vArray.parray ;

/* Clear Routine */

// VARIANT Clear

VariantClear(&vArray);

// BSTR Clear
if(url) SysFreeString(url);
if(head) SysFreeString(head);
if(target) SysFreeString(target);

// SafeArray Clear
if(psa)
{
SafeArrayDestroy(psa);
psa = NULL;
}

#endif

#undef _TJ_POST_

return ;
}


HRESULT CHook::GetPostData(LPVARIANT pvPostData)
{
HRESULT hr;
LPSAFEARRAY psa;
LPCTSTR cszPostData = "KEY=SM&DIV=1&OLD=MS";
UINT cElems = lstrlen(cszPostData);
LPSTR pPostData;

if (!pvPostData)
{
return E_POINTER;
}

VariantInit(pvPostData);

psa = SafeArrayCreateVector(VT_UI1, 0, cElems);
if (!psa)
{
return E_OUTOFMEMORY;
}

hr = SafeArrayAccessData(psa, (LPVOID*)&pPostData);
memcpy(pPostData, cszPostData, cElems);
hr = SafeArrayUnaccessData(psa);

V_VT(pvPostData) = VT_ARRAY | VT_UI1;

V_ARRAY(pvPostData) = psa;
return NOERROR;
}

0 new messages