locked
Unable to load DLL 'coredll.dll' RRS feed

  • Question

  • I'm using Visual Studio Team System 2008 for Developers.  I'm working on a Smart Device Project targeting Windows Mobile 6.5.  I have a user control which uses a PInvoke call to GetSystemMetrics() in order to determine the width of a vertical scrollbar.  When I drop the user control onto a form I get the following error:

    Unable to load DLL 'coredll.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

    I'm assuming this is because coredll.dll is a Windows CE library and isn't available on Windows.  When the designer instantiates the user control it throws an exception because coredll.dll isn't present.  So what's the workaround you Microsoft guys use?  There must be some way design Smart Device forms with Visual Studio.  And given that the Compact Framework only provides 80% of what a normal application needs, I'm positive you also have to drop down to PInvoke...

    Brian
    • Moved by Kira Qian Wednesday, December 23, 2009 2:18 AM (From:Windows Forms Designer)
    Tuesday, December 22, 2009 5:33 PM

Answers

  • Yes, that is because Windows CE library is not available on Windows. In general designers should figure that out and never instantiate the control but that might not work in some cases. So your options are:

    1. Use DesktopCompatible attribute set to false in designer ASMMETA.
    2. Remove P/Invoke.
    3. Add try/catch around P/Invoke, use default value if failed.
    2. Check platform type or design time and do not call this API in designers.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by ZHE ZHAO Tuesday, December 29, 2009 5:29 AM
    Wednesday, December 23, 2009 3:51 AM
  • Here's how you can check for design time in general on NETCF:

    if (this.Site != null && this.Site.DesignMode)
    {
       // do design time only stuff
    }


    Naturally this is not set while class is been constructed. So you can check platform type instead:

    if (Environment.OSVersion.Platform != PlatformID.WinCE)
    {
        // We're on desktop, so that must be design time.
    }
    Another way is not to do anything platform dependent in the constructor (as you have done). This is a good solution.

    You can also get to current AppDomain and check it's friendly name but that is fishy.

    One more thing you can try is removing default constructor from your control and replacing it with the one which takes IContainer - which should be DesignerHost at design time. That would give you ability to get to check for design time in the constructor. It has number of drawbacks though so I would go with not doing platform dependent things in the constructor instead.




    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by ZHE ZHAO Tuesday, December 29, 2009 5:29 AM
    Wednesday, December 23, 2009 8:22 PM

All replies

  • Yes, that is because Windows CE library is not available on Windows. In general designers should figure that out and never instantiate the control but that might not work in some cases. So your options are:

    1. Use DesktopCompatible attribute set to false in designer ASMMETA.
    2. Remove P/Invoke.
    3. Add try/catch around P/Invoke, use default value if failed.
    2. Check platform type or design time and do not call this API in designers.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by ZHE ZHAO Tuesday, December 29, 2009 5:29 AM
    Wednesday, December 23, 2009 3:51 AM
  • Thanks for the response.  I tried the try/catch and it unfortunately didn't make a difference.  Removing the P/Invoke isn't an option because as far as I know, there's no managed way to get the size of the system's vertical scrollbar width.  Please correct me if I'm wrong though.  I ended up solving it by not calling the GetSystemMetrics function in the constructor and adding a property that calls it the first time the property is accessed.  Then in my resize and painting code I call the property instead of the member variable (field).  I've never seen the DesktopCompatible attribute and will definitely play with this some more.  Thanks for that lead!

    Your response brings up another question that seems to be asked a lot with no apparent answer.  Your last point states to check to see if the control is being used at design time.  How can this be done in an object's constructor?  Furthermore, what properties are available from the compact framework?  It seems every property that indicates design time is missing in the compact framework.

    Thanks!
    Brian
    Wednesday, December 23, 2009 2:31 PM
  • Here's how you can check for design time in general on NETCF:

    if (this.Site != null && this.Site.DesignMode)
    {
       // do design time only stuff
    }


    Naturally this is not set while class is been constructed. So you can check platform type instead:

    if (Environment.OSVersion.Platform != PlatformID.WinCE)
    {
        // We're on desktop, so that must be design time.
    }
    Another way is not to do anything platform dependent in the constructor (as you have done). This is a good solution.

    You can also get to current AppDomain and check it's friendly name but that is fishy.

    One more thing you can try is removing default constructor from your control and replacing it with the one which takes IContainer - which should be DesignerHost at design time. That would give you ability to get to check for design time in the constructor. It has number of drawbacks though so I would go with not doing platform dependent things in the constructor instead.




    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by ZHE ZHAO Tuesday, December 29, 2009 5:29 AM
    Wednesday, December 23, 2009 8:22 PM