Click here to Skip to main content
15,897,291 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem with CDC:SetMapMode (in Release-Mode) Pin
AnTri31-Aug-06 22:20
AnTri31-Aug-06 22:20 
GeneralRe: Problem with CDC:SetMapMode (in Release-Mode) Pin
Stephen Hewitt31-Aug-06 23:07
Stephen Hewitt31-Aug-06 23:07 
QuestionProblem with a button in an SDI application Pin
Eikthrynir31-Aug-06 9:44
Eikthrynir31-Aug-06 9:44 
AnswerRe: Problem with a button in an SDI application [modified] Pin
prasad_som31-Aug-06 20:50
prasad_som31-Aug-06 20:50 
QuestionSetNamedSecurityInfo 2 Pin
RomTibi31-Aug-06 9:29
RomTibi31-Aug-06 9:29 
QuestionPreventing others to access my process via interprocess communication Pin
Marco225031-Aug-06 9:07
Marco225031-Aug-06 9:07 
AnswerRe: Preventing others to access my process via interprocess communication Pin
Jun Du31-Aug-06 9:42
Jun Du31-Aug-06 9:42 
GeneralDllMain and its usage (Followup to a post by Jeremy Falcon) Pin
PJ Arends31-Aug-06 8:46
professionalPJ Arends31-Aug-06 8:46 
In a recent post Jeremy Falcon[^] provided a link to a white paper about DLL best practices. Basically the paper outlined the does and don'ts of the DllMain function. One of the references cited in that paper is http://blogs.msdn.com/oldnewthing/archive/2004/01/27/63401.aspx[^] where the author says never create a window in response to DLL_PROCESS_ATTACH.

Now this brings up a question in my mind. I have a dll where I have declared a global class that calls the CreateWindow() API in it's constructor. While the window is technically not created in DllMain, it does get created every time the dll is loaded but before DllMain is called.

Everything seems to be working fine so far, but am I asking for trouble using this approach? Or is the fact the window is not created in DllMain mean that I am avoiding the locking issues mentioned in those papers? I guess my question can be summed up as: Is this a safe way to create global window objects in a dll?

Global class:
class CDllWindow
{
public:
    CDllWindow();
private:
    HWND DllWindow;
};

CDllWindow::CDllWindow()
{
    DllWindow = CreateWindow(...);
}


Dll cpp file:
#include "DllWindow.h"
CDllWindow DllWindow;     // Creates a window

BOOL APIENTRY DllMain(HMODULE, DWORD, LPVOID)
{
    return TRUE;
}






You may be right
I may be crazy
-- Billy Joel --


Within you lies the power for good, use it!!!
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
Zac Howland31-Aug-06 9:03
Zac Howland31-Aug-06 9:03 
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
PJ Arends31-Aug-06 9:19
professionalPJ Arends31-Aug-06 9:19 
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
PJ Arends31-Aug-06 9:33
professionalPJ Arends31-Aug-06 9:33 
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
Michael Dunn31-Aug-06 18:42
sitebuilderMichael Dunn31-Aug-06 18:42 
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
PJ Arends31-Aug-06 21:14
professionalPJ Arends31-Aug-06 21:14 
QuestionHeap corruption?! Pin
Nader Elshehabi31-Aug-06 7:55
Nader Elshehabi31-Aug-06 7:55 
AnswerRe: Heap corruption?! Pin
Zac Howland31-Aug-06 8:15
Zac Howland31-Aug-06 8:15 
QuestionRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 9:01
Nader Elshehabi31-Aug-06 9:01 
AnswerRe: Heap corruption?! Pin
Zac Howland31-Aug-06 9:08
Zac Howland31-Aug-06 9:08 
GeneralRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 9:49
Nader Elshehabi31-Aug-06 9:49 
GeneralRe: Heap corruption?! Pin
David Crow31-Aug-06 10:09
David Crow31-Aug-06 10:09 
GeneralRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 12:21
Nader Elshehabi31-Aug-06 12:21 
GeneralRe: Heap corruption?! Pin
Zac Howland31-Aug-06 10:20
Zac Howland31-Aug-06 10:20 
JokeRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 12:29
Nader Elshehabi31-Aug-06 12:29 
GeneralRe: Heap corruption?! Pin
Stephen Hewitt31-Aug-06 14:10
Stephen Hewitt31-Aug-06 14:10 
GeneralRe: Heap corruption?! Pin
Zac Howland1-Sep-06 3:56
Zac Howland1-Sep-06 3:56 
GeneralRe: Heap corruption?! Pin
Stephen Hewitt1-Sep-06 4:19
Stephen Hewitt1-Sep-06 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.