Source code of Windows XP (NT5)
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.

597 lines
14 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // GenScript.cpp
  7. //
  8. // Description:
  9. // DLL services/entry points for the generic script resource.
  10. //
  11. // Maintained By:
  12. // gpease 08-FEB-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "pch.h"
  16. #include "ActiveScriptSite.h"
  17. #include "ScriptResource.h"
  18. #include "SpinLock.h"
  19. //
  20. // Debugging Module Name
  21. //
  22. DEFINE_MODULE("SCRIPTRES")
  23. //
  24. // DLL Globals
  25. //
  26. HINSTANCE g_hInstance = NULL;
  27. LONG g_cObjects = 0;
  28. LONG g_cLock = 0;
  29. TCHAR g_szDllFilename[ MAX_PATH ] = { 0 };
  30. #if defined(DEBUG)
  31. LPVOID g_GlobalMemoryList = NULL; // Global memory tracking list
  32. #endif
  33. PSET_RESOURCE_STATUS_ROUTINE g_prsrCallback = NULL;
  34. extern "C"
  35. {
  36. extern CLRES_FUNCTION_TABLE GenScriptFunctionTable;
  37. #define PARAM_NAME__PATH L"Path"
  38. // GenScript resource read-write private properties
  39. RESUTIL_PROPERTY_ITEM
  40. GenScriptResourcePrivateProperties[] = {
  41. { PARAM_NAME__PATH, NULL, CLUSPROP_FORMAT_SZ, 0, 0, 0, RESUTIL_PROPITEM_REQUIRED, 0 },
  42. { NULL, NULL, 0, 0, 0, 0 }
  43. };
  44. //****************************************************************************
  45. //
  46. // DLL Entry Points
  47. //
  48. //****************************************************************************
  49. //////////////////////////////////////////////////////////////////////////////
  50. //
  51. // BOOL
  52. // WINAPI
  53. // GenScriptDllEntryPoint(
  54. // HANDLE hInstIn,
  55. // ULONG ulReasonIn,
  56. // LPVOID lpReservedIn
  57. // )
  58. //
  59. // Description:
  60. // Dll entry point.
  61. //
  62. // Arguments:
  63. // hInstIn - DLL instance handle.
  64. // ulReasonIn - DLL reason code for entrance.
  65. // lpReservedIn - Not used.
  66. //
  67. //////////////////////////////////////////////////////////////////////////////
  68. BOOL WINAPI
  69. GenScriptDllEntryPoint(
  70. HANDLE hInstIn,
  71. ULONG ulReasonIn,
  72. LPVOID // lpReservedIn
  73. )
  74. {
  75. //
  76. // KB: NO_THREAD_OPTIMIZATIONS gpease 19-OCT-1999
  77. //
  78. // By not defining this you can prvent the linker
  79. // from calling you DllEntry for every new thread.
  80. // This makes creating new thread significantly
  81. // faster if every DLL in a process does it.
  82. // Unfortunately, not all DLLs do this.
  83. //
  84. // In CHKed/DEBUG, we keep this on for memory
  85. // tracking.
  86. //
  87. #if defined( DEBUG )
  88. #define NO_THREAD_OPTIMIZATIONS
  89. #endif // DEBUG
  90. #if defined(DEBUG) || defined(NO_THREAD_OPTIMIZATIONS)
  91. switch( ulReasonIn )
  92. {
  93. case DLL_PROCESS_ATTACH:
  94. TraceInitializeProcess( NULL, NULL );
  95. TraceCreateMemoryList( g_GlobalMemoryList );
  96. #if defined( DEBUG )
  97. TraceFunc( "GenScriptDllEntryPoint( )\n" );
  98. TraceMessage( TEXT(__FILE__),
  99. __LINE__,
  100. __MODULE__,
  101. mtfDLL,
  102. TEXT("DLL: DLL_PROCESS_ATTACH - ThreadID = 0x%08x\n"),
  103. GetCurrentThreadId( )
  104. );
  105. FRETURN( TRUE );
  106. #endif // DEBUG
  107. g_hInstance = (HINSTANCE) hInstIn;
  108. GetModuleFileName( g_hInstance, g_szDllFilename, MAX_PATH );
  109. break;
  110. case DLL_PROCESS_DETACH:
  111. #if defined( DEBUG )
  112. TraceFunc( "GenScriptDllEntryPoint( )\n" );
  113. TraceMessage( TEXT(__FILE__),
  114. __LINE__,
  115. __MODULE__,
  116. mtfDLL,
  117. TEXT("DLL: DLL_PROCESS_DETACH - ThreadID = 0x%08x [ g_cLock=%u, g_cObjects=%u ]\n"),
  118. GetCurrentThreadId( ),
  119. g_cLock,
  120. g_cObjects
  121. );
  122. FRETURN( TRUE );
  123. #endif // DEBUG
  124. TraceTerminateMemoryList( g_GlobalMemoryList );
  125. TraceTerminateProcess( NULL, NULL );
  126. break;
  127. case DLL_THREAD_ATTACH:
  128. TraceInitializeThread( NULL );
  129. #if defined( DEBUG )
  130. DebugMsg( "The thread 0x%x has started.\n", GetCurrentThreadId( ) );
  131. TraceFunc( "GenScriptDllEntryPoint( )\n" );
  132. TraceMessage( TEXT(__FILE__),
  133. __LINE__,
  134. __MODULE__,
  135. mtfDLL,
  136. TEXT("DLL: DLL_THREAD_ATTACH - ThreadID = 0x%08x [ g_cLock=%u, g_cObjects=%u ]\n"),
  137. GetCurrentThreadId( ),
  138. g_cLock,
  139. g_cObjects
  140. );
  141. FRETURN( TRUE );
  142. #endif // DEBUG
  143. break;
  144. case DLL_THREAD_DETACH:
  145. #if defined( DEBUG )
  146. TraceFunc( "GenScriptDllEntryPoint( )\n" );
  147. TraceMessage( TEXT(__FILE__),
  148. __LINE__,
  149. __MODULE__,
  150. mtfDLL,
  151. TEXT("DLL: DLL_THREAD_DETACH - ThreadID = 0x%08x [ g_cLock=%u, g_cObjects=%u ]\n"),
  152. GetCurrentThreadId( ),
  153. g_cLock,
  154. g_cObjects
  155. );
  156. FRETURN( TRUE );
  157. #endif // DEBUG
  158. TraceRundownThread( );;
  159. break;
  160. default:
  161. #if defined( DEBUG )
  162. TraceFunc( "GenScriptDllEntryPoint( )\n" );
  163. TraceMessage( TEXT(__FILE__),
  164. __LINE__,
  165. __MODULE__,
  166. mtfDLL,
  167. TEXT("DLL: UNKNOWN ENTRANCE REASON - ThreadID = 0x%08x [ g_cLock=%u, g_cObjects=%u ]\n"),
  168. GetCurrentThreadId( ),
  169. g_cLock,
  170. g_cObjects
  171. );
  172. FRETURN( TRUE );
  173. #endif // DEBUG
  174. break;
  175. }
  176. return TRUE;
  177. #else // !NO_THREAD_OPTIMIZATIONS
  178. BOOL f;
  179. Assert( ulReasonIn == DLL_PROCESS_ATTACH || ulReasonIn == DLL_PROCESS_DETACH );
  180. TraceInitializeProcess( NULL, NULL );
  181. g_hInstance = (HINSTANCE) hInstIn;
  182. GetModuleFileName( g_hInstance, g_szDllFilename, MAX_PATH );
  183. f = DisableThreadLibraryCalls( g_hInstance );
  184. if ( !f )
  185. {
  186. OutputDebugString( TEXT("*ERROR* DisableThreadLibraryCalls( ) failed.") );
  187. }
  188. return TRUE;
  189. #endif // NO_THREAD_OPTIMIZATIONS
  190. } //*** GenScriptDllEntryPoint()
  191. //****************************************************************************
  192. //
  193. // Cluster Resource Entry Points
  194. //
  195. //****************************************************************************
  196. //////////////////////////////////////////////////////////////////////////////
  197. //
  198. // void
  199. // WINAPI
  200. // ScriptResClose(
  201. // RESID residIn
  202. // )
  203. //
  204. //////////////////////////////////////////////////////////////////////////////
  205. void
  206. WINAPI
  207. ScriptResClose(
  208. RESID residIn
  209. )
  210. {
  211. TraceFunc1( "ScriptResClose( residIn = 0x%08x )\n", residIn );
  212. HRESULT hr;
  213. CScriptResource * pres = reinterpret_cast< CScriptResource * >( residIn );
  214. if ( pres == NULL )
  215. goto Cleanup;
  216. hr = THR( pres->Close( ) );
  217. //
  218. // Matching Release() for object creation in ScriptResOpen( ).
  219. //
  220. pres->Release( );
  221. Cleanup:
  222. TraceFuncExit( );
  223. } //*** ScriptResClose( )
  224. //////////////////////////////////////////////////////////////////////////////
  225. //
  226. // RESID
  227. // WINAPI
  228. // ScriptResOpen(
  229. // LPCWSTR pszNameIn,
  230. // HKEY hkeyIn,
  231. // RESOURCE_HANDLE hResourceIn
  232. // )
  233. //
  234. //////////////////////////////////////////////////////////////////////////////
  235. RESID
  236. WINAPI
  237. ScriptResOpen(
  238. LPCWSTR pszNameIn,
  239. HKEY hkeyIn,
  240. RESOURCE_HANDLE hResourceIn
  241. )
  242. {
  243. TraceFunc1( "ScriptResOpen( pszNameIn = '%s', hkeyIn, hResourceIn )\n", pszNameIn );
  244. HRESULT hr;
  245. CScriptResource * pres;
  246. pres = CScriptResource_CreateInstance( pszNameIn, hkeyIn, hResourceIn );
  247. if ( pres == NULL )
  248. goto OutOfMemory;
  249. hr = THR( pres->Open( ) );
  250. Cleanup:
  251. //
  252. // KB: Don't pres->Release( ) as we are handing it out as out RESID.
  253. //
  254. RETURN( pres );
  255. OutOfMemory:
  256. hr = ERROR_OUTOFMEMORY;
  257. goto Cleanup;
  258. } //*** ScriptResOpen( )
  259. //////////////////////////////////////////////////////////////////////////////
  260. //
  261. // DWORD
  262. // WINAPI
  263. // ScriptResOnline(
  264. // RESID residIn,
  265. // PHANDLE hEventInout
  266. // )
  267. //
  268. //////////////////////////////////////////////////////////////////////////////
  269. DWORD
  270. WINAPI
  271. ScriptResOnline(
  272. RESID residIn,
  273. PHANDLE hEventInout
  274. )
  275. {
  276. TraceFunc2( "ScriptResOnline( residIn = 0x%08x, hEventInout = 0x%08x )\n",
  277. residIn, hEventInout );
  278. HRESULT hr;
  279. CScriptResource * pres = reinterpret_cast< CScriptResource * >( residIn );
  280. if ( pres == NULL )
  281. goto InvalidArg;
  282. hr = THR( pres->Online( ) );
  283. Cleanup:
  284. RETURN( hr );
  285. InvalidArg:
  286. hr = THR( E_INVALIDARG );
  287. goto Cleanup;
  288. } //*** ScriptResOnline( )
  289. //////////////////////////////////////////////////////////////////////////////
  290. //
  291. // DWORD
  292. // WINAPI
  293. // ScriptResOffline(
  294. // RESID residIn
  295. // )
  296. //
  297. //////////////////////////////////////////////////////////////////////////////
  298. DWORD
  299. WINAPI
  300. ScriptResOffline(
  301. RESID residIn
  302. )
  303. {
  304. TraceFunc1( "ScriptResOffline( residIn = 0x%08x )\n", residIn );
  305. HRESULT hr;
  306. CScriptResource * pres = reinterpret_cast< CScriptResource * >( residIn );
  307. if ( pres == NULL )
  308. goto InvalidArg;
  309. hr = THR( pres->Offline( ) );
  310. Cleanup:
  311. RETURN( hr );
  312. InvalidArg:
  313. hr = THR( E_INVALIDARG );
  314. goto Cleanup;
  315. } //*** ScriptResOffline( )
  316. //////////////////////////////////////////////////////////////////////////////
  317. //
  318. // void
  319. // WINAPI
  320. // ScriptResTerminate(
  321. // RESID residIn
  322. // )
  323. //
  324. //////////////////////////////////////////////////////////////////////////////
  325. void
  326. WINAPI
  327. ScriptResTerminate(
  328. RESID residIn
  329. )
  330. {
  331. TraceFunc1( "ScriptResTerminate( residIn = 0x%08x )\n", residIn );
  332. CScriptResource * pres = reinterpret_cast< CScriptResource * >( residIn );
  333. if ( pres == NULL )
  334. goto InvalidArg;
  335. THR( pres->Terminate( ) );
  336. Cleanup:
  337. TraceFuncExit( );
  338. InvalidArg:
  339. THR( E_INVALIDARG );
  340. goto Cleanup;
  341. } // ScriptResTerminate( )
  342. //////////////////////////////////////////////////////////////////////////////
  343. //
  344. // BOOL
  345. // WINAPI
  346. // ScriptResLooksAlive(
  347. // RESID residIn
  348. // )
  349. //
  350. //////////////////////////////////////////////////////////////////////////////
  351. BOOL
  352. WINAPI
  353. ScriptResLooksAlive(
  354. RESID residIn
  355. )
  356. {
  357. TraceFunc1( "ScriptResLooksAlive( residIn = 0x%08x )\n", residIn );
  358. HRESULT hr;
  359. BOOL bLooksAlive = FALSE;
  360. CScriptResource * pres = reinterpret_cast< CScriptResource * >( residIn );
  361. if ( pres == NULL )
  362. goto InvalidArg;
  363. hr = STHR( pres->LooksAlive( ) );
  364. if ( hr == S_OK )
  365. {
  366. bLooksAlive = TRUE;
  367. } // if: S_OK
  368. Cleanup:
  369. RETURN( bLooksAlive );
  370. InvalidArg:
  371. hr = THR( E_INVALIDARG );
  372. goto Cleanup;
  373. } //*** ScriptResLooksAlive( )
  374. //////////////////////////////////////////////////////////////////////////////
  375. //
  376. // BOOL
  377. // WINAPI
  378. // ScriptResIsAlive(
  379. // RESID residIn
  380. // )
  381. //
  382. //////////////////////////////////////////////////////////////////////////////
  383. BOOL
  384. WINAPI
  385. ScriptResIsAlive(
  386. RESID residIn
  387. )
  388. {
  389. TraceFunc1( "ScriptResIsAlive( residIn = 0x%08x )\n", residIn );
  390. HRESULT hr;
  391. BOOL bIsAlive = FALSE;
  392. CScriptResource * pres = reinterpret_cast< CScriptResource * >( residIn );
  393. if ( pres == NULL )
  394. goto InvalidArg;
  395. hr = STHR( pres->IsAlive( ) );
  396. if ( hr == S_OK )
  397. {
  398. bIsAlive = TRUE;
  399. } // if: S_OK
  400. Cleanup:
  401. RETURN( bIsAlive );
  402. InvalidArg:
  403. hr = THR( E_INVALIDARG );
  404. goto Cleanup;
  405. } //*** ScriptResIsAlive( )
  406. DWORD
  407. ScriptResResourceControl(
  408. RESID residIn,
  409. DWORD dwControlCodeIn,
  410. PVOID pvBufferIn,
  411. DWORD dwBufferInSizeIn,
  412. PVOID pvBufferOut,
  413. DWORD dwBufferOutSizeIn,
  414. LPDWORD pdwBytesReturnedOut
  415. )
  416. {
  417. TraceFunc( "ScriptResResourceControl( ... )\n " );
  418. DWORD dwErr = ERROR_SUCCESS;
  419. DWORD dwBytesRequired;
  420. *pdwBytesReturnedOut = 0;
  421. CScriptResource * pres = reinterpret_cast< CScriptResource * >( residIn );
  422. if ( pres == NULL )
  423. {
  424. dwErr = THR( E_INVALIDARG );
  425. goto Cleanup;
  426. }
  427. switch ( dwControlCodeIn )
  428. {
  429. case CLUSCTL_RESOURCE_UNKNOWN:
  430. break;
  431. case CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTY_FMTS:
  432. dwErr = ResUtilGetPropertyFormats( GenScriptResourcePrivateProperties,
  433. pvBufferOut,
  434. dwBufferOutSizeIn,
  435. pdwBytesReturnedOut,
  436. &dwBytesRequired );
  437. if ( dwErr == ERROR_MORE_DATA ) {
  438. *pdwBytesReturnedOut = dwBytesRequired;
  439. }
  440. break;
  441. default:
  442. dwErr = ERROR_INVALID_FUNCTION;
  443. break;
  444. }
  445. Cleanup:
  446. RETURN( dwErr );
  447. } //*** ScriptResResourceControl( )
  448. DWORD
  449. ScriptResTypeControl(
  450. LPCWSTR ResourceTypeName,
  451. DWORD dwControlCodeIn,
  452. PVOID pvBufferIn,
  453. DWORD dwBufferInSizeIn,
  454. PVOID pvBufferOut,
  455. DWORD dwBufferOutSizeIn,
  456. LPDWORD pdwBytesReturnedOut
  457. )
  458. {
  459. TraceFunc( "ScriptResTypeControl( ... )\n " );
  460. DWORD dwErr = ERROR_SUCCESS;
  461. DWORD dwBytesRequired;
  462. *pdwBytesReturnedOut = 0;
  463. switch ( dwControlCodeIn )
  464. {
  465. case CLUSCTL_RESOURCE_TYPE_UNKNOWN:
  466. break;
  467. case CLUSCTL_RESOURCE_TYPE_GET_PRIVATE_RESOURCE_PROPERTY_FMTS:
  468. dwErr = ResUtilGetPropertyFormats( GenScriptResourcePrivateProperties,
  469. pvBufferOut,
  470. dwBufferOutSizeIn,
  471. pdwBytesReturnedOut,
  472. &dwBytesRequired );
  473. if ( dwErr == ERROR_MORE_DATA ) {
  474. *pdwBytesReturnedOut = dwBytesRequired;
  475. }
  476. break;
  477. default:
  478. dwErr = ERROR_INVALID_FUNCTION;
  479. break;
  480. }
  481. RETURN( dwErr );
  482. } //*** ScriptResTypeControl( )
  483. //***********************************************************
  484. //
  485. // Define Function Table
  486. //
  487. //***********************************************************
  488. CLRES_V1_FUNCTION_TABLE( GenScriptFunctionTable, // Name
  489. CLRES_VERSION_V1_00, // Version
  490. ScriptRes, // Prefix
  491. NULL, // Arbitrate
  492. NULL, // Release
  493. ScriptResResourceControl, // ResControl
  494. ScriptResTypeControl // ResTypeControl
  495. );
  496. } // extern "C"