|
From: skooter500 on 7 May 2008 11:50 Hi, I am trying to port my program TunePal: http://www.bryanduggan.com/TunePal.html To Windows Mobile Pocket PC to run on my Palm Treo 500v smartphone. I cant get this simple file writing code to work: void testFile() { FILE * fp = NULL; fp = fopen("\\temp\\test.txt", "w"); int r = fprintf(fp, "Hello world!!\n"); fclose(fp); HANDLE file; char * msg = "Hello world!"; CreateFile(L"\\temp\\test1.txt", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, file); WriteFile(file, msg, strlen(msg), 0, 0); CloseHandle(file); exit(0); } In both cases, the files are created correctly, but there is nothing in the contents (the length of the files is 0 bytes. Also the value of r is 0 after the call to fprintf. I have tried adding fflush before closing the files and writing files to various locations (internal memory and an SD card inserted in the device) In all cases, the files are created, but there is no contents. Ive also had problems with this program: http://classic.pocketgear.com/software_detail.asp?id=26010&associateid=9 I dont know if its related, but it wont write a file copy of my sim card. Is there some strange problem writing files on this device or am I going mad! Thanks, Bryan
From: Chris Tacke, eMVP on 7 May 2008 11:57 Your use of CreateFile is wrong. It returns a handle to a file, and that handle is used for subsequent calls to ReadFile and WriteFile. You've passed it in as the "template file" which is ignored. http://msdn.microsoft.com/en-us/library/ms923949.aspx -- Chris Tacke, Embedded MVP OpenNETCF Consulting Giving back to the embedded community http://community.OpenNETCF.com "skooter500" <skooter500(a)gmail.com> wrote in message news:4ca19654-a417-4354-a982-5ddeae402743(a)27g2000hsf.googlegroups.com... > Hi, > > I am trying to port my program TunePal: > > http://www.bryanduggan.com/TunePal.html > > To Windows Mobile Pocket PC to run on my Palm Treo 500v smartphone. I > cant get this simple file writing code to work: > > void testFile() > { > FILE * fp = NULL; > > fp = fopen("\\temp\\test.txt", "w"); > int r = fprintf(fp, "Hello world!!\n"); > fclose(fp); > > > HANDLE file; > char * msg = "Hello world!"; > CreateFile(L"\\temp\\test1.txt", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, > FILE_ATTRIBUTE_NORMAL, file); > WriteFile(file, msg, strlen(msg), 0, 0); > CloseHandle(file); > exit(0); > } > > In both cases, the files are created correctly, but there is nothing > in the contents (the length of the files is 0 bytes. Also the value of > r is 0 after the call to fprintf. I have tried adding fflush before > closing the files and writing files to various locations (internal > memory and an SD card inserted in the device) In all cases, the files > are created, but there is no contents. Ive also had problems with this > program: > > http://classic.pocketgear.com/software_detail.asp?id=26010&associateid=9 > > I dont know if its related, but it wont write a file copy of my sim > card. > > Is there some strange problem writing files on this device or am I > going mad! > > Thanks, > > Bryan
From: Scott Seligman on 7 May 2008 14:55 skooter500 <skooter500(a)gmail.com> wrote: > > WriteFile(file, msg, strlen(msg), 0, 0); As Chris pointed out, you need to pass the return from CreateFile instead of the uninitialized value you pass in for the first parameter. Additionally, the fourth parameter, lpNumberOfBytesWritten, can not be NULL. -- --------- Scott Seligman <scott at <firstname> and michelle dot net> --------- Circular logic will only make you dizzy, Doctor. -- Peri in Doctor Who:"The Two Doctors"
|
Pages: 1 Prev: Application Directory Next: Need dll to convert sdf to dbf |