Hi,
Greetings...
I have a document view application. View is displaying pdf document with the help of CHTMLCtrl which is editable and as soon as user gives command to save data, following method called to get data from view.
void getDataFromPDF(CHTMLCtrl &mView)
{
HRESULT hr;
IDispatch* pDispatchDoc = NULL;
bool cont=true;
int count=0;
while(cont && count<100)
{
count++;
pDispatchDoc = mView.GetHtmlDocument();
if(pDispatchDoc != NULL)
{
IHTMLDocument2* pHTMLDocument2 = NULL;
hr = pDispatchDoc->QueryInterface( IID_IHTMLDocument2, (void**)&pHTMLDocument2 );
if(hr == S_OK)
{
IHTMLElementCollection* pElementCollection = NULL;
hr = pHTMLDocument2->get_all(&pElementCollection);
if( hr == S_OK && pElementCollection != NULL )
{
VARIANT varName;
varName.vt = VT_BSTR;
BSTR bs=T2BSTR(L"MsgRsp1");
varName.bstrVal = bs;
VARIANT var2;
VariantInit(&var2);
IDispatch* pDispatchElement = NULL;
hr = pElementCollection->item( varName, var2, &pDispatchElement );
if( (hr == S_OK) && (pDispatchElement) )
{
IHTMLInputHiddenElement* pElement = NULL;
hr = pDispatchElement->QueryInterface( IID_IHTMLInputHiddenElement, (void**) &pElement );
if(hr == S_OK)
{
BSTR bstrTXT;
hr=pElement->get_value(&bstrTXT);
pElement->Release();
if(hr == S_OK)
{
m_strFormData= bstrTXT;
if(wcscmp(m_strFormData,L"--"))
{
cont=false;
hr=pElement->put_value((BSTR)"--");
}
::SysFreeString( bstrTXT );
}
}
pDispatchElement->Release();
}
pElementCollection->Release();
}
pHTMLDocument2->Release();
}
pDispatchDoc->Release();
if(cont) Sleep(20);
AfxPumpMessage();
}
}
TRACE("Printing\n");
TRACE(m_strFormData);
TRACE("\n");
}
At very first instance, it is giving correct data but during second attempt when user modified form, data retrieved by getData method is old one (whatever in first command).
Third time, it again gives data of previous attempt (second command).
I have searched through internet to solve the issue but did not found anything relevant.
Please help resolve the issue.
Thanks
Vishal
What I have tried:
http://www.tenouk.com/visualcplusmfc/visualcplusmfc35.html
http://stackoverflow.com/questions/14719345/retrieve-html-source-from-chtmlview-visual-studio-6
https://msdn.microsoft.com/en-us/library/bb250491(v=vs.85).aspx
http://www.mctainsh.com/Articles/MFC/CHtmlCtrl.aspx