CPI_Player_FileAssoc.c
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:3k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "globals.h"
  3. #include "CPI_Player_CoDec.h"
  4. typedef struct _CPs_FileAssociation
  5. {
  6.     char* m_pcExtension;
  7.     DWORD m_dwCookie;
  8.     void* m_pNext;
  9. } CPs_FileAssociation;
  10. //
  11. void CPFA_InitialiseFileAssociations(CPs_CoDecModule* pCoDec)
  12. {
  13.     pCoDec->m_pFileAssociationCookie = NULL;
  14. }
  15. void CPFA_EmptyFileAssociations(CPs_CoDecModule* pCoDec)
  16. {
  17.     CPs_FileAssociation* pCursor = (CPs_FileAssociation*)pCoDec->m_pFileAssociationCookie;
  18.     CPs_FileAssociation* pNext;
  19.     while(pCursor)
  20.     {
  21.         CP_CHECKOBJECT(pCursor);
  22.         pNext = (CPs_FileAssociation*)pCursor->m_pNext;
  23.         free(pCursor->m_pcExtension);
  24.         free(pCursor);
  25.         pCursor = pNext;
  26.     }
  27. }
  28. void CPFA_AddFileAssociation(CPs_CoDecModule* pCoDec, const char* pcExtension, DWORD dwCookie)
  29. {
  30.     CPs_FileAssociation* pNewAssociation = (CPs_FileAssociation*)malloc(sizeof(CPs_FileAssociation));
  31.     CPs_FileAssociation* pCursor = (CPs_FileAssociation*)pCoDec->m_pFileAssociationCookie;
  32.     while(pCursor)
  33.     {
  34.         if(stricmp(pcExtension, pCursor->m_pcExtension) == 0)
  35.         {
  36.             CP_TRACE1("** Extension "%s" already registered here", pcExtension);
  37.             return;
  38.         }
  39.         pCursor = (CPs_FileAssociation*)pCursor->m_pNext;
  40.     }
  41.     STR_AllocSetString(&pNewAssociation->m_pcExtension, pcExtension, FALSE);
  42.     pNewAssociation->m_dwCookie = dwCookie;
  43.     pNewAssociation->m_pNext = pCoDec->m_pFileAssociationCookie;
  44.     pCoDec->m_pFileAssociationCookie = pNewAssociation;
  45. }
  46. //
  47. BOOL CPFA_IsAssociated(CPs_CoDecModule* pCoDec, const char* pcExtension, DWORD* pdwCookie)
  48. {
  49.     CPs_FileAssociation* pCursor = (CPs_FileAssociation*)pCoDec->m_pFileAssociationCookie;
  50.     while(pCursor)
  51.     {
  52.         CP_CHECKOBJECT(pCursor);
  53.         if(stricmp(pcExtension, pCursor->m_pcExtension) == 0)
  54.         {
  55.             *pdwCookie = pCursor->m_dwCookie;
  56.             return TRUE;
  57.         }
  58.         pCursor = (CPs_FileAssociation*)pCursor->m_pNext;
  59.     }
  60.     return FALSE;
  61. }
  62. void CPFA_AssociateWithEXE(CPs_CoDecModule* pCoDec)
  63. {
  64.     CPs_FileAssociation* pCursor = (CPs_FileAssociation*)pCoDec->m_pFileAssociationCookie;
  65.     HKEY hKey;
  66.     DWORD dwDisposition;
  67.     while(pCursor)
  68.     {
  69.         char* pDotExt;
  70.         CP_CHECKOBJECT(pCursor);
  71.         pDotExt = (char*)malloc(strlen(pCursor->m_pcExtension) + 2);
  72.         pDotExt[0] = '.';
  73.         strcpy(pDotExt + 1, pCursor->m_pcExtension);
  74.         CP_TRACE1("Associating extension: "%s"", pCursor->m_pcExtension);
  75.         RegCreateKeyEx(HKEY_CLASSES_ROOT, pDotExt, 0, NULL,
  76.                        REG_OPTION_NON_VOLATILE,
  77.                        KEY_ALL_ACCESS, NULL, &hKey,
  78.                        &dwDisposition);
  79.         RegSetValueEx(hKey, NULL, 0, REG_SZ, CIC_COOLPLAYER_FILETYPE, sizeof(CIC_COOLPLAYER_FILETYPE));
  80.         RegCloseKey(hKey);
  81.         free(pDotExt);
  82.         pCursor = (CPs_FileAssociation*)pCursor->m_pNext;
  83.     }
  84. }
  85. //