Excel 2003 Problem opening System.Windows.Form

410 views
Skip to first unread message

llandi

unread,
Jan 19, 2012, 3:29:34 PM1/19/12
to Excel-DNA
Hi,

I tried to create an Add-In in C # Ver.4 ExcelDNA with ver 0.29.
I works but Excel 2003 does not display any of the forms that I
created in my C # project.
I tried various methods: even the same technique used in
ExcelDNA.Logging, but nothing (in this case I get an error on a call
for the management of the icons).

Under 2007 and 2010 I have no problem and all techniques from the
simplest to the most complex I have never had problems.

Excel 2003 is old and has installed the SP3 only. (under XP).

It obviously does not work is calling. Show () from CommandBar that
Function.

What tricks do you suggest to try? VBA can be integrated into a direct
call to a method in a DLL that is packed inside the XLL? or risk of
getting the same problem?

It would have to open a very simple form of the typical About. Success
in this then I will be able to write this directly into Excel that has
the call.

I hope that I explained enough,
Thanks to all,
Luca

Govert van Drimmelen

unread,
Jan 19, 2012, 5:01:57 PM1/19/12
to Excel-DNA
Hi Luca,

Here is a discussion that might be helpful, even though it was about
WPF rather than Windows Forms: http://exceldna.codeplex.com/discussions/266302

Below I paste a small .dna file that you can try with - it creates a
menu and a few ways of running a form from the menu buttons - modal or
not modal, and with a separate thread.

On my Excel 2002 all the options work OK, but maybe to arrive at your
problem we need to make it a bit more complicated.

What do you see when you press the different menu buttons?

Can you make this example more complicated in a way that represents
the problem you have?

Regards,
Govert


<DnaLibrary Name="Excel-DNA WinForms Test" Language="C#">
<Reference Name="System.Windows.Forms" />

<![CDATA[
using System;
using System.Threading;
using System.Windows.Forms;
using ExcelDna.Integration;

public static class Test
{
[ExcelCommand(MenuName="Winforms Test", MenuText="Show
MessageBox")]
public static void ShowMessageBox()
{
MessageBox.Show("This is a messagebox");
}

[ExcelCommand(MenuName="Winforms Test", MenuText="Show Modal
Form - Main Thread")]
public static void ShowFormModalMainThread()
{
Form f = new Form();
Label l = new Label();
l.Text = "Hello";
f.Controls.Add(l);
f.ShowDialog();
}

[ExcelCommand(MenuName="Winforms Test", MenuText="Show Non-
Modal Form - Main Thread")]
public static void ShowFormNonModalMainThread()
{
Form f = new Form();
Label l = new Label();
l.Text = "Hello";
f.Controls.Add(l);
f.Show();
}

[ExcelCommand(MenuName="Winforms Test", MenuText="Show Non-
Modal Form - New Thread")]
public static void ShowFormModalNewThread()
{
ShowUserFormNonModal();
}

// Non-Modal thread storyu
private static Thread threadNonModal;

public static void ShowUserFormNonModal()
{
threadNonModal = new Thread(doWorkNonModal);
threadNonModal.SetApartmentState(ApartmentState.STA);
threadNonModal.IsBackground = true;
threadNonModal.Start();
}

private static void doWorkNonModal()
{
Form form = new Form();
Label label = new Label();
label.Text = "Hello";
form.Controls.Add(label);
Application.Run(form);
}
}
]]>
</DnaLibrary>

Luca Landi

unread,
Jan 24, 2012, 3:23:53 AM1/24/12
to exce...@googlegroups.com
HI,

Thank you for your invaluable help!

Thanks to the piece of code that I have seen that I have provided the
basic what I had done was correct. So I began to rebuild from scratch
the forms that I had. Eventually I discovered that I followed: In one
form, with Excel 2003, an exception was generated because I had
defined an icon associated with the form (the top left corner near the
window title).
In another form I had created a potential loop within a function
itemChecked event of a ListView with checkboxes. At the moment of
creation, a checkbox with check = true by default, unleashed the
potential loop and after a few moments, Excel 2003 closes with no
errors.

For some strange reason both defects under Win7 with Excel 2007 and
Excel 2010 did not give any problems and everything worked as
expected.

Now I created a project finalemnte able to add an addin XLL compacted
into a single file that is able to function properly from 2003 to 2010
in the same way without any problems (indeed, the addin in Excel 2003
opens much faster).

Thanks again for the quick and valuable help,
Luca.

> --
> You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
> To post to this group, send email to exce...@googlegroups.com.
> To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.
>

Jon49

unread,
Jan 25, 2012, 1:12:27 PM1/25/12
to Excel-DNA
Here's another way to go about it. Just get the IWin32Window and put
it in the .Show(owner) when you call the form.

I wrote about it here: http://www.spreadsheetbudget.com/2012/01/23/net-and-modeless-forms-in-excel/

Here's the code. I grabbed the original code from StackOverflow in C#:

Public Class WindowWrapper



Implements System.Windows.Forms.IWin32Window


Private _hwnd As IntPtr


Public Sub New(ByVal handle As IntPtr)
_hwnd = handle
End Sub


Public ReadOnly Property Handle() As IntPtr Implements
System.Windows.Forms.IWin32Window.Handle
Get
Return _hwnd
End Get
End Property


End Class


'Code for implementation
Dim owner As New WindowWrapper(CType(gXLApp.Hwnd, IntPtr))
gfTimeStamp = New FTimeStamp
gfTimeStamp.Show (owner)

CSharp Dummy

unread,
Jul 30, 2013, 1:40:46 PM7/30/13
to exce...@googlegroups.com
This looks nice, but how do it get "gXLApp.Hwnd"?
Do I need the COM object for that?

CSharp Dummy

unread,
Aug 8, 2013, 9:47:20 PM8/8/13
to exce...@googlegroups.com
Anyone?
Reply all
Reply to author
Forward
0 new messages