// ------------------------------------------------ // // FUNCTION: sys_GetRegKey( PA_PluginParameters params ) // // PURPOSE: Get a key from the registry. // // DATE: MJG 12/4/03 (3.5.6) // void sys_GetRegKey( PA_PluginParameters params ) { LONG_PTR returnValue, regKey, retErr, dataSize, arraySize, expandDataSize; LONG_PTR i, len; char regSub[MAXBUF]; char regName[MAXBUF]; char *returnDataBuffer, *ptrData; HKEY hRootKey; HKEY hOpenKey; DWORD dwDataType; DWORD dwReturnLong; PA_Variable paReturnArray; // AMS2 12/9/14 #41400 Initalized the dataSize variable. In 64 bit environments this can be randomly initalized to a size in bytes // that is larger than malloc can allot, causing it to return null and crash when returning to 4D. Remember to always initialize your size variables. dataSize = 0; returnValue = regKey = retErr = arraySize = expandDataSize = 0; hRootKey = hOpenKey = 0; ptrData = returnDataBuffer = NULL; memset(regSub, 0, MAXBUF); memset(regName, 0, MAXBUF); // Get the function parameters. regKey = PA_GetLongParameter( params, 1 ); PA_GetTextParameter( params, 2, regSub ); PA_GetTextParameter( params, 3, regName ); // Convert the 4d registry constant into a Windows registry key. hRootKey = getRootKey( regKey ); // Open the registry key. retErr = RegOpenKeyEx(hRootKey, regSub, 0, KEY_READ, &hOpenKey); if(retErr == ERROR_SUCCESS){ // Get the value type and size. retErr = RegQueryValueEx(hOpenKey, regName, NULL, &dwDataType, NULL, &dataSize); if(retErr == ERROR_SUCCESS){ switch(dwDataType){ case REG_BINARY: returnDataBuffer = malloc(dataSize); retErr = RegQueryValueEx(hOpenKey, regName, NULL, NULL, (LPBYTE) returnDataBuffer, &dataSize); if(retErr == ERROR_SUCCESS){ PA_SetBlobParameter(params, 4, returnDataBuffer, dataSize); returnValue = 1; } free(returnDataBuffer); break; case REG_DWORD: case REG_DWORD_BIG_ENDIAN: dataSize = sizeof(dwReturnLong); retErr = RegQueryValueEx(hOpenKey, regName, NULL, NULL, (LPBYTE) &dwReturnLong, &dataSize); if(retErr == ERROR_SUCCESS){ PA_SetLongParameter(params, 4, dwReturnLong); returnValue = 1; } break; case REG_EXPAND_SZ: returnDataBuffer = malloc(dataSize); retErr = RegQueryValueEx (hOpenKey, regName, NULL, NULL, returnDataBuffer, &dataSize); if(retErr == ERROR_SUCCESS) { regExpandStr(&returnDataBuffer); PA_SetTextParameter(params, 4, returnDataBuffer, strlen(returnDataBuffer)); returnValue = 1; } free(returnDataBuffer); break; case REG_MULTI_SZ: returnDataBuffer = malloc(dataSize); paReturnArray = PA_GetVariableParameter( params, 4 ); retErr = RegQueryValueEx(hOpenKey, regName, NULL, NULL, returnDataBuffer, &dataSize); if(retErr == ERROR_SUCCESS) { arraySize = regGetNumElements(returnDataBuffer); PA_ResizeArray(&paReturnArray, arraySize); for(i = 1, ptrData = returnDataBuffer; i <= arraySize; i++) { len = strlen(ptrData); PA_SetTextInArray(paReturnArray, i, ptrData, len); ptrData+=len+1; } returnValue = 1; PA_SetVariableParameter( params, 4, paReturnArray, 0 ); } free(returnDataBuffer); break; case REG_SZ: returnDataBuffer = (char*)malloc(dataSize); retErr = RegQueryValueEx(hOpenKey, regName, NULL, NULL, returnDataBuffer, &dataSize); if(retErr == ERROR_SUCCESS){ PA_SetTextParameter(params, 4, returnDataBuffer, dataSize-1); returnValue = 1; } free(returnDataBuffer); break; } } } RegCloseKey( hOpenKey ); PA_ReturnLong( params, returnValue ); }
// ------------------------------------------------ // // FUNCTION: sys_GetRegType( PA_PluginParameters params ) // // PURPOSE: Get a key from the registry. // // DATE: MJG 12/4/03 (3.5.6) // void sys_GetRegType( PA_PluginParameters params ) { LONG_PTR returnValue, regKey, retErr; char regSub[MAXBUF]; char regName[MAXBUF]; char *returnDataBuffer; HKEY hRootKey; HKEY hOpenKey; DWORD dwDataType; returnValue = regKey = retErr = 0; hRootKey = hOpenKey = 0; returnDataBuffer = NULL; memset(regSub, 0, MAXBUF); memset(regName, 0, MAXBUF); // Get the function parameters. regKey = PA_GetLongParameter( params, 1 ); PA_GetTextParameter( params, 2, regSub ); PA_GetTextParameter( params, 3, regName ); // Convert the 4d registry constant into a Windows registry key. hRootKey = getRootKey( regKey ); // Open the registry key. retErr = RegOpenKeyEx(hRootKey, regSub, 0, KEY_READ, &hOpenKey); if(retErr == ERROR_SUCCESS){ // Get the value type and size. retErr = RegQueryValueEx(hOpenKey, regName, NULL, &dwDataType, NULL, NULL); if(retErr == ERROR_SUCCESS){ returnValue = get4dRegType(dwDataType); } } RegCloseKey( hOpenKey ); PA_ReturnLong( params, returnValue ); }
Chord Chord::getTransposedVersion(int semitones) const { if (semitones == 0) return Chord(getChordText(), getBeat()); QString newRootKey = getTransposedRoot(getRootKey(), semitones); QString newChordText = newRootKey; if (hasLettersAfterRoot()) newChordText += getLettersAfterRoot(); if (hasLastPart()) newChordText += getLastPart(); if (hasBassInversion()) { QString newBassInversionRoot = getTransposedRoot(getBassInversion(), semitones); newChordText += "/" + newBassInversionRoot; } return Chord(newChordText, getBeat()); }
// ------------------------------------------------ // // FUNCTION: sys_GetRegEnum( PA_PluginParameters params ) // // PURPOSE: Get a key from the registry. // // DATE: MJG 12/4/03 (3.5.6) // void sys_GetRegEnum( PA_PluginParameters params ) { LONG_PTR returnValue, regKey, retErr; char regSub[MAXBUF]; LONG_PTR regBufSize = MAX_REG_SIZE; CHAR regBuf[MAX_REG_SIZE]; FILETIME ftLastWriteTime; HKEY hRootKey; HKEY hOpenKey; DWORD dwSubKeys; DWORD dwValues; DWORD i, j; PA_Variable paReturnArray1; PA_Variable paReturnArray2; dwSubKeys = dwValues = 0; returnValue = regKey = retErr = 0; hRootKey = hOpenKey = 0; memset(regSub, 0, MAXBUF); // Get the function parameters. regKey = PA_GetLongParameter( params, 1 ); PA_GetTextParameter( params, 2, regSub ); paReturnArray1 = PA_GetVariableParameter( params, 3 ); paReturnArray2 = PA_GetVariableParameter( params, 4 ); PA_ResizeArray(&paReturnArray1, 0); PA_ResizeArray(&paReturnArray2, 0); // Convert the 4d registry constant into a Windows registry key. hRootKey = getRootKey( regKey ); // Open the registry key. retErr = RegOpenKeyEx(hRootKey, regSub, 0, KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE , &hOpenKey); if(retErr == ERROR_SUCCESS){ retErr = RegQueryInfoKey(hOpenKey, NULL, NULL, NULL, &dwSubKeys, NULL, NULL, &dwValues, NULL, NULL, NULL, NULL); if( retErr == ERROR_SUCCESS) { // Enumerate the subkey names. if (dwSubKeys) { retErr = ERROR_SUCCESS; PA_ResizeArray(&paReturnArray1, dwSubKeys); for (i=0,j=0; i<dwSubKeys; i++) { regBufSize = MAX_REG_SIZE; retErr = RegEnumKeyEx(hOpenKey, i, regBuf, ®BufSize, NULL, NULL, NULL, &ftLastWriteTime); if (retErr == ERROR_SUCCESS) { PA_SetTextInArray(paReturnArray1, ++j, regBuf, regBufSize); } } } // Enumerate the key value names. if (dwValues) { retErr = ERROR_SUCCESS; PA_ResizeArray(&paReturnArray2, dwValues); for (i=0,j=0; i<dwValues; i++) { regBufSize = MAX_REG_SIZE; regBuf[0] = '\0'; retErr = RegEnumValue(hOpenKey, i, regBuf, ®BufSize, NULL, NULL, NULL, NULL); if (retErr == ERROR_SUCCESS ) { PA_SetTextInArray(paReturnArray2, ++j, regBuf, regBufSize); } } } returnValue = 1; } } PA_SetVariableParameter( params, 3, paReturnArray1, 0 ); PA_SetVariableParameter( params, 4, paReturnArray2, 0 ); RegCloseKey( hOpenKey ); PA_ReturnLong( params, returnValue ); }