ShowMessage fails in Word2010

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

ShowMessage fails in Word2010
 
Steve Smith


Guest


Hello!

I've ran into a very strange problem:

Calling ShowMessage in my Word add-in (in Word2010) causes the following error to be displayed:

"A call to an OS function failed."

I've not tested my add-in extensively in Word2010, so I don't know if it used to work or not (it could be the result of an MS security update maybe) - but it doesn't work now.

With earlier Word versions (including Word2007) there seems to be no problem.

Note: if I call the MessageBox function it works fine...

Any ideas?

Thank you!
Posted 04 Oct, 2011 13:30:47 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Steve,

Can you show some code? In what event do you call ShowMessage? What Word build number and bitness is used?


Andrei Smolin
Add-in Express Team Leader
Posted 05 Oct, 2011 02:49:28 Top
Steve Smith


Guest


Hello Andrei,

I've now checked my add-in with another (earlier) version of Word2010 and it works without problems.

Here are the version numbers:

Works on 14.0.5128.5000
Doesn't work on 14.0.6106.5005

The security settings of Word are the same on both computers.

I can't really give you example code as all my add-in does at the line of the error is calling "ShowMessage('something');".

I'll try to make an add-in from scratch to see if it produces the same issue.

Thanks!
Posted 05 Oct, 2011 05:37:12 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
In what event do you call this?

Are other add-ins turned off?


Andrei Smolin
Add-in Express Team Leader
Posted 05 Oct, 2011 05:45:03 Top
Steve Smith


Guest


This is super strange.

I created a dummy add-in which called ShowMessage on the press of a ribbon button. It worked in the newer Word version.

Then I tried my original add-in and it started to work!

I have no idea what happened.

Note: I didn't call the problematic ShowMessages in an event, but on the press of a ribbon button. Actually there were a lot of ShowMessages in my add-in, and all of them displayed the same error. Just the ShowMessage calls.

Word has suprised me many times, but this one seems extremely strange and bothering, as one might never know when the issue will resurface again...

Thanks for your help Andrei!
Posted 05 Oct, 2011 11:13:19 Top
Steve Smith


Guest


OK, so one more hour of testing and I got the culprit.

I'm using some code from MustangPeak's EasyNSE [name space extensions] (the site is now off-line BTW) to enable XP/Vista/7 theming on the forms displayed by my add-in.

If this code below is called, it messes up any showmessages called afterwards by the newly created form:


if ActCtxAvailable then
    begin
        FillChar(ActCtx, SizeOf(ActCtx), #0);
        ActCtx.cbSize:=SizeOf(ActCtx);
        ActCtx.dwFlags:=ACTCTX_FLAG_RESOURCE_NAME_VALID;
        GetModuleFileName(hInstance, Buffer, SizeOf(Buffer));
        ActCtx.lpSource:=Buffer;
        ActCtx.lpResourceName:=MAKEINTRESOURCE(2);
 
        hActCtx:=CreateActCtxA(ActCtx);
 
        ActivateContext:=hActCtx <> INVALID_HANDLE_VALUE;
        if ActivateContext then
            ActivateActCtx(hActCtx, Cookie);
 
        MyForm:=TMyForm.Create(Self.WordApp);
        ForceAllWindowHandles(MyForm);
 
        if ActivateContext then
        begin
            DeactivateActCtx(0, Cookie);
            ReleaseActCtx(hActCtx);
        end;
    end


Interestingly, this issue didn't surface up to now and it doesn't exist with older Word versions.

Do you know of any other ways to enable theming on Forms displayed by my add-in?

Thanks!
Posted 05 Oct, 2011 12:03:08 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Steve,

Steve Smith writes:
Do you know of any other ways to enable theming on Forms displayed by my add-in?


The only way I know is to use third-party controls. It seems we have tried all other ways - none of them worked.


Andrei Smolin
Add-in Express Team Leader
Posted 06 Oct, 2011 09:39:05 Top
Steve Smith


Guest


Hello Andrei,

The code I use works (except for the above problem recently). There is only one thing I haven't been able to figure out: sometimes when the add-in is first registered on a computer, it will show the form for the first time without theming. But from the second or third time it will be themed.

Do you want me to send you some example code? Maybe you guys could figure out how to make the above work consistently, I suppose it would be of great help to many Delphi developers using Add-in Express!

Thanks!
Posted 07 Oct, 2011 04:17:37 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Steve,

I doubt we will be able to help but we can try. Please send us the code sample to the support email address (see readme.txt).


Andrei Smolin
Add-in Express Team Leader
Posted 07 Oct, 2011 05:39:34 Top