1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
DISPID Id;
WCHAR * Name = L"getElementByID";// Method name
WebBrowser1->Document->GetIDsOfNames
(
IID_NULL, // Must be null
&Name, // Name of the method we want
1, // Number of parameters we want to pass
LOCALE_SYSTEM_DEFAULT, //Seems to work just fine
&Id // The value of the method ID WE WANT!
);
DISPPARAMS DispParams; // Parameters structure to pass to the getElementByID
// through the following Invoke method
DispParams.cArgs=1; // Number of parameters to pass
DispParams.cNamedArgs=0; // Number of named parameters to pass
DispParams.rgdispidNamedArgs=NULL;//We don't want to pass arguments by name,
//just by position (in rgvarg array)
DispParams.rgvarg=new VARIANT[1]; // Allocate 1 variant for 1 parameter
DispParams.rgvarg[0].vt=VT_BSTR; // Tells thet we want to pass a string by value
DispParams.rgvarg[0].bstrVal=L"txt_Username";// String we want to pass
VARIANT *ReturnParams =new VARIANT;
unsigned int ReturnInt;
WebBrowser1->Document->Invoke
(
Id, // got from GetIDsOfNames
IID_NULL, // Must be
LOCALE_SYSTEM_DEFAULT,// Seems to work!
DISPATCH_METHOD, // We want to call a method 'getElementById'
&DispParams, // Parameters to pass to getElementById
ReturnParams, // Contains a Element in the webpage in a DISPATCH interface
NULL, // Returns Exceptions, For simplicity we wont bother
&ReturnInt // Only if there's an error in passed parameters
// DISP_E_TYPEMISMATCH or DISP_E_PARAMNOTFOUND.
);
IDispatch *Element;
Name=L"OuterHtml"; // The property we want to change the value of
Element=ReturnParams->pdispVal;
Element->GetIDsOfNames
(
IID_NULL, // Must be!
&Name, // Name of the propery
1, // Number of parameters in this case the 'value'
LOCALE_SYSTEM_DEFAULT, // Seems to work
&Id // Returned Property ID
);
DispParams.cArgs=1; // Number of values we want to pass
DispParams.cNamedArgs=0; // 0 named params
DispParams.rgdispidNamedArgs=NULL; // No named params
DispParams.rgvarg[0].vt=VT_BSTR; // Pass the parameter by value
DispParams.rgvarg[0].bstrVal=L"EUREKA!"; // Put it in the corresponding field
// The rest is similar ...
Element->Invoke
(
Id,
IID_NULL,
LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYPUT,
&DispParams,
NULL,
NULL,
&ReturnInt // Or NULL because we don't expect a result
);
|