dllmain.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright 2001 Sun Microsystems, Inc.
  3. * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. /*
  7. * Microsoft Windows specifics for BACK-LDBM DLL
  8. */
  9. #include "ldap.h"
  10. #include "lber.h"
  11. #ifdef _WIN32
  12. /* Lifted from Q125688
  13. * How to Port a 16-bit DLL to a Win32 DLL
  14. * on the MSVC 4.0 CD
  15. */
  16. BOOL WINAPI DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
  17. {
  18. WSADATA wsadata;
  19. switch (fdwReason)
  20. {
  21. case DLL_PROCESS_ATTACH:
  22. /* Code from LibMain inserted here. Return TRUE to keep the
  23. DLL loaded or return FALSE to fail loading the DLL.
  24. You may have to modify the code in your original LibMain to
  25. account for the fact that it may be called more than once.
  26. You will get one DLL_PROCESS_ATTACH for each process that
  27. loads the DLL. This is different from LibMain which gets
  28. called only once when the DLL is loaded. The only time this
  29. is critical is when you are using shared data sections.
  30. If you are using shared data sections for statically
  31. allocated data, you will need to be careful to initialize it
  32. only once. Check your code carefully.
  33. Certain one-time initializations may now need to be done for
  34. each process that attaches. You may also not need code from
  35. your original LibMain because the operating system may now
  36. be doing it for you.
  37. */
  38. /*
  39. * 16 bit code calls UnlockData()
  40. * which is mapped to UnlockSegment in windows.h
  41. * in 32 bit world UnlockData is not defined anywhere
  42. * UnlockSegment is mapped to GlobalUnfix in winbase.h
  43. * and the docs for both UnlockSegment and GlobalUnfix say
  44. * ".. function is oboslete. Segments have no meaning
  45. * in the 32-bit environment". So we do nothing here.
  46. */
  47. if( errno = WSAStartup(0x0101, &wsadata ) != 0 )
  48. return FALSE;
  49. break;
  50. case DLL_THREAD_ATTACH:
  51. /* Called each time a thread is created in a process that has
  52. already loaded (attached to) this DLL. Does not get called
  53. for each thread that exists in the process before it loaded
  54. the DLL.
  55. Do thread-specific initialization here.
  56. */
  57. break;
  58. case DLL_THREAD_DETACH:
  59. /* Same as above, but called when a thread in the process
  60. exits.
  61. Do thread-specific cleanup here.
  62. */
  63. break;
  64. case DLL_PROCESS_DETACH:
  65. /* Code from _WEP inserted here. This code may (like the
  66. LibMain) not be necessary. Check to make certain that the
  67. operating system is not doing it for you.
  68. */
  69. WSACleanup();
  70. break;
  71. }
  72. /* The return value is only used for DLL_PROCESS_ATTACH; all other
  73. conditions are ignored. */
  74. return TRUE; // successful DLL_PROCESS_ATTACH
  75. }
  76. #else
  77. int CALLBACK
  78. LibMain( HINSTANCE hinst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine )
  79. {
  80. /*UnlockData( 0 );*/
  81. return( 1 );
  82. }
  83. #endif