ADXKeyboardShortcut bug (causing AccessViolationException)

Add-in Express™ Support Service
That's what is more important than anything else

ADXKeyboardShortcut bug (causing AccessViolationException)
Found bug in ADXKeyboardShortcut component 
Maros Kantera




Posts: 17
Joined: 2007-01-09
Hi,

I have found a bug in ADXKeyboardShortcut (Add-in Express v.2.8.1763.2005) component when used in Word (i haven't tested it in other office apps). Put the following code in response to ADXKeyboardShortcut.Action event:


//this method is executed in response to ADXKeyboardShortcut.Action event
        private void adxKeyboardShortcut_Action(object sender)
        {
            object saveChanges = Type.Missing;
            object originalFormat = Type.Missing;
            object routeDocument = Type.Missing;

            Document doc = WordApp.ActiveDocument;
            doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
            Marshal.ReleaseComObject(doc);
        }


Run Word and open existing document (and DO NOT switch active document). Modify content of active document. Press assigned keyboard shortcut combination (which will display dialog if you wish to save changes => press any button) and Word will crash in call to doc.Close(..) with AccessViolationException exception with message "attempted to read or write protected memory. This is often an indication that other memory is corrupt.".

However, if you open several documents, switch focus between them (thus changing active document), modify content of currently active document and press keyboard shortcut, the code will run just fine.

The code runs ALWAYS fine if it is executed in response to a button click (in custom toolbar or menu)...

I hope you will repair this error ASAP. Thanks!
Posted 09 Jan, 2007 04:56:17 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Maros.

Fixed!

private const int WM_USER = 0x0400;
private const int WM_CLOSEDOCUMENT = WM_USER + 1000;

private void adxKeyboardShortcut1_Action(object sender)
{
this.SendMessage(WM_CLOSEDOCUMENT, IntPtr.Zero, IntPtr.Zero);
}

private void AddinModule_OnSendMessage(object sender, AddinExpress.MSO.ADXSendMessageEventArgs e)
{
if (e.Message == WM_CLOSEDOCUMENT)
{
object saveChanges = Type.Missing;
object originalFormat = Type.Missing;
object routeDocument = Type.Missing;

Word._Document doc = WordApp.ActiveDocument;
doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
Marshal.ReleaseComObject(doc);
}
}


P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 09 Jan, 2007 09:56:47 Top
Maros Kantera




Posts: 17
Joined: 2007-01-09
Hi Sergey,

it works, thanks! You're doing great job at Add-in Express team!
Posted 09 Jan, 2007 10:20:47 Top