PlugInApp.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // PlugInApp.cpp : Defines the initialization routines for the DLL.
  2. //
  3. #include "stdafx.h"
  4. #include "PlugInApp.h"
  5. ////////////////////////////////////////////////////////////////////////////////
  6. extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
  7. BOOL WINAPI DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pv)
  8. {
  9. return DllEntryPoint( hInstance, ulReason, pv );
  10. }
  11. ////////////////////////////////////////////////////////////////////////////////
  12. LONG recursiveDeleteKey( HKEY hKeyParent, // Parent of key to delete
  13. const char* lpszKeyChild ) // Key to delete
  14. {
  15. // Open the child.
  16. HKEY hKeyChild ;
  17. LONG lRes = RegOpenKeyEx( hKeyParent, lpszKeyChild, 0, KEY_ALL_ACCESS, &hKeyChild );
  18. if (lRes != ERROR_SUCCESS)
  19. {
  20. return lRes;
  21. }
  22. // Enumerate all of the decendents of this child.
  23. FILETIME time;
  24. char szBuffer[ 256 ];
  25. DWORD dwSize = 256;
  26. while (RegEnumKeyEx( hKeyChild, 0, szBuffer, &dwSize, NULL, NULL, NULL, &time ) == S_OK)
  27. {
  28. // Delete the decendents of this child.
  29. lRes = recursiveDeleteKey( hKeyChild, szBuffer );
  30. if (lRes != ERROR_SUCCESS)
  31. {
  32. // Cleanup before exiting.
  33. RegCloseKey( hKeyChild );
  34. return lRes;
  35. }
  36. dwSize = 256;
  37. }
  38. // Close the child.
  39. RegCloseKey( hKeyChild );
  40. // Delete this child.
  41. return RegDeleteKey( hKeyParent, lpszKeyChild );
  42. }
  43. ////////////////////////////////////////////////////////////////////////////////
  44. static const char* s_pszReg = "CakewalkPlugIns\\";
  45. extern CFactoryTemplate g_Templates[];
  46. extern int g_cTemplates;
  47. ////////////////////////////////////////////////////////////////////////////////
  48. STDAPI DllRegisterServer()
  49. {
  50. HKEY hKey = 0;
  51. char sz[ _MAX_PATH ];
  52. OLECHAR wsz[ _MAX_PATH ];
  53. char szCLSID[ 64 ];
  54. ITypeLib* pTypeLib = 0;
  55. int i = 0;
  56. HRESULT hr = E_FAIL;
  57. // Do DirectShow registration
  58. hr = AMovieDllRegisterServer2( TRUE );
  59. if (FAILED( hr ))
  60. goto DONE;
  61. // Get our full pathname, converting to multibyte
  62. GetModuleFileName( g_hInst, sz, sizeof sz );
  63. if (0 == MultiByteToWideChar( CP_ACP, 0, sz, _MAX_PATH, wsz, _MAX_PATH ))
  64. goto DONE;
  65. // Iterate over all exported CLSIDs
  66. for (i = 0; i < g_cTemplates; i++)
  67. {
  68. CFactoryTemplate* pT = &g_Templates[ i ];
  69. if (NULL != pT->m_pAMovieSetup_Filter)
  70. {
  71. // For backwards compatability, instantiate all servers and get hold of
  72. // IAMovieSetup (if implemented) and call IAMovieSetup.Register() method
  73. if (NULL != pT->m_lpfnNew)
  74. {
  75. IAMovieSetup* pSetup = 0;
  76. if (SUCCEEDED( CoCreateInstance( *(pT->m_ClsID), 0, CLSCTX_INPROC_SERVER,
  77. IID_IAMovieSetup, (void**)&pSetup ) ))
  78. {
  79. pSetup->Register();
  80. pSetup->Release();
  81. }
  82. }
  83. // Convert the CLSID to an ANSI string
  84. StringFromGUID2( *(pT->m_ClsID), wsz, sizeof wsz );
  85. if (0 == WideCharToMultiByte( CP_ACP, 0, wsz, -1, szCLSID, sizeof szCLSID, NULL, NULL ))
  86. goto DONE;
  87. // Add {...} to HKEY_CLASSES_ROOT\<s_pszReg>
  88. strcpy( sz, s_pszReg );
  89. strcat( sz, szCLSID );
  90. if (ERROR_SUCCESS != RegCreateKey( HKEY_CLASSES_ROOT, sz, &hKey ))
  91. goto DONE;
  92. // {...}\Description = <description text>
  93. if (0 == WideCharToMultiByte( CP_ACP, 0, pT->m_Name, -1, sz, sizeof sz, NULL, NULL ))
  94. goto DONE;
  95. RegSetValueEx( hKey, "Description", 0, REG_SZ, (BYTE*)sz, strlen(sz) );
  96. // Written for backwards compatability with SONAR 1.x and Pro Audio:
  97. // {...}\HelpFilePath = ""
  98. // {...}\HelpFileTopic = ""
  99. *sz = 0;
  100. RegSetValueEx( hKey, "HelpFilePath", 0, REG_SZ, (BYTE*)sz, 1 );
  101. RegSetValueEx( hKey, "HelpFileTopic", 0, REG_SZ, (BYTE*)sz, 1 );
  102. RegCloseKey( hKey );
  103. hKey = 0;
  104. }
  105. }
  106. hr = S_OK;
  107. DONE:
  108. if (hKey)
  109. RegCloseKey( hKey );
  110. return hr;
  111. }
  112. ////////////////////////////////////////////////////////////////////////////////
  113. STDAPI DllUnregisterServer()
  114. {
  115. char sz[ _MAX_PATH ];
  116. OLECHAR wsz[ _MAX_PATH ];
  117. char szCLSID[ 64 ];
  118. int i = 0;
  119. HRESULT hr = E_FAIL;
  120. // Do DirectShow unregistration
  121. hr = AMovieDllRegisterServer2( FALSE );
  122. if (FAILED( hr ))
  123. goto DONE;
  124. // Iterate over all exported CLSIDs
  125. for (i = 0; i < g_cTemplates; i++)
  126. {
  127. CFactoryTemplate* pT = &g_Templates[ i ];
  128. // For backwards compatability, instantiate all servers and get hold of
  129. // IAMovieSetup (if implemented) and call IAMovieSetup.Register() method
  130. if (NULL != pT->m_lpfnNew)
  131. {
  132. IAMovieSetup* pSetup = 0;
  133. if (SUCCEEDED( CoCreateInstance( *(pT->m_ClsID), 0, CLSCTX_INPROC_SERVER,
  134. IID_IAMovieSetup, (void**)&pSetup ) ))
  135. {
  136. pSetup->Unregister();
  137. pSetup->Release();
  138. }
  139. }
  140. // Convert the CLSID to an ANSI string
  141. StringFromGUID2( *(pT->m_ClsID), wsz, sizeof wsz );
  142. if (0 == WideCharToMultiByte( CP_ACP, 0, wsz, -1, szCLSID, sizeof szCLSID, NULL, NULL ))
  143. goto DONE;
  144. // Delete HKEY_CLASSES_ROOT\<s_pszReg>
  145. strcpy( sz, s_pszReg );
  146. strcat( sz, szCLSID );
  147. recursiveDeleteKey( HKEY_CLASSES_ROOT, sz );
  148. }
  149. hr = S_OK;
  150. DONE:
  151. return hr;
  152. }
  153. ////////////////////////////////////////////////////////////////////////////////