I was using the web browser control and getting some errors when binding to its events. This can be duplicated with the code below.
To generate the event class, open the object browser (Tools->Object Browser) and select the Microsoft Web Browser Control. Navigate to the DWebBrowserEvents2 interface and drag and drop it onto an open PRG editor window.
The object browser reads the interface definition from the type library for the chosen COM object and defines a class with the appropriate method signatures for you.
Then I added a couple lines to instantiate the web browser, the event class, and bind them together.
Running the code highlights the FileDownload method and gives the error: “Must specify additional parameters.”
Because this error is generated by an external object (IE) calling VFP, but before even reaching any VFP user code, a TRY/CATCH or error handler doesn’t help.
Further investigation showed that the FileDownload method of the DWebBrowserEvents2 interface shows that there is one parameter specified in the Type library.
[id(0x0000010e), helpstring("Fired to indicate the File Download dialog is opening")]
void FileDownload([in, out] VARIANT_BOOL* Cancel);
However, IE is calling with 2 parameters. The MSDN documentation for this method shows 2 parameters:
void FileDownload(
VARIANT_BOOL *&ActiveDocument,
VARIANT_BOOL *&Cancel
);
This KB article has more info. In particular, it states “any development tool that generates event handlers that are based on the type library cannot properly sink the event. “ The article itself has to do with .NET interop with the web browser control, so C# and VB.Net have the same problem.
Rick Strahl’s article also mentions this bug.
VFP internally reads the typelib and tries to match the number and type of parameters for each method. If the number of parameters aren’t exactly the same, VFP triggers an error message.
Perhaps a fix to this on the VFP side would be to relax the restriction that the number of parameters match exactly: just trigger an error if the number of parameters in the TypeLib is greater than the number defined in the VFP method. This change will allow the user to add more parameters to the implemented methods, which would fix this issue and also allow the method to be called internally with additional parameter(s).
oIe=
oIe.
oEvents =
?
oIe.navigate2("www.msn.com")
DEFINE CLASS
IMPLEMENTS
?cstr
this
PROCEDURE
* PROCEDURE DWebBrowserEvents2_FileDownload( Cancel AS LOGICAL @) AS VOID
ENDDEFINE