// ------------------------------------------------ // // 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 ); }
sword _fetchDataIntoDateArray(ORACLE_SQL_CURSOR *cursor, PA_Variable variable, unsigned int pos) { if(cursor->rowsFetched) { unsigned int itemCount = cursor->rowsFetched < cursor->itemCount ? cursor->rowsFetched : cursor->itemCount; //to clear the content of element #0, if any PA_ResizeArray(&variable, 0); PA_ResizeArray(&variable, itemCount); short d; short m; short y; for(unsigned int i = 0; i < itemCount; ++i) { PA_YieldAbsolute(); if(cursor->indicatorLists.at(pos).at(i) != -1) { OCIDateGetDate(&cursor->arrayOfDates.at(pos).at(i), &y, &m, &d); PA_SetDateInArray(variable, i + 1, d, m, y); }else{ setDateArrayValueNull(variable, i + 1); } } PA_SetPointerValue(&cursor->pointers.at(pos), variable); } return cursor->rowsFetched; }
sword _fetchDataIntoTextArray(ORACLE_SQL_CURSOR *cursor, PA_Variable variable, unsigned int pos, sessionInfo *session) { if(cursor->rowsFetched) { unsigned int itemCount = cursor->rowsFetched < cursor->itemCount ? cursor->rowsFetched : cursor->itemCount; //to clear the content of element #0, if any PA_ResizeArray(&variable, 0); PA_ResizeArray(&variable, itemCount); for(unsigned int i = 0; i < itemCount; ++i) { PA_YieldAbsolute(); if(cursor->indicatorLists.at(pos).at(i) != -1) { PA_Unistring u = PA_CreateUnistring((PA_Unichar *)OCIStringPtr(session->envhp, cursor->arrayOfTexts.at(pos).at(i))); PA_SetStringInArray(variable, i + 1, &u); }else{ setTextArrayValueNull(variable, i + 1); } //prepare buffer of next fetch memset(OCIStringPtr(session->envhp, cursor->arrayOfTexts.at(pos).at(i)), 0, BUFFER_SIZE_TEXT_ARRAY_ELEMENT); } PA_SetPointerValue(&cursor->pointers.at(pos), variable); } return cursor->rowsFetched; }
sword _fetchDataIntoLongintArray(ORACLE_SQL_CURSOR *cursor, PA_Variable variable, unsigned int pos) { if(cursor->rowsFetched) { unsigned int itemCount = cursor->rowsFetched < cursor->itemCount ? cursor->rowsFetched : cursor->itemCount; //to clear the content of element #0, if any PA_ResizeArray(&variable, 0); PA_ResizeArray(&variable, itemCount); int intValue; for(unsigned int i = 0; i < itemCount; ++i) { PA_YieldAbsolute(); if(cursor->indicatorLists.at(pos).at(i) != -1) { OCINumberToInt(cursor->errhp, &cursor->arrayOfNumbers.at(pos).at(i), sizeof(int), OCI_NUMBER_SIGNED, &intValue); PA_SetLongintInArray(variable, i + 1, intValue); }else{ setLongintArrayValueNull(variable, i + 1); } } PA_SetPointerValue(&cursor->pointers.at(pos), variable); } return cursor->rowsFetched; }
void DoubleArray::toParamAtIndex(PackagePtr pParams, uint32_t index) { if(index) { PA_Variable arr = *((PA_Variable*) pParams[index - 1]); if(arr.fType == eVK_ArrayReal) { PA_ResizeArray(&arr, this->_DoubleArray.empty() ? 0 : (this->_DoubleArray.size() - 1)); unsigned int i; for(i = 0; i < this->_DoubleArray.size(); i++) { PA_SetRealInArray(arr, i, this->_DoubleArray.at(i)); } PA_Variable *param = ((PA_Variable *)pParams[index - 1]); param->fFiller = 0; param->uValue.fArray.fCurrent = arr.uValue.fArray.fCurrent; param->uValue.fArray.fNbElements = arr.uValue.fArray.fNbElements; param->uValue.fArray.fData = arr.uValue.fArray.fData; } } }
void UStringArray::toParamAtIndex(PackagePtr pParams, uint32_t index) { if(index) { PA_Variable arr = *((PA_Variable*) pParams[index - 1]); if(arr.fType == eVK_ArrayUnicode) { PA_ResizeArray(&arr, this->_UStringArray.empty() ? 0 : (this->_UStringArray.size() - 1)); unsigned int i; for(i = 0; i < this->_UStringArray.size(); i++) { int size = this->_UStringArray.at(i).length(); int len = (size * sizeof(PA_Unichar)) + 2; std::vector<uint8_t> buf(len); PA_ConvertCharsetToCharset( (char *)this->_UStringArray.at(i).c_str(), size, eVTC_UTF_8, (char *)&buf[0], len, eVTC_UTF_16 ); PA_Unistring str = PA_CreateUnistring((PA_Unichar *)&buf[0]); PA_SetStringInArray(arr, i, &str); } PA_Variable *param = ((PA_Variable *)pParams[index - 1]); param->fFiller = 0; param->uValue.fArray.fCurrent = arr.uValue.fArray.fCurrent; param->uValue.fArray.fNbElements = arr.uValue.fArray.fNbElements; param->uValue.fArray.fData = arr.uValue.fArray.fData; } } }
void ARRAY_TEXT::toParamAtIndex(PackagePtr pParams, uint32_t index) { if(index) { PA_Variable arr = *((PA_Variable*) pParams[index - 1]); PA_Variable *param = ((PA_Variable *)pParams[index - 1]); switch (arr.fType) { case eVK_ArrayUnicode: break; case eVK_Undefined: PA_ClearVariable(&arr); arr = PA_CreateVariable(eVK_ArrayUnicode); param->fType = arr.fType; break; default: break; } if(arr.fType == eVK_ArrayUnicode) { PA_ResizeArray(&arr, this->_CUTF16StringArray->empty() ? 0 : (uint32_t)(this->_CUTF16StringArray->size() - 1)); uint32_t i; for(i = 0; i < this->_CUTF16StringArray->size(); i++) { PA_Unistring str = PA_CreateUnistring((PA_Unichar *)this->_CUTF16StringArray->at(i).c_str()); PA_SetStringInArray(arr, i, &str); } param->fFiller = 0; param->uValue.fArray.fCurrent = arr.uValue.fArray.fCurrent; param->uValue.fArray.fNbElements = arr.uValue.fArray.fNbElements; param->uValue.fArray.fData = arr.uValue.fArray.fData; } } }
void ARRAY_LONGINT::toParamAtIndex(PackagePtr pParams, uint32_t index) { if(index) { PA_Variable arr = *((PA_Variable*) pParams[index - 1]); PA_Variable *param = ((PA_Variable *)pParams[index - 1]); switch (arr.fType) { case eVK_ArrayLongint: break; case eVK_Undefined: PA_ClearVariable(&arr); arr = PA_CreateVariable(eVK_ArrayLongint); param->fType = arr.fType; break; default: break; } if(arr.fType == eVK_ArrayLongint) { PA_ResizeArray(&arr, this->_CIntArray->empty() ? 0 : (uint32_t)(this->_CIntArray->size() - 1)); uint32_t i; for(i = 0; i < this->_CIntArray->size(); i++) { PA_SetLongintInArray(arr, i, this->_CIntArray->at(i)); } param->fFiller = 0; param->uValue.fArray.fCurrent = arr.uValue.fArray.fCurrent; param->uValue.fArray.fNbElements = arr.uValue.fArray.fNbElements; param->uValue.fArray.fData = arr.uValue.fArray.fData; } } }
// ------------------------------------------------ // // FUNCTION: sys_GetCommandLine( PA_PluginParameters params) // // PURPOSE: Gets command line used to start 4D // // COMMENTS: Parse command line. Ends at a negative character value. // Returns an array of parameters. // Params should be passed unquoted. There can be a space or NULL // between parameters. 1st param is delimited by space. Rest are NULL. // // DATE: dcc 04/03/02 dcc // // MODIFICATIONS: Rewritten 06/20/02 to make more concise, less convoluted, etc. // Modified 7/29/03 void sys_GetCommandLine(PA_PluginParameters params) { char commandLineStr[MAXBUF]; char paramElement[MAXBUF]; char executableString[MAXBUF]; char *pMarker; LONG returnValue = 0, commandLine_len = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG_PTR charsToCopy; LPTSTR pCommandLineStr, pTemp; PA_Variable parameters; BOOL bInQuotes = FALSE, bDone = FALSE; LONG paramCount = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG action = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG memset(commandLineStr, 0, MAXBUF); memset(paramElement, 0, MAXBUF); memset(executableString, 0, MAXBUF); parameters = PA_GetVariableParameter(params, 1); action = PA_GetLongParameter(params, 2); pCommandLineStr = GetCommandLine(); if (pCommandLineStr == NULL) { returnValue = 0; } else { pMarker = pTemp = pCommandLineStr; //if first char a doublequote, skip it if (*pMarker == '"') { pMarker++; bInQuotes = TRUE; } // Find the executable name. while (!((*(++pTemp) == ' ' && !bInQuotes) || (*pTemp == '"' && bInQuotes) || *pTemp == '\0')); charsToCopy = (pTemp - pMarker); strncpy(executableString, pMarker, charsToCopy); commandLine_len = (LONG)charsToCopy; // WJF 6/30/16 Win-21 Cast to LONG executableString[charsToCopy] = '\0'; //skip next quotes and spaces if they are there while ((*pTemp == '"') || (*pTemp == ' ')) { if ((*pTemp == '"') && (action == CL_DRAGDROP)) { bInQuotes = !bInQuotes; // toggle flag } commandLine_len += 1; pTemp++; } pMarker = pTemp; if (action == CL_DRAGDROP) { if (bInQuotes) { while ((*pTemp != '"') || ((*pTemp != '\0') && (*(pTemp + 1) != '\0'))) { pTemp++; } } else { while (*pTemp != '\0') { pTemp++; } } strncpy(paramElement, pMarker, pTemp - pMarker); paramElement[pTemp - pMarker] = '\0'; if (strlen(paramElement) == 0) { PA_ResizeArray(¶meters, 1); strcpy(commandLineStr, executableString); returnValue = 1; } else { PA_ResizeArray(¶meters, 2); PA_SetTextInArray(parameters, 2, paramElement, strlen(paramElement)); strcpy(commandLineStr, executableString); strcat(commandLineStr, " "); strcat(commandLineStr, paramElement); returnValue = 2; } } else { paramCount = 1; strcpy(commandLineStr, executableString); PA_ResizeArray(¶meters, paramCount); while (!bDone) { strcpy(paramElement, ""); while (*pTemp >= 0) { pTemp++; //two nulls in a row also end //replace nulls with spaces if ((*(pTemp) == '\0') || (*(pTemp) == ' ')) { if ((*(pTemp + 1) == '\0') || (*(pTemp + 1) == ' ')){ bDone = TRUE; paramCount++; break; } else { paramCount++; break; } } } // end while strncpy(paramElement, pMarker, pTemp - pMarker); paramElement[pTemp - pMarker] = '\0'; if (strlen(paramElement) > 0) { PA_ResizeArray(¶meters, paramCount); PA_SetTextInArray(parameters, paramCount, paramElement, strlen(paramElement)); pMarker = pTemp + 1; strcat(commandLineStr, " "); strcat(commandLineStr, paramElement); } else { bDone = TRUE; } } // end while !done returnValue = PA_GetArrayNbElements(parameters); } PA_SetTextInArray(parameters, 1, executableString, strlen(executableString)); PA_SetTextInArray(parameters, 0, commandLineStr, strlen(commandLineStr)); PA_SetVariableParameter(params, 1, parameters, 0); } // (pCommandLineStr == NULL) PA_ReturnLong(params, returnValue); }
// ------------------------------------------------ // // FUNCTION: gui_GetWindowStyle( PA_PluginParameters params) // // PURPOSE: Get window styles // // COMMENTS: outputs in array the applicable styles for the window // Returns via return code the LONG_PTR representing the value // // DATE: dcc 07/18/02 dcc // // MODIFICATIONS: // void gui_GetWindowStyle(PA_PluginParameters params, BOOL isEx) { PA_Variable styles; LONG returnValue = 0, testValue = 0, i; // WJF 6/30/16 Win-21 LONG_PTR -> LONG HWND hWnd; char styleText[40]; BOOL bFoundOne; LONG hWndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG hWndIndex = PA_GetLongParameter(params, 1); // WJF 9/1/15 #43731 We are now getting an index to an internal array if (isEx){ // WJF 9/16/15 #43731 hWnd = handleArray_retrieve((DWORD)hWndIndex); } else { hWnd = (HWND)hWndIndex; } if (IsWindow(hWnd)) { styles = PA_GetVariableParameter(params, 2); returnValue = GetWindowLong(hWnd, GWL_STYLE); testValue = returnValue; //and all styles to see what the window uses i = 1; while ((testValue != 0) && (i <= NUMBER_STYLES)) { bFoundOne = FALSE; if ((testValue & WS_THICKFRAME) == WS_THICKFRAME) { strcpy(styleText, "WS_THICKFRAME"); bFoundOne = TRUE; testValue = testValue ^ WS_THICKFRAME; } else if ((testValue & WS_POPUP) == WS_POPUP) { strcpy(styleText, "WS_POPUP"); bFoundOne = TRUE; testValue = testValue ^ WS_POPUP; } else if ((testValue & WS_CHILD) == WS_CHILD) { strcpy(styleText, "WS_CHILD"); bFoundOne = TRUE; testValue = testValue ^ WS_CHILD; } else if ((testValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) { strcpy(styleText, "WS_MINIMIZEBOX"); bFoundOne = TRUE; testValue = testValue ^ WS_MINIMIZEBOX; } else if ((testValue & WS_VISIBLE) == WS_VISIBLE) { strcpy(styleText, "WS_VISIBLE"); bFoundOne = TRUE; testValue = testValue ^ WS_VISIBLE; } else if ((testValue & WS_DISABLED) == WS_DISABLED) { strcpy(styleText, "WS_DISABLED"); bFoundOne = TRUE; testValue = testValue ^ WS_DISABLED; } else if ((testValue & WS_CLIPSIBLINGS) == WS_CLIPSIBLINGS) { strcpy(styleText, "WS_CLIPSIBLINGS"); bFoundOne = TRUE; testValue = testValue ^ WS_CLIPSIBLINGS; } else if ((testValue & WS_CLIPCHILDREN) == WS_CLIPCHILDREN) { strcpy(styleText, "WS_CLIPCHILDREN"); bFoundOne = TRUE; testValue = testValue ^ WS_CLIPCHILDREN; } else if ((testValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) { strcpy(styleText, "WS_MAXIMIZEBOX"); bFoundOne = TRUE; testValue = testValue ^ WS_MAXIMIZEBOX; } else if ((testValue & WS_CAPTION) == WS_CAPTION) { strcpy(styleText, "WS_CAPTION"); bFoundOne = TRUE; testValue = testValue ^ WS_CAPTION; } else if ((testValue & WS_BORDER) == WS_BORDER) { strcpy(styleText, "WS_BORDER"); bFoundOne = TRUE; testValue = testValue ^ WS_BORDER; } else if ((testValue & WS_DLGFRAME) == WS_DLGFRAME) { strcpy(styleText, "WS_DLGFRAME"); bFoundOne = TRUE; testValue = testValue ^ WS_DLGFRAME; } else if ((testValue & WS_VSCROLL) == WS_VSCROLL) { strcpy(styleText, "WS_VSCROLL"); bFoundOne = TRUE; testValue = testValue ^ WS_VSCROLL; } else if ((testValue & WS_HSCROLL) == WS_HSCROLL) { strcpy(styleText, "WS_HSCROLL"); bFoundOne = TRUE; testValue = testValue ^ WS_HSCROLL; } else if ((testValue & WS_SYSMENU) == WS_SYSMENU) { strcpy(styleText, "WS_SYSMENU"); bFoundOne = TRUE; testValue = testValue ^ WS_SYSMENU; } if (bFoundOne) { PA_ResizeArray(&styles, i); PA_SetTextInArray(styles, i, styleText, strlen(styleText)); } i++; } // end while if (testValue == 0) { strcpy(styleText, "WS_OVERLAPPED"); PA_ResizeArray(&styles, i); PA_SetTextInArray(styles, i, styleText, strlen(styleText)); } PA_SetVariableParameter(params, 2, styles, 0); } PA_ReturnLong(params, returnValue); }
// ------------------------------------------------ // // FUNCTION: sys_GetDocumentList( PA_PluginParameters params ) // // PURPOSE: Return a list of files in a directory. // // DATE: MJG 6/4/04 (3.6) // // UPDATES: MJG 7/5/05 (3.6.2) Updated to set the 4D variable, Error, // when an error occurs. // // AMS 9/16/14 #40405 (6.4) Updated to return the oldest entries first // and take in a starting index for specifying // where the list of returned files begins. // // // ------------------------------------------------ void sys_GetDocumentList(PA_PluginParameters params) { LONG lReturnValue = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG lFileCount = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG lArraySize = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG lEndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG lCount = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG const LONG lFileLimit = 1000; char fullPath[MAXBUF]; WIN32_FIND_DATA fFindData; DWORD ret = 0; DWORD lastError = 0; HANDLE NextFind = 0; BOOL bGetAllFiles = FALSE; WIN32_FIND_DATA fileList[1000]; // parameter variables char *patPathName = NULL; char *patFilePattern = NULL; LONG palMaxFilesToReturn = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG palFileSort = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG palStartIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG PA_Variable paReturnFileList; // Get the function parameters. patPathName = getTextParameter(params, 1); patFilePattern = getTextParameter(params, 2); paReturnFileList = PA_GetVariableParameter(params, 3); palMaxFilesToReturn = PA_GetLongParameter(params, 4); palFileSort = PA_GetLongParameter(params, 5); // AMS2 9/30/14 #40405 Moved the sort parameter to be before start index palStartIndex = PA_GetLongParameter(params, 6); // AMS2 9/16/14 #40405 // Clear out the return array. PA_ResizeArray(&paReturnFileList, 0); // AMS2 9/19/14 #40405 Passing in the start index is optional, if a value is passed in then it is assumed that the user put in a number relative to a starting index of 1 instead of 0 for c/c++ arrays if ((palStartIndex != 0) || (palStartIndex > 0)) // WJF 6/24/16 Win-21 NULL -> 0 { palStartIndex--; } else{ palStartIndex = 0; } // WJF 4/7/15 #41624 If they haven't chosen a valid sort option, set to default if ((palFileSort != 1) && (palFileSort != 2)) { palFileSort = 0; } if (patPathName != NULL && patFilePattern != NULL) { // Check if the path is valid. ret = GetFileAttributes(patPathName); if ((ret & FILE_ATTRIBUTE_DIRECTORY) != 0 && ret != INVALID_DIRECTORY) { // Build the full path name. if (patFilePattern[0] == '\0') { snprintf(fullPath, MAXBUF, "%s%s*.*", patPathName, patPathName[strlen(patPathName) - 1] == PATHCHAR ? "" : PATHSTR); } else { snprintf(fullPath, MAXBUF, "%s%s%s", patPathName, patPathName[strlen(patPathName) - 1] == PATHCHAR ? "" : PATHSTR, patFilePattern); } // Get the first file. NextFind = FindFirstFile(fullPath, &fFindData); if (NextFind != INVALID_HANDLE_VALUE) { // AMS2 9/18/14 #40405 Loop through the files in the directory and build a list to sort. Currently the max files that can be stored from a directory is 1000. lastError = ERROR_NO_MORE_FILES; bGetAllFiles = (palMaxFilesToReturn <= 0); while ((NextFind != INVALID_HANDLE_VALUE) && (lFileCount < lFileLimit)) { if ((fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { // AMS2 9/19/14 #40405 When a file match is found, insert it into the file list array. fileList[lFileCount] = fFindData; lFileCount++; // Count the number of files that match the pattern. } if (!FindNextFile(NextFind, &fFindData)) { lastError = GetLastError(); break; } } // end while // AMS2 9/18/14 #40405 Sort the array using compareFileTimeCreation which takes in two win32 find data variables and compares their creation dates. if (palFileSort == 1) { qsort(fileList, lFileCount, sizeof(WIN32_FIND_DATA), (int(*)(const void*, const void*))compareFileTimeCreation); } else if (palFileSort == 2) // WJF 4/7/15 #41624 Sorty by alphabetical order { qsort(fileList, lFileCount, sizeof(WIN32_FIND_DATA), (int(*)(const void*, const void*))compareAlphabetical); } // AMS2 9/18/14 #40405 Get all of the files if 0 is passed for the max files parameter. if (palMaxFilesToReturn == 0) { palMaxFilesToReturn = lFileCount; } // AMS2 9/18/14 #40405 If the start index or end index is out of range, then set them to the file count. if (palStartIndex > lFileCount) { palStartIndex = lFileCount; } lEndIndex = palMaxFilesToReturn + palStartIndex; if (lEndIndex > lFileCount) { lEndIndex = lFileCount; } // AMS2 9/22/14 #40405 As long as the end index is within the file limit, insert the requested file names into the return array // starting at the specified start index and end at the start index + the max number of files to return. if (lEndIndex <= lFileLimit) { for (int i = palStartIndex; i < lEndIndex; i++) { lCount++; if (lCount > lArraySize) { // Increase the size of the array. lArraySize = lCount + ARRAY_LOAD_VALUE; PA_ResizeArray(&paReturnFileList, lArraySize); } PA_SetTextInArray(paReturnFileList, lCount, fileList[i].cFileName, strlen(fileList[i].cFileName)); } } } else { lastError = GetLastError(); } FindClose(NextFind); } else { lastError = GetLastError(); } } if (lastError == ERROR_NO_MORE_FILES || lastError == ERROR_FILE_NOT_FOUND) { setError(0); PA_ResizeArray(&paReturnFileList, lCount); // AMS2 9/22/14 #40405 When the file selection has finished with no more files in the dir or a file has not been found, resize the return array to the number of files inserted into the array. lReturnValue = 1; } else { setError(lastError); PA_ResizeArray(&paReturnFileList, 0); } PA_SetVariableParameter(params, 3, paReturnFileList, 0); freeTextParameter(patPathName); freeTextParameter(patFilePattern); PA_ReturnLong(params, lReturnValue); }
// ------------------------------------------------ // // 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 ); }
// ------------------------------------------------ // // FUNCTION: gui_SelectColor( PA_PluginParameters params) // // PURPOSE: Displays the color common dialog // // COMMENTS: // // // DATE: dcc 11/25/02 (3.5.3) // // MODIFICATIONS: // void gui_SelectColor( PA_PluginParameters params) { CHOOSECOLOR cColor; static COLORREF acrCustColor[16]; static DWORD rgbCurrent; LONG_PTR rParam, gParam, bParam, returnValue = 0, i, hasCustom; PA_Variable custColorArray; rParam = PA_GetLongParameter( params, 1); gParam = PA_GetLongParameter( params, 2); bParam = PA_GetLongParameter( params, 3); hasCustom = PA_GetLongParameter( params, 4); if (rParam > 255) rParam = 0; if (gParam > 255) gParam = 0; if (bParam > 255) bParam = 0; if (hasCustom == 1) { custColorArray = PA_GetVariableParameter( params, 5 ); if(PA_GetVariableKind(custColorArray) == eVK_ArrayLongint) { for (i = 0; i < PA_GetArrayNbElements(custColorArray); i++) { acrCustColor[i] = PA_GetLongintInArray(custColorArray, i + 1); } } } ZeroMemory(&cColor, sizeof(CHOOSECOLOR)); cColor.lStructSize = sizeof(CHOOSECOLOR); cColor.hwndOwner = windowHandles.fourDhWnd; cColor.lpCustColors = (LPDWORD) acrCustColor; cColor.rgbResult = rgbCurrent; if ((rParam > 0) || (gParam > 0) || (bParam > 0)) { cColor.rgbResult = RGB(rParam, gParam, bParam); cColor.Flags = CC_FULLOPEN | CC_RGBINIT; } else { cColor.Flags = CC_FULLOPEN; } if (ChooseColor(&cColor)== TRUE) { rgbCurrent = cColor.rgbResult; rParam = GetRValue(rgbCurrent); gParam = GetGValue(rgbCurrent); bParam = GetBValue(rgbCurrent); PA_SetLongParameter( params, 1, rParam ); PA_SetLongParameter( params, 2, gParam ); PA_SetLongParameter( params, 3, bParam ); if (hasCustom == 1) { PA_ResizeArray(&custColorArray, 16); for (i = 0; i < 16; i++) { PA_SetLongintInArray(custColorArray, i + 1, acrCustColor[i]); } PA_SetVariableParameter( params, 5, custColorArray, 0); } returnValue = 1; } PA_ReturnLong( params, returnValue); }
void sys_EnumProcesses( PA_PluginParameters params ) { HANDLE hProcessSnap; // Handle to the process snapshot PROCESSENTRY32 pe32; // ProcessEntry to get info about processes PA_Variable paNameArray; // Array to store process names ($1) PA_Variable paIDArray; // Array to store process IDs ($2) INT_PTR iSize = 0; // Int to control size of array // Get variables representing passed in arrays paNameArray = PA_GetVariableParameter(params, 1); paIDArray = PA_GetVariableParameter(params, 2); // Resize arrays to 0 PA_ResizeArray(&paNameArray, iSize); PA_ResizeArray(&paIDArray, iSize); // Take a snapshot of all processes in the system. // If we fail, return the error code hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(hProcessSnap == INVALID_HANDLE_VALUE) { PA_ReturnLong(params, (LONG_PTR)GetLastError()); return; } // Set the size of the structure before using it. pe32.dwSize = sizeof( PROCESSENTRY32 ); // Retrieve information about the first process, // If we can't do it, then return the error code if(!Process32First( hProcessSnap, &pe32)) { CloseHandle( hProcessSnap ); // Must clean up the snapshot object! PA_ReturnLong(params, (LONG_PTR)GetLastError()); return; } // Now walk the snapshot of processes, and // Insert an array element in each array, one for name and one for ID. do { iSize++; PA_ResizeArray(&paNameArray, iSize); PA_ResizeArray(&paIDArray, iSize); PA_SetTextInArray(paNameArray, iSize, pe32.szExeFile, strlen(pe32.szExeFile)); PA_SetLongintInArray(paIDArray, iSize, pe32.th32ProcessID); } while(Process32Next(hProcessSnap, &pe32)); // Close the handle and return success CloseHandle(hProcessSnap); // Set return arrays PA_SetVariableParameter(params, 1, paNameArray, 0); PA_SetVariableParameter(params, 2, paIDArray, 0); // Return error code. PA_ReturnLong(params, 0); }
// ------------------------------------------------ // // FUNCTION: gui_GetWindowStyle( PA_PluginParameters params) // // PURPOSE: Get window styles // // COMMENTS: outputs in array the applicable styles for the window // Returns via return code the LONG_PTR representing the value // // DATE: dcc 07/18/02 dcc // // MODIFICATIONS: // void gui_GetWindowStyle ( PA_PluginParameters params ) { PA_Variable styles; LONG_PTR returnValue = 0, testValue = 0, i; HWND hWnd; char styleText[40]; BOOL bFoundOne; hWnd = (HWND) PA_GetLongParameter( params, 1); if (IsWindow(hWnd)) { styles = PA_GetVariableParameter( params, 2 ); returnValue = GetWindowLong(hWnd, GWL_STYLE); testValue = returnValue; //and all styles to see what the window uses i = 1; while ((testValue != 0) && (i <= NUMBER_STYLES)) { bFoundOne = FALSE; if ((testValue & WS_THICKFRAME) == WS_THICKFRAME) { strcpy(styleText, "WS_THICKFRAME"); bFoundOne = TRUE; testValue = testValue ^ WS_THICKFRAME; } else if ((testValue & WS_POPUP) == WS_POPUP) { strcpy(styleText, "WS_POPUP"); bFoundOne = TRUE; testValue = testValue ^ WS_POPUP; } else if ((testValue & WS_CHILD) == WS_CHILD) { strcpy(styleText, "WS_CHILD"); bFoundOne = TRUE; testValue = testValue ^ WS_CHILD; } else if ((testValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) { strcpy(styleText, "WS_MINIMIZEBOX"); bFoundOne = TRUE; testValue = testValue ^ WS_MINIMIZEBOX; } else if ((testValue & WS_VISIBLE) == WS_VISIBLE) { strcpy(styleText, "WS_VISIBLE"); bFoundOne = TRUE; testValue = testValue ^ WS_VISIBLE; } else if ((testValue & WS_DISABLED) == WS_DISABLED) { strcpy(styleText, "WS_DISABLED"); bFoundOne = TRUE; testValue = testValue ^ WS_DISABLED; } else if ((testValue & WS_CLIPSIBLINGS) == WS_CLIPSIBLINGS) { strcpy(styleText, "WS_CLIPSIBLINGS"); bFoundOne = TRUE; testValue = testValue ^ WS_CLIPSIBLINGS; } else if ((testValue & WS_CLIPCHILDREN) == WS_CLIPCHILDREN) { strcpy(styleText, "WS_CLIPCHILDREN"); bFoundOne = TRUE; testValue = testValue ^ WS_CLIPCHILDREN; } else if ((testValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) { strcpy(styleText, "WS_MAXIMIZEBOX"); bFoundOne = TRUE; testValue = testValue ^ WS_MAXIMIZEBOX; } else if ((testValue & WS_CAPTION) == WS_CAPTION) { strcpy(styleText, "WS_CAPTION"); bFoundOne = TRUE; testValue = testValue ^ WS_CAPTION; } else if ((testValue & WS_BORDER) == WS_BORDER) { strcpy(styleText, "WS_BORDER"); bFoundOne = TRUE; testValue = testValue ^ WS_BORDER; } else if ((testValue & WS_DLGFRAME) == WS_DLGFRAME) { strcpy(styleText, "WS_DLGFRAME"); bFoundOne = TRUE; testValue = testValue ^ WS_DLGFRAME; } else if ((testValue & WS_VSCROLL) == WS_VSCROLL) { strcpy(styleText, "WS_VSCROLL"); bFoundOne = TRUE; testValue = testValue ^ WS_VSCROLL; } else if ((testValue & WS_HSCROLL) == WS_HSCROLL) { strcpy(styleText, "WS_HSCROLL"); bFoundOne = TRUE; testValue = testValue ^ WS_HSCROLL; } else if ((testValue & WS_SYSMENU) == WS_SYSMENU) { strcpy(styleText, "WS_SYSMENU"); bFoundOne = TRUE; testValue = testValue ^ WS_SYSMENU; } if (bFoundOne) { PA_ResizeArray (&styles, i); PA_SetTextInArray (styles, i, styleText, strlen(styleText)); } i++; } // end while if (testValue == 0) { strcpy(styleText, "WS_OVERLAPPED"); PA_ResizeArray (&styles, i); PA_SetTextInArray (styles, i, styleText, strlen(styleText)); } PA_SetVariableParameter( params, 2, styles, 0 ); } PA_ReturnLong( params, returnValue ); }