Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
7.0 KiB

  1. /** FILE: ports.c ********** Module Header ********************************
  2. *
  3. * DLL entry point.
  4. *
  5. *
  6. * Copyright (C) 2000 Cyclades Corporation
  7. *
  8. *************************************************************************/
  9. //==========================================================================
  10. // Include files
  11. //==========================================================================
  12. // C Runtime
  13. #include <stddef.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. // Application specific
  17. #include "cyyports.h"
  18. #include <msports.h>
  19. //==========================================================================
  20. // Globals
  21. //==========================================================================
  22. HANDLE g_hInst = NULL;
  23. TCHAR g_szErrMem[ 200 ]; // Low memory message
  24. TCHAR g_szPortsApplet[ 30 ]; // "Ports Control Panel Applet" title
  25. TCHAR g_szNull[] = TEXT(""); // Null string
  26. TCHAR m_szColon[] = TEXT( ":" );
  27. TCHAR m_szPorts[] = TEXT( "Ports" );
  28. TCHAR m_szCOM[] = TEXT( "COM" );
  29. //
  30. // NT Registry keys to find COM port to Serial Device mapping
  31. //
  32. TCHAR m_szRegSerialMap[] = TEXT( "Hardware\\DeviceMap\\SerialComm" );
  33. //
  34. // Registry Serial Port Advanced I/O settings key and valuenames
  35. //
  36. TCHAR m_szFIFO[] = TEXT( "ForceFifoEnable" );
  37. TCHAR m_szPollingPeriod[] = TEXT( "PollingPeriod" );
  38. TCHAR m_szPortName[] = REGSTR_VAL_PORTNAME;
  39. TCHAR m_szDefParams[] = TEXT( "9600,n,8,1" );
  40. //==========================================================================
  41. // Local Function Prototypes
  42. //==========================================================================
  43. LPTSTR GetDIFString(IN DI_FUNCTION Func);
  44. //==========================================================================
  45. // Dll Entry Point
  46. //==========================================================================
  47. BOOL APIENTRY LibMain( HANDLE hDll, DWORD dwReason, LPVOID lpReserved )
  48. {
  49. switch( dwReason )
  50. {
  51. case DLL_PROCESS_ATTACH:
  52. // DbgOut(TEXT("cyyports DLL_PROCESS_ATTACH\n"));
  53. g_hInst = hDll;
  54. DisableThreadLibraryCalls(hDll);
  55. InitStrings();
  56. break;
  57. case DLL_PROCESS_DETACH:
  58. // DbgOut(TEXT("cyyports DLL_PROCESS_DETACH\n"));
  59. break;
  60. default:
  61. break;
  62. }
  63. return TRUE;
  64. }
  65. //==========================================================================
  66. // Functions
  67. //==========================================================================
  68. HRESULT
  69. CyyportCoInstaller(
  70. IN DI_FUNCTION InstallFunction,
  71. IN HDEVINFO DeviceInfoSet,
  72. IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
  73. IN OUT PCOINSTALLER_CONTEXT_DATA Context
  74. )
  75. /*++
  76. Routine Description:
  77. This routine is a Co-Installer for the Cyclom-Y Port device.
  78. Arguments:
  79. InstallFunction - Specifies the device installer function code indicating
  80. the action being performed.
  81. DeviceInfoSet - Supplies a handle to the device information set being
  82. acted upon by this install action.
  83. DeviceInfoData - Optionally, supplies the address of a device information
  84. element being acted upon by this install action.
  85. Context - Points to a coinstaller-specific context structure for this
  86. installation request.
  87. Return Value:
  88. If this function successfully completed the requested action, the return
  89. value is NO_ERROR.
  90. If an error occurred while attempting to perform the requested action, a
  91. Win32 error code is returned.
  92. --*/
  93. {
  94. DWORD dwSize;
  95. TCHAR instanceId[MAX_DEVICE_ID_LEN];
  96. TCHAR parentIdPrefix[50];
  97. HKEY enumKey,instKey;
  98. BOOL gotParentIdPrefix;
  99. DWORD Status = NO_ERROR;
  100. // #if DBG
  101. // {
  102. // TCHAR buf[500];
  103. // wsprintf(buf, TEXT("CyyportCoInstaller:InstallFunction(%s) PostProcessing:%d\n"), GetDIFString(InstallFunction), Context->PostProcessing);
  104. // DbgOut(buf);
  105. // }
  106. // #endif
  107. switch(InstallFunction) {
  108. case DIF_INSTALLDEVICE :
  109. //
  110. // We should not copy any INF files until the install has completed
  111. // like the primary INF, all secondary INF's must exist on each disk
  112. // of a multi-disk install.
  113. //
  114. if(!Context->PostProcessing) {
  115. Status = ERROR_DI_POSTPROCESSING_REQUIRED;
  116. } else {
  117. if (Context->InstallResult != NO_ERROR) {
  118. DbgOut(TEXT("DIF_INSTALLDEVICE PostProcessing on failure"));
  119. Status = Context->InstallResult;
  120. break;
  121. }
  122. ReplaceFriendlyName(DeviceInfoSet,DeviceInfoData,NULL);
  123. }
  124. break;
  125. default :
  126. break;
  127. }
  128. return Status;
  129. }
  130. LPTSTR GetDIFString(IN DI_FUNCTION Func)
  131. /*++
  132. Routine Description:
  133. Given a DI_FUNCTION value, returns a text representation.
  134. Arguments:
  135. Func - DI_FUNCTON value
  136. Return Value:
  137. Text string if value is known. Hex representation if not.
  138. --*/
  139. {
  140. static TCHAR buf[32];
  141. #define MakeCase(d) case d: return TEXT(#d)
  142. switch (Func)
  143. {
  144. MakeCase(DIF_SELECTDEVICE);
  145. MakeCase(DIF_INSTALLDEVICE);
  146. MakeCase(DIF_ASSIGNRESOURCES);
  147. MakeCase(DIF_PROPERTIES);
  148. MakeCase(DIF_REMOVE);
  149. MakeCase(DIF_FIRSTTIMESETUP);
  150. MakeCase(DIF_FOUNDDEVICE);
  151. MakeCase(DIF_SELECTCLASSDRIVERS);
  152. MakeCase(DIF_VALIDATECLASSDRIVERS);
  153. MakeCase(DIF_INSTALLCLASSDRIVERS);
  154. MakeCase(DIF_CALCDISKSPACE);
  155. MakeCase(DIF_DESTROYPRIVATEDATA);
  156. MakeCase(DIF_VALIDATEDRIVER);
  157. MakeCase(DIF_MOVEDEVICE);
  158. MakeCase(DIF_DETECT);
  159. MakeCase(DIF_INSTALLWIZARD);
  160. MakeCase(DIF_DESTROYWIZARDDATA);
  161. MakeCase(DIF_PROPERTYCHANGE);
  162. MakeCase(DIF_ENABLECLASS);
  163. MakeCase(DIF_DETECTVERIFY);
  164. MakeCase(DIF_INSTALLDEVICEFILES);
  165. MakeCase(DIF_UNREMOVE);
  166. MakeCase(DIF_SELECTBESTCOMPATDRV);
  167. MakeCase(DIF_ALLOW_INSTALL);
  168. MakeCase(DIF_REGISTERDEVICE);
  169. MakeCase(DIF_INSTALLINTERFACES);
  170. MakeCase(DIF_DETECTCANCEL);
  171. MakeCase(DIF_REGISTER_COINSTALLERS);
  172. MakeCase(DIF_NEWDEVICEWIZARD_FINISHINSTALL);
  173. MakeCase(DIF_ADDPROPERTYPAGE_ADVANCED);
  174. MakeCase(DIF_TROUBLESHOOTER);
  175. default:
  176. wsprintf(buf, TEXT("%x"), Func);
  177. return buf;
  178. }
  179. }
  180. void InitStrings(void)
  181. {
  182. DWORD dwClass, dwShare;
  183. TCHAR szClass[ 40 ];
  184. LoadString(g_hInst,
  185. INITS,
  186. g_szErrMem,
  187. CharSizeOf(g_szErrMem));
  188. LoadString(g_hInst,
  189. IDS_INIT_NAME,
  190. g_szPortsApplet,
  191. CharSizeOf(g_szPortsApplet));
  192. }