FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

usage of juno.com.client EventProvider

 
Post new topic   Reply to topic     Forum Index -> Juno
View previous topic :: View next topic  
Author Message
yidabu



Joined: 21 Apr 2007
Posts: 87

PostPosted: Fri Aug 31, 2007 5:04 am    Post subject: usage of juno.com.client EventProvider Reply with quote

code cause error:
Quote:
cannot implicitly convert expression (__dgliteral1) of type void delegate(ref IDispatch ppDisp ...) to void delegate(IDispatch ...)


if use :
Code:
delegate void (IDispatch ppDisp, short Cancel ...)

Cancel = VARIANT_TRUE cannot canceled the current navigation.

can you give me a hand ?


// http://msdn2.microsoft.com/en-us/library/aa768288.aspx
Code:
import shdocvw;
import mshtml;
import juno.com.client;
import juno.com.core;

void main()
{
    IWebBrowser2 iwb = InternetExplorer.coCreate!(IWebBrowser2)(ExecutionContext.LocalServer);
   iwb.put_Visible(VARIANT_TRUE);       
   
   auto events = new EventProvider!(DWebBrowserEvents2)(iwb);
   scope(exit) tryRelease(events);           
   events.attach("NewWindow3",
        delegate void (ref IDispatch ppDisp, ref short Cancel, uint dwFlags, wchar* bstrUrlContext, wchar* bstrUrl)
        {                                 
            Cancel = VARIANT_TRUE;
            string urlcontext;
            urlcontext = fromBStr(bstrUrlContext);
            scope(exit) { freeBStr(bstrUrlContext); freeBStr(bstrUrl); }
            printf("clicked url: %.*s \n",  urlcontext);
        }
       
    );//   
           
    wchar* BStrURL = toBStr("http://www.google.com");
    VARIANT vars[4];
    auto hr = iwb.Navigate(BStrURL, &vars[0], &vars[1], &vars[2], &vars[3]);
    scope(exit) freeBStr(BStrURL);      
   
    tagREADYSTATE rs;
    while (rs != tagREADYSTATE.READYSTATE_COMPLETE)
    {
        Application.doEvents();// dfl.application
        iwb.get_ReadyState(rs);
    }    
   
}
//
Back to top
View user's profile Send private message
John



Joined: 17 Jan 2006
Posts: 75

PostPosted: Fri Aug 31, 2007 9:16 am    Post subject: Reply with quote

Behind the scenes, EventProvider.attach uses std.traits.ParameterTypeTuple, which doesn't allow 'ref' parameters. So you have to use pointers instead.

Code:

events.attach("NewWindow3", (IDispatch* ppDisp, VARIANT_BOOL* cancel, uint dwFlags, wchar* bstrUrlContext, wchar* bstrUrl) {
  *cancel = VARIANT_TRUE;
});

wchar* url = "http://www.google.com".toBStr();
scope(exit) freeBStr(url);
// flags = 1 to open in new window.
VARIANT flags = 1, empty;
iwb.Navigate(url, &flags, &empty, &empty, &empty);


It compiles, and there are no runtime errors - meaning that the event handler was successfully attached. But, for some reason, the handler never gets used.

It works fine when I host the WebBrowser, but not using the InternetExplorer object. I'll look into it.

Update: The code does actually work, and some events are received - but not NewWindow2/3.

Code:

events.attach("OnVisible", (bool visible) {
  writefln("Visible");
});


So I don't think it's an issue with Juno, but with IE - it just isn't calling any of the NewWindow handlers.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Juno All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group