I have an MFC application with CWebBrowser embedded. I wanna post data when navigating to the specified web .
With some investigation around internet,
I get to know one argument of the Navigate method aims to pass it. But I try it out several times and always fail. The post data is not carried in the data traffic(Yes. I capture the data and check it) after navigate method is invoked.
I also check the post parameter of the before2Navigate calback and it's empty ..
Here is my snippet .
void PostData(LPCTSTR URL , LPCTSTR pPostData = NULL ) {
_variant_t flags(0L,VT_I4);
_variant_t target_frame_name("");
_variant_t post_data(!pPostData ? _T("") : pPostData) ;
_variant_t headers("Content-Type: application/x-www-form-urlencoded\r\n") ;
this->Navigate(URL ,&flags,
&target_frame_name,
&post_data,
&headers) ;
}
Please help me out . Thanks a lot.
I have found out the reason, that's caused by the incorrect type of PostData.
Construction of PostData ,as mentioned in my code, makes VT_BSTR VARIANT while the correct one is VT_ARRAY | VT_UI1
Here is the link for your reference hope it's helpful to you.
http://support.microsoft.com/default.aspx?scid=KB;en-us;q167658
One thing needs to be noted that the example of VS might has an defect and can not be used in unicode
Related
One of my tasks it to configure network adapters for DHCP/static IP, and the only way I found to do this is using Win32_NetworkAdapterConfiguration class.
WMI is new to me, and it seems to use it in C++ (Qt/MinGW) is not that easy, and most things I found in the WWW deal with .NET, PowerShell or VBScript. However, I already succeeded in querying information, for example the MAC address for a specific adapter.
I already read the MSDN: Calling a Provider method on MSDN, but in looking forware to WIn32_NetworkAdapterConfiguration there is one thing I don't unstand.
My IEnumWbemClassObject is the result of a SELECT * FROM Win32_NetworkAdapterConfiguration WHERE InterfaceIndex=n (n is a number, of course), and returns IWbemClassObject for the specific adapter.
How to I tell ExecMethod which instance of Win32_NetworkAdapterConiguration to use when calling the EnableDHCP()/EnableStatic() methods (in meaning of the IWbemClassObject I will recieve when i enumerate the result of my query)?
While looking for a example for passing string arrays to ExecMethod() if found this thread at CodeProject which execatly fit to my tasks. As stated in the comments above, the path of the object instance (not the class path!) must be passed to the "strObjectPath" parameter of ExecMethod.
I am trying to use an ActiveX control in my program.
QAxWidget* mAX = new QAxWidget();
mAX->setControl("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}");
I know that there is a function:
put_ChannelType(long newValue)
But when I try to execute it:
mAX->dynamicCall("put_ChannelType(long)",2);
mAX->dynamicCall("put_ChannelType(int)",2);
mAX->dynamicCall("put_ChannelType(long)",QVariant(2));
mAX->dynamicCall("put_ChannelType(int)",QVariant(2));
I get:
QAxBase: Error calling IDispatch member put_ChannelType: Bad parameter count
Any idea what is going wrong ?
EDIT:
Weird thing is if I call
mAX->dynamicCall("put_ChannelType()");
I do not get any error message...
EDIT 2:
This also fails (as Constantin suggested)
QList<QVariant> varlist;
varlist << (int)1;
mAX->dynamicCall("put_ChannelType(int)",varlist);
Got this solved using the generateDocumentation() function.
I was using this ActiveX control in another application, but an MFC one.
It seems the function names I was referring to (which were in a machine generated IDispatch wrapper class created by VS) were not the same as the ones Qt listed.
i.e. put_ChannelType is actually SetChannelType...
Maybe this is just a version issue ?
Anyways, important part is knowing that generateDocumentation() can list you all the functions you can call with dynamicCall.
Is it OK?
mAX->dynamicCall("put_ChannelType(const QVariant &)", (long)2);
I want to prevent IE from showing JS error dialogs, I read that it can be done by setting
ScriptErrorsSuppressed = true.
Where exactly do I set it in IWebBrowser2?
Thanks
Simply use put_Silent method.
m_pWebBrowser->put_Silent(VARIANT_TRUE);
As mentioned earlier, use the put_Silent() method to turn error reporting on or off.
For example, if using a CDHtmlDialog, put this in your OnInitDialog():
m_pBrowserApp->put_Silent(VARIANT_TRUE);
and put it before the LoadFromResource() call.
Be careful though as this will suppress a lot more messages than just JavaScript errors. (Think SSL certificate notifications.)
make change in both HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE paths.
Software\\Microsoft\\Internet Explorer\\Main
RegSetValueEx (hKey, LPCSTR("Disable Script Debugger"), 0, REG_SZ, (BYTE*) "yes", 3);
RegSetValueEx (hKey, LPCSTR("DisableScriptDebuggerIE"), 0, REG_SZ, (BYTE*) "yes", 3);
The docs you are reading refer to what you can do if you embed an IE HTML rendering pane in your own application. They allow you to alter the behavior of that pane.
If you have done that, then you can use COM to QueryInterface an IWebBrowser2 interface from the component.
See more here:
http://support.microsoft.com/kb/196340
And here's how you handle errors:
http://support.microsoft.com/kb/261003
I suspect that that's not what you are trying to do, and that you are just making a web-app. In that case, you need to
Fix your JS errors
Put all of your JS code in try/catch blocks. Then you won't get JS dialogs, but you need to handle the error yourself.
The quick and easy way would be to use a global state to solve a local problem and modify the registry as described here (although Raymond would disapprove of doing so). This basically deactivates script errors entirely for the currently logged in user.
Summary:
Registry Key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
Value Name: Disable Script Debugger
Data Type: REG_SZ (String Value)
Value Data: yes
The more complex solution would be implementing IOleCommandTarget, as already pointed out by Lou.
Well, it's been several hours I'm lost...
IXSLTemplate::putref_stylesheet doesn't document any error except E_FAIL.
However in my case putref_stylesheet returns E_INVALIDARG. GetErrorInfo() is only redundant telling me that the "Argument is invalid". So I am not left with much information.
However my code is pretty close to all examples I found on the web and msdn.
And it does something like:
void xsltProcessing(MSXML2::IXMLDOMDocument* pXmlDoc, MSXML2::IXMLDOMDocument * pXslDoc)
{
IXSLTemplatePtr pTemplate;
pTemplate.CreateInstance( _T( "Msxml2.XSLTemplate" ));
pTemplate->putref_stylesheet(pXslDoc);
//...
}
As there is not much documentation for putref_stylesheet. Do you have any idea what could go wrong for it to return E_INVALIDARG ?
My pXslDoc is a IXMLDOMDocument I have loaded from static const strings with success.
Any clue ? ( I guess it's pretty vague a question, but it's been hours I am searching )
Are you loading pXslDoc asynchronously perhaps?
The default behaviour for IXMLDOMDocument objects is to load asynchronously, so it is possible that the pXslDoc has not finished loading when you call putref_stylesheet().
Adding the following code before you load pXslDoc would fix this problem, if it is what you are suffering from:
pXslDoc->put_async(VARIANT_FALSE);
I am writing an background service application that has to automatically read data from Excel 2003 files. But no matter what I try, the method OlePropertyGet() always results in an EAccessViolation error while trying to read from address "00000800".
The error always occurs at the last line of this code snippet, and seems independent of what parameter the method receives:
Variant excel, workbooks;
try
{
excel = GetActiveOleObject("Excel.Application");
}
catch(...)
{
excel = CreateOleObject("Excel.Application");
}
workbooks = excel.OlePropertyGet("Workbooks");
I've done some extensive google search on this, but found nothing that's even remotely helpful, only this forum thread where someone has the same issue, but doesn't give any information about the cause or solution (it's somewhat funny that at one point the author mentions he knows the cause, but doesn't say what it is!).
I'm open to any ideas as to what is causing this and how to solve this problem, but also alternative approaches to Excel OLE automation.
My guess is its a null pointer issue..
It looks like neither GetActiveOleObject() nor CreateOleObject() worked.
Try checkign the validity of 'excel' before calling OlePropertyGet.
And I guess you should make sure you have Excel installed.
You can use Visual Studio Tools for Office (see http://msdn.microsoft.com/en-us/library/d2tx7z6d.aspx).
Or you can use ATL support to instantiate the object model provided by office.
Your code may not be able to resolve "Excel.Application" successfully, leading to a null pointer. It uses a registry lookup with that string to identify Excel. It sounds like you're missing that registry entry.
I use such code to determine validity of created objects(in C++ Builder):
Varaint excel = GetActiveOleObject("Excel.Application");
TAutoDriver<IDispatch> dispatcher;
dispatcher.Bind(excel, false);
if (dispatcher.IsBound())
{
Variant workbooks = excel.OlePropertyGet("Workbooks");
}