Click here to Skip to main content
16,008,010 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralManny thanks ! it is works !!! extra last question Pin
mimi21-Oct-01 23:22
mimi21-Oct-01 23:22 
GeneralRegister an ActiveX control Pin
Daed21-Oct-01 1:08
Daed21-Oct-01 1:08 
GeneralRe: Register an ActiveX control Pin
Michael P Butler21-Oct-01 3:05
Michael P Butler21-Oct-01 3:05 
GeneralRe: Register an ActiveX control Pin
Daed21-Oct-01 3:51
Daed21-Oct-01 3:51 
GeneralRe: Register an ActiveX control Pin
Michael Dunn21-Oct-01 8:17
sitebuilderMichael Dunn21-Oct-01 8:17 
GeneralRe: Register an ActiveX control Pin
Daed22-Oct-01 6:28
Daed22-Oct-01 6:28 
GeneralAbout DLL initialization Pin
Maer72721-Oct-01 1:05
Maer72721-Oct-01 1:05 
GeneralRe: About DLL initialization Pin
Steen Krogsgaard21-Oct-01 23:23
Steen Krogsgaard21-Oct-01 23:23 
Hi Maer,

When you wan't to use a DLL in your app you have to load it into your process address space first. This is done by the function LoadLibrary. When LoadLibrary executes it first maps the DLL into the process' address space (this means that if the DLL is already used by another app it is not re-loaded from disk, but setup so the your process can see it in it's own address space). Then it's initialization time! LoadLibrary calls the DllMain function located in the DLL with the dwReason parameter set to DLL_PROCESS_ATTACH. After the DllMain function returns LoadLibrary calls it once again, this time with dwReason set to DLL_THREAD_ATTACH. If both these calls to DllMain succeeds then LoadLibrary returns to your app, giving you the handle to the newly loaded - and initialized - DLL.

The problem you're referring to is if you put another LoadLibrary call in your DllMain function. Say your DLL (DllA) is dependent on a second DLL, DllB, which in turn is dependent on DllA again. In DllA's DllMain function a call to LoadLibrary(DllB) is issued. In DllB's DllMain function a function in DllA is executed. Since DllA is loaded there's no problem in calling the function, but since the DllA is not yet initialized there may be some data that the called function uses that is not set up properly (e.g. MFC state data Wink | ;-) .

To summarize: LoadLibray performs two tasks: One is to do the physical loading of the DLL (loading from disk, linking all the exported functions), the other is to initialize the DLL. Initialization consists of calling DllMain twice, once with DLL_PROCESS_ATTACH and once with DLL_THREAD_ATTACH.

Cheers
Steen.

"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
Generala very very simple question about DllMain Pin
Maer72721-Oct-01 0:47
Maer72721-Oct-01 0:47 
GeneralRe: a very very simple question about DllMain Pin
Steen Krogsgaard21-Oct-01 23:33
Steen Krogsgaard21-Oct-01 23:33 
GeneralDistributing a DLL Pin
Peter Liddle21-Oct-01 0:34
Peter Liddle21-Oct-01 0:34 
GeneralRe: Distributing a DLL Pin
Michael P Butler21-Oct-01 3:11
Michael P Butler21-Oct-01 3:11 
GeneralRe: Distributing a DLL Pin
Michael Dunn21-Oct-01 8:21
sitebuilderMichael Dunn21-Oct-01 8:21 
GeneralRe: Distributing a DLL Pin
Michael P Butler21-Oct-01 8:22
Michael P Butler21-Oct-01 8:22 
GeneralRe: Distributing a DLL Pin
Michael Dunn21-Oct-01 8:36
sitebuilderMichael Dunn21-Oct-01 8:36 
GeneralDistributing a DLL Pin
21-Oct-01 0:30
suss21-Oct-01 0:30 
Generalgraying/enabling menu items in an MFC dialog Pin
Kuniva20-Oct-01 23:54
Kuniva20-Oct-01 23:54 
GeneralRe: graying/enabling menu items in an MFC dialog Pin
Christian Graus21-Oct-01 1:20
protectorChristian Graus21-Oct-01 1:20 
GeneralRe: graying/enabling menu items in an MFC dialog Pin
Kuniva21-Oct-01 1:25
Kuniva21-Oct-01 1:25 
GeneralRe: graying/enabling menu items in an MFC dialog Pin
Christian Graus21-Oct-01 10:01
protectorChristian Graus21-Oct-01 10:01 
Questionwhat find a string in a file and delete it in this file????? Pin
leech4220-Oct-01 22:03
leech4220-Oct-01 22:03 
AnswerRe: what find a string in a file and delete it in this file????? Pin
davemin20-Oct-01 22:56
davemin20-Oct-01 22:56 
QuestionIs Dll a thread? Pin
Maer72720-Oct-01 21:57
Maer72720-Oct-01 21:57 
AnswerRe: Is Dll a thread? Pin
Andrew Peace21-Oct-01 10:52
Andrew Peace21-Oct-01 10:52 
GeneralRe: Is Dll a thread? Pin
Maer72721-Oct-01 19:23
Maer72721-Oct-01 19:23 

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.