tags:

views:

7

answers:

0

Hi,

I would like to know what happens between window contructor and window loaded event. The reason why I'm asking is because I wrote a code like this:

    LoadUnmanagedLibrary lib;

    public Window1()
    {
        InitializeComponent();            
       lib = new LoadUnmanagedLibrary(this);
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {

    }

and it throws an exception - stackOverflow (funny thing to say on this site :-) ).

When I move the command:

lib = new LoadUnmanagedLibrary(this);

to Window_Loaded event it works allright.

What the command above does is:

Configure configure = (Configure)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(Configure));
WindowInteropHelper wih = new WindowInteropHelper(window);
configure(wih.Handle);

where configure is call of method in unmanaged library in order to show a dialog window.

The question: Why is the exception raised? I don't need to use the command in the constructor but I would like to understand the problem.

Thanks for help!

(I'm sorry I'm quite at loss what tags I should use)