Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!microsoft!michaelt From: michaelt@microsoft.UUCP (Michael THURLKILL) Newsgroups: comp.windows.ms Subject: Re: RegisterClass in DLL Message-ID: <10126@microsoft.UUCP> Date: 3 Jan 90 15:06:50 GMT References: <6970014@hpmcaa.mcm.hp.com> <34458@mirror.UUCP> Reply-To: michaelt@microsoft.UUCP (Michael THURLKILL) Organization: Microsoft Corp., Redmond WA Lines: 34 In article <34458@mirror.UUCP> bobg@mirror.TMC.COM (Bob Goodearl) writes: >In article <6970014@hpmcaa.mcm.hp.com> marco@hpmcaa.mcm.hp.com > (Marco Dalla-Gasperina) writes: >=>I'm having a problem registering a window class inside a DLL... It seems >=>to work for a "few" times (usually 3) but then it fails? >=> > >When writing DLL code, I found that a window class registered using the >DLL instance handle caused problems. If the application calling the >DLL was closed and then started a second time without exiting windows >first, the call to RegisterClass in the DLL would fail the second time. >The solution I found was to use the parent application's instance >handle when calling RegisterClass in the DLL. This works for the code >I'm writing because only 1 application can use the DLL and only 1 >instance of the application can exist at any one time. > The problem is that the class isn't automatically de-registered when the DLL exits, and it is not possible to request that the class be de-registered. Things will work ok in the case of using hInst of the app because the class then "belongs" to the task and goes away when the task terminates. However, if more than one app uses the class, and the first app terminates, the class is destroyed, and the other apps will shortly crash. A class can be registered, and shared by applications, if it is registered in the DLL, uses the DLL's hInst, AND the DLL stays around forever. To keep the DLL around, it must be loaded independantly, ie. file-run from the MSDOS Executive or placed on the load= line in win.ini. This is one of those things that "is under consideration and will be addressed in a future release." But seriously, I think it will be fixed. Mike Thurlkill Disclaimer: These thoughts and opinions are mine. They should not be mis-construed as being correct or in any way related to my employer.