Re: DllMain vs. DllMain
- From: "Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx>
- Date: Wed, 1 Feb 2006 10:33:48 +0900
OK "m" you are right on one point, but my hand still needs holding.
You are right that page http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Initialize_Non.2d.MFC_DLLs.asp concerns VS .Net. So I apologize for quoting that page.
Now let's look at pages for VC++6. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_initialize_non.2d.mfc_dlls.asp This one says the same as the .Net version said, but this is for VC++6.
BOOL APIENTRY DllMain( HANDLE hModule,
> DWORD ul_reason_for_call, > LPVOID lpReserved)
Meanwhile the other page http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp still says what it said before.
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Now, is a user of VC++6 supposed to obey the MSDN page that tells VC++6 programmers how to interact with the API, or is a user of VC++6 supposed to obey the MSDN page that says what the API itself is?
I'm looking again at a page that you cited.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/dllprocessthreads.asp
In that page, I do not see any statement about whether it (or other pages) contains instructions for VC++6 programmers or descriptions of the APIs themselves. You said that this page was the way that you knew some of the information you wrote, but I don't see it on this page. So I'm afraid my hand still needs holding.
Thank you for your descriptions of internal behaviour of some parts of Windows. Indeed I am not opposed to learning about such things and I don't have any complaint about that. However, I am opposed to writing programs that depend on such undocumented internal behaviour. Such a program might work this morning and fail this afternoon because undocumented behaviour is subject to change at any time. Some famous Microsoft employees hate companies that depend on undocumented behaviour, and in this kind of situation I agree.
"m" <m@xxx> wrote in message news:u84U6tnJGHA.1192@xxxxxxxxxxxxxxxxxxxxxxx
At the top of page #1 it says:
'Visual C++ Concepts: Adding Functionality'
At the top of page #2 it says:
'Platform SDK: DLLs, Processes, and Threads'
Page #1 is part of the documentation for Visual Studio .NET - this is included to help people use VS.NET and is geared toward Win32 development.
Page #2 is part of the actual Win32 API documentation. This is the page that documents the actual API.
Now you may ask, "how do you know this?". I respond: I know this because on the page
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/dllprocessthreads.asp
it tells me that the platform SDK contains this type of documentation. MSDN is NOT a single API ref for windows, it is a library with lots of stuff - most of it junk - that includes the API references for windows. if you want, you can even look in the archives for lot of old junk.
BTW: always use WINAPI, APIENTRY will work (it is __stdcall), but it is the wrong macro
The actual PE entry point prototype (which you can find in MSDN too - look for PE) is:
int __stdcall Entry(void* var1, DWORD var2, void* var3)
This is usually implemented by the CRT as WinMainCRTStartup, mainCRTStartup, or DllMainCRTStartup (you can see this in crt0.c and crtdll.c if you installed the CRT source with VS.NET)
The CRT initializes itself and then calls your entry point.
"Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx> wrote in message news:%23cRz9dgJGHA.1192@xxxxxxxxxxxxxxxxxxxxxxx"m", I GAVE YOU TWO (2) URLS TO HELP. I QUOTED FROM BOTH OF THEM.
But yes, if you know how to determine that one of those MSDN pages is right while the other one is wrong, then yes I do need your fu**ing hand to point me to where MSDN says which of its pages is wrong.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Initialize_Non.2d.MFC_DLLs.asp says:BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp says:BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
"m", you wrote "Rest assured: HANDLE is NOT equivalent to HINSTANCE." Excellent, thank you, now you know why I posted my question. Now RTFM and lend a hand.
"m" <m@xxx> wrote in message news:u3x92QgJGHA.1388@xxxxxxxxxxxxxxxxxxxxxxxIf you need a URL to help:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/windows_data_types.asp
"m" <m@xxx> wrote in message news:%23NfbCNgJGHA.2704@xxxxxxxxxxxxxxxxxxxxxxxShould I hold your hand?
1) go to http://msdn.microsoft.com
2) in the search box type 'DLLMain'
3) click the first link
4) copy the prototype
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved
);
Rest assured: HANDLE is NOT equivalent to HINSTANCE. HISNSTANCE IS equivalent to HMODULE - this IS documented in MSDN
"Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx> wrote in message news:euKUyzfJGHA.2864@xxxxxxxxxxxxxxxxxxxxxxx>I am looking at the definition of the DECLARE_HANDLE macro in file Winnt.hin the Platform SDK from year 2003. It does not tell me the definition of HINSTANCE. In fact the entire file does not tell me the definition of HINSTANCE. However, if the STRICT macro is defined then the Platform SDK makes a half-hearted effort to catch programs that accidentally interchange different kinds of handles. So I think HANDLE and HINSTANCE are intended to be not interchangeable.
I am looking again at the definition of the DECLARE_HANDLE macro in file Winnt.h in the Platform SDK from year 2003. It does not tell me if a service pack will change the definition tomorrow. It does not tell me where to find a statement in MSDN to say "Don't read MSDN, read the source code to see what definitions you should rely on when you write programs (or DLLs)."
Some very famous Microsoft employees hate programmers relying on undocumented behaviour. I think they might hate programmers violating documented behaviour too. Well in this case, no matter how I define dllmain, my definition will violate at least one of these two MSDN pages.
Now, is one of these pages correct? If so, which one? If not, then what is the correct calling sequence for dllmain?
"Arkady Frenkel" <arkadyf@xxxxxxxxxxxxxxxx> wrote in message news:ONPaefZJGHA.1032@xxxxxxxxxxxxxxxxxxxxxxxLook windef.h and at definition of DECLARE_HANDLE macro in Winnt.h Arkady
"Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx> wrote in message news:eiM$rcYJGHA.528@xxxxxxxxxxxxxxxxxxxxxxxAre types HANDLE and HINSTANCE guaranteed to be interchangeable? If yes, where? (Other than logical inference from the following ^_^) If not, which of the following is correct?
While we're at it, are APIENTRY and WINAPI guaranteed to be equally "noisy"?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Initialize_Non.2d.MFC_DLLs.asp says:BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp says:BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
.
- Follow-Ups:
- Re: DllMain vs. DllMain
- From: "Jeffrey Tan[MSFT]"
- Re: DllMain vs. DllMain
- From: m
- Re: DllMain vs. DllMain
- Prev by Date: Re: Sudden decrease in available virtual address space
- Next by Date: Re: Using RegDeleteKey() to delete RunOnce key in WinXP x64
- Previous by thread: Re: Sudden decrease in available virtual address space
- Next by thread: Re: DllMain vs. DllMain
- Index(es):
Relevant Pages
|