okay, i have a c function that reads from a file and populates a data structure, at present the filename is defined during development. what i was hoping for was to use the standard load dialog that comes with win32 to load different files
the questioncan i use the c code directly or will i need to rewrite the function to talk with the HANDLE in win32
my c code
my win32 code (unnecessary code has been commented out)Code:static void readFile(char path[MAXSTR]){ FILE * log; char t; // Temporary char variable for delimiters int id, conId; // Temporary variables for the ID of an item and ID of a connection float trait[5], str; // Trait[] holds the traits/levels of the item. str contains the strength log = fopen(path, "r"); // Open the file if(log != NULL){ // Check the file is opened correctly while(!feof(log)){ // While the end of file has not been reached // Line Below: Reads in the item ID and 5 traits/levels. fscanf(log,"%d, %f, %f, %f, %f, %f", &id, &trait[0], &trait[1], &trait[2], &trait[3], &trait[4]); fscanf(log,"%c", &t); // Check if there is any connections getID(id); addNode(id, trait); // Add the item to the data structure if(t == '{'){ // There are connections to be read in while(t == '{'){ // While there are connections available fscanf(log,"%d, %f", &conId, &str ); // Read in conId and strength of connection addConnection(id, conId, str); // Add the connection to the list fscanf(log,"%c %c", &t, &t); // Check if there are more connections } } } fclose(log); // Close the file } }
the first code example reads from a file into a data structure the second reads from a file and populates an edit dialog windowCode:BOOL LoadTextFileToEdit(HWND hEdit, LPCTSTR pszFileName) { HANDLE hFile1; //file handler BOOL bSuccess = FALSE; //success flag, default set to FALSE hFile1 = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); //open file dialog if(hFile1 != INVALID_HANDLE_VALUE) //error if cant get dialog handle { DWORD dwFileSize; //Variable to store file size dwFileSize = GetFileSize(hFile1, NULL); //assign value to variable if(dwFileSize != 0xFFFFFFFF) { //readFile(pszFileName, hFile1); /* LPSTR pszFileText; //A 32-bit pointer to the contents of the edit window pszFileText = GlobalAlloc(GPTR, dwFileSize + 1);//allocate the specified bytes from the heap if(pszFileText != NULL) //no text, dont bother { DWORD dwRead; if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL)) { pszFileText[dwFileSize] = 0; // Add null terminator if(SetWindowText(hEdit, pszFileText)) bSuccess = TRUE; // It worked! } GlobalFree(pszFileText); }*/ } CloseHandle(hFile1);//close the file } return bSuccess; //return the outcome, true or false }
will this require much alterations and if so has anyone got any tips that will not require me to rewrite this or at least not much![]()
thanx in advance
korbitz



LinkBack URL
About LinkBacks
can i use the c code directly or will i need to rewrite the function to talk with the HANDLE in win32



