15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Reason of a DLL's InitInstance

Lior Messinger -- 100274.2607@compuserve.com
Sunday, April 07, 1996

Platform: Windows NT, VC++ 4.0

Hi,

When programming a DLL in Win32, one can obtain teh reason for
entering the DllEntryPoint main function of a DLL: because of
DLL+PROCESS_ATTACH,DLL_THREAD_ATTACh etc.

When I'm programming with MFC, one option to create a
DLL is to use CWinAPP and to compile as a DLL. First, is it a
good solution? And if so, assuming that InitInstance is the
entry point for the DLL, how can I get the reason for entring
this entry point?


Thanks a lot,
Lior Messinger, Fundtech.





Dan Kirby -- dkirby@accessone.com
Monday, April 08, 1996

Here is the DLLMain from DLLMODUL.CPP in the MFC\SRC directory.
You can see where InitInstance() and ExitInstance() are called.   Thread attaching and detaching cases aren't handled.

****
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
	if (dwReason == DLL_PROCESS_ATTACH)
	{
		BOOL bResult = FALSE;

#ifdef _AFXDLL
		// wire up resources from core DLL
		AfxCoreInitModule();
#endif

		// Initialize DLL's instance(/module) not the app's
		if (!AfxWinInit(hInstance, NULL, &afxChNil, 0))
		{
			AfxWinTerm();
			goto Cleanup;       // Init Failed
		}

		// initialize the single instance DLL
		CWinApp* pApp; pApp = AfxGetApp();
		if (pApp != NULL && !pApp->InitInstance())
		{
			pApp->ExitInstance();
			AfxWinTerm();
			goto Cleanup;       // Init Failed
		}

#ifdef _AFXDLL
		// wire up this DLL into the resource chain
		VERIFY(AfxInitExtensionModule(controlDLL, hInstance));
		CDynLinkLibrary* pDLL; pDLL = new CDynLinkLibrary(controlDLL);
		ASSERT(pDLL != NULL);
#else
		AfxInitLocalData(hInstance);
#endif

		bResult = TRUE;

Cleanup:
#ifdef _AFXDLL
		// restore previously-saved module state
		VERIFY(AfxSetModuleState(AfxGetThreadState()->m_pPrevModuleState) ==
			AfxGetStaticModuleState());
		DEBUG_ONLY(AfxGetThreadState()->m_pPrevModuleState = NULL);
#endif
		return bResult;
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
#ifdef _AFXDLL
		// set module state for cleanup
		ASSERT(AfxGetThreadState()->m_pPrevModuleState == NULL);
		AfxGetThreadState()->m_pPrevModuleState =
			AfxSetModuleState(AfxGetStaticModuleState());
#endif

		CWinApp* pApp = AfxGetApp();
		if (pApp != NULL)
			pApp->ExitInstance();

#ifdef _DEBUG
		// check for missing AfxLockTempMap calls
		if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
		{
			TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
				AfxGetModuleThreadState()->m_nTempMapLock);
		}
		AfxLockTempMaps();
		AfxUnlockTempMaps();
#endif

		// terminate the library before destructors are called
		AfxWinTerm();

#ifdef _AFXDLL
		AfxTermExtensionModule(controlDLL, TRUE);
#else
		AfxTermLocalData(hInstance);
#endif
	}

	return TRUE;
}


----------
From: 	Lior Messinger[SMTP:100274.2607@compuserve.com]
Sent: 	Sunday, April 07, 1996 3:04 AM
To: 	MFC Mailing List
Subject: 	Reason of a DLL's InitInstance

Platform: Windows NT, VC++ 4.0

Hi,

When programming a DLL in Win32, one can obtain teh reason for
entering the DllEntryPoint main function of a DLL: because of
DLL+PROCESS_ATTACH,DLL_THREAD_ATTACh etc.

When I'm programming with MFC, one option to create a
DLL is to use CWinAPP and to compile as a DLL. First, is it a
good solution? And if so, assuming that InitInstance is the
entry point for the DLL, how can I get the reason for entring
this entry point?


Thanks a lot,
Lior Messinger, Fundtech.





