dllmain.c 2.9 KB

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