Shoutbox

Code snippet crashing messenger - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Code snippet crashing messenger (/showthread.php?tid=79267)

Code snippet crashing messenger by MeEtc on 11-22-2007 at 03:50 PM

whenever the following code I have here is executed, and the HTTP response is not '0', messenger will crash. The first dialog box will open, I click OK, and messenger 'encounters a problem and needs to close'. And, it is sorry for any inconvenience.

So, after "Interop.Call("User32", "MessageBoxW", 0, "1There was a problem..." is executed and closed, messenger crashes. Whats going on here?!

code:
if (ControlId == 'BtnDelete' && activeiid==null){
    var response = Interop.Call("User32", "MessageBoxW", 0, "Are you SURE you want to delete this image?\nOnce deleted, it cannot be recovered.", 'YASS', 1);
    if (response == 1){
        var i = 0;
        while(!(Wnd.LstView_GetSelectedState('LVimagelst', i)))
            i++;
        var sBoundary = randomString(10);
        var mpform = new multipartform(sBoundary);
        mpform.addfield('req', 'imgdelete');
        mpform.addfield('iid', i);
        mpform.addfield(yass.fields.MSNid, Messenger.MyUserId);
        mpform.addfield(yass.fields.Password, yass.config.Pass);
        var sPost = mpform.buildmessage();
        var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.open("POST", yass.config.URL, false);
        xmlhttp.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + sBoundary);
        xmlhttp.onreadystatechange = function(){
            if(xmlhttp.readyState == 4) {
                wnd.close(0);
                if(xmlhttp.status == 200) {
                    if (xmlhttp.responseText != 0){
                        Interop.Call("User32", "MessageBoxW", 0, "1There was a problem when trying to complete your request. Please try again later. \nIf this continues, please contact your YASS admin for assistance.", 'YASS', 0);
                    }else{
                        wnd.close(0);
                        OnEvent_MenuClicked('image', 'foo', 'bar')
                    }
                }else{
                    Interop.Call("User32", "MessageBoxW", 0, "2There was a problem when trying to complete your request. Please try again later. \nIf this continues, please contact your YASS admin for assistance.", 'YASS', 0);
                }
            }
        }
        xmlhttp.send(sPost);
    }
}

EDIT: well, commenting the line in question so that is does not execute, stops messenger from crashing, so it has something to do with running the dialog box...
RE: Code snippet crashing messenger by vikke on 11-22-2007 at 04:06 PM

Why are you combining " " and ' ' in the call to MessageBox?

I don't see anything wrong elsewhere.
Edit: I think "xmlhttp.send(sPost);" is crashing your script.


RE: Code snippet crashing messenger by MeEtc on 11-22-2007 at 04:19 PM

" " and ' ' are both present because it was a copy/paste job. I usually use single quotes. xmlhttp.send(sPost); can't be crashing it, because that is actually executed before the dialog box. and commenting the line with the dialog box stops messenger from crashing


RE: Code snippet crashing messenger by Matti on 11-22-2007 at 05:35 PM

code:
xmlhttp.open("POST", yass.config.URL, false);
The "false" indicates that you want it to execute synchronously, so that the script will hang while it's executing the MessageBox in the onreadystatechange function. However, this is not needed because when you let it do it asynchronously, the script will continue and thus will stop it from hanging (I suppose).

I suggest you to try and set it to "true" and see if that makes any difference.
RE: Code snippet crashing messenger by MeEtc on 11-22-2007 at 05:54 PM

that fixed it, thanks!