begin 600 WINMAIL.DAT
M>)\^(@P%`0:0" `$```````!``$``0>0!@`(````Y 0```````#H``$(@ <`
M& ```$E032Y-:6-R;W-O9G0@36%I;"Y.;W1E`#$(`0V ! `"`````@`"``$$
MD 8`I (```(````,`````P``, ,````+``\.``````(!_P\!````/P``````
M``"!*Q^DOJ,0&9UN`-T!#U0"`````&UF8RUL0&YE=&-O;2YC;VT`4TU44 !M
M9F,M;$!N971C;VTN8V]M```>``(P`0````4```!33510`````!X``S !````
M$0```&UF8RUL0&YE=&-O;2YC;VT``````P`5# $````#`/X/!@```!X``3 !
M````$P```"=M9F,M;$!N971C;VTN8V]M)P```@$+, $````6````4TU44#I-
M1D,M3$!.151#3TTN0T]-`````P``.0`````+`$ Z`0````(!]@\!````! ``
M``````,-`````P``, 0````+``\.`0````(!_P\!````4P````````"!*Q^D
MOJ,0&9UN`-T!#U0"```!`#$P,#(W-"XR-C W0&-O;7!U``$P`0```!T````G,3 P,CP$$@ $`(P```%)%.B!296%S;VX@;V8@82!$3$PG`' ``0```",`
M``!213H@4F5A`!X,`0````4```!33510
M`````!X`'PP!````%0```&1K:7)B>4!A8V-E$0``3%I&=0ZP/-S_``H!#P(5`J0#Y 7K`H,`4!,#5 (`8V@*
MP'-E=.XR!@`&PP*#,@/&!Q,"@T8S`\4"`'!R<1(B?,C4U`H '"H$-L0M@;F2X*A5D(8"!N8P.1$? PJ&(P&1',!F("@MYB ]
M0CT=,E]04D\LH%.04U]!5"QP0T@OUR\P\C!<,.,J\V(O,75L`P5 ,A!&04Q3
M13LM*%PC!I -L2 RX$98,QU!-$\O+R&@'_$@=?QP(!>@+C (<"*P!" =P\<%
MH1TC.&]!9G@(4!>@O2(2301P-> BP3:6(PGP/1_@9BA<.-LB$@'6@!@+V'01'EN3 N TFMP(&)R"L!Y5,$=0?=5(6BR,A!N!]%O[6U)
M;K_W/($RP&N 5%>P:+)8%3W)3FP1\'//:^5,;R1Q1'TE@&%%:#W/3Y\PXS6H
M5.Q253:.8>4Z95]F;SDU3SHA(#$ 9@/46^4X+R:])5X244A70I61#P;5]P4(%QA1DBX#(`SX,_/%95
MX85R:6.%&FZO`3$!1$5"54=?3_Q.3&O#A@^''Q5 -A%US?=Z232X%Z!T"' #
MH#6EBXS_3V8PXW:B,2\R.HR@,Q\P5[]^SW_?$?&":QVP!;%C8?3_F7]TU8U?
MCF^/=8_=B4Z>7_^?;XA_/$>$[XH/BQUZ+U./_U2758]6GU>L6A]<7UUOF"U?
MC*.O#SEQ$; %D&N;LVTO! $EXCRA>&%K7\!M&]Y?Y,OS'Z2-7RJ
M1]V."HM P#$X, +1:? M,30T#? ,T.)S"UD\,38*H -@%4 @(" MW^27"H?C
M2PPPY!9&`V&^P/_C+^0T,.-P( 6R!Y!2$@200%M33510.AK , `R-S0N,C8P
M-UY !:"V4(' +V(NZU%=O^4_YDT&8 (PYW_HBU._X/AD87DM8%20!1 #(.L@
M`2U@,3DY-B S.C0P-!-P3>Q/YDU4;__NC^B+'U$%T&-A)>)P(!4PX_)/[5YU
M8FH@$?1OZ(OUE75OE2!A004B&N"?X:.^,^L0"T85P@P!Y!90"V"/#2 %L.=A
M1/%D;W<'H8)4+6!60RLK(.K@LPIV"H5(:<%6"H57'1#GDH#D$0G 86W.(28!
M:*5Y`0(S,BU@#M D4OOA8O,.0![B96@Z$963F\$I=E\.X!"!)?$=`R2016UQ
M>?Q0;VCQOR$=DK_@YH?_[][[ SU#:P.N1^_'W11U!"BLR?"PR,E1(4D7<
M040RY =@$@!C*$T$0_Q))QWP!)H48!T`'T(&-&QO< K38;%C)3&/H6'_#&@<
MPV' # )44QZQ(P(2XK_K86-Q(O#081TR)-!&.;#_@0`M8!S18R$3AF&0@H A
M8/5S4'4*TC\\D",1E1$N,/\M8"<0-= %`QT`)8 B"QS%^P@HSR%P"?.;P@DC
M;=,!4/\A(RN0Z@!"M >('%,EX?=%>VAC'&D_X"_W 1`"K0`P`0$ `````#`!$0`0``
M`$ `!S @8%\3U26[`4 `"# @8%\3U26[`1X`/0`!````!0```%)%.B `````
*`P`--/TW``#.%B6[
`
end




Lior Messinger -- lior@trendline.co.il
Sunday, April 07, 1996

Platform: Windows NT, VC++ 4.0

Hi,

When programming a DLL in Win32, one can obtain teh reason for 
entering the DllEntryPoint main function of a DLL: because of 
DLL+PROCESS_ATTACH,DLL_THREAD_ATTACh etc.

When I'm programming with MFC, one option to create a 
DLL is to use CWinAPP and to compile as a DLL. First, is it a 
good solution? And if so, assuming that InitInstance is the 
entry point for the DLL, how can I get the reason for entring 
this entry point?


Thanks a lot,
Lior Messinger, Fundtech.






| Вернуться в корень Архива |