From: Danny B. <dan...@sc...> - 2006-08-27 17:53:34
|
Erik, You're right. My good friend, the debugger, has been of help. (But first I changed the source of your DLL so even in the fp =3D=3D 0 case I try to write, because if we have no stdin, then it would be perfectly logical to get a 0 file descriptor.) Here's what happens : 18 void doit(const TCHAR *text) 19 { 20 #if 0 21 FILE *fp =3D fopen("/My Documents/testfile2.txt", "w"); 22 =20 23 if (!fp) { (gdb) break 38 Breakpoint 2 at 0x170113c: file demodll.c, line 38. (gdb) c Continuing. warning: 00B06029:A5B5091A: open(/My Documents/testfile1.txt, 601, 3206577330) warning: 00B06289:A5B5091A: _assignfd(855b3fc6) warning: 00B064E3:A5B5091A: _assignfd returns 3 warning: 00B06741:A5B5091A: open returns 3 fd 3 cxt 0x8030014 (hnd 855b3fc6) warning: 00B069A1:A5B5091A: write(3, 5, 855b3fc6) warning: 00B06C01:A5B5091A: close(3) warning: 00B06E5D:A5B5091A: close: fd 3 type 1 flags 0 hnd 0x855b3fc6 cxt 0x0 warning: 00B070BD:A5B5091A: ch: 0x855b3fc6 1 warning: 00B07322:A5B5091A: open(/My Documents/testfile2.txt, 601, 0) warning: 00B0757E:A5B5091A: _assignfd(255b3fc6) warning: 00B077D7:A5B5091A: _assignfd returns 0 warning: 00B07A35:A5B5091A: open returns 0 fd 0 cxt 0x10 (hnd 255b3fc6) Breakpoint 2, doit (text=3D0x3007c) at demodll.c:38 38 if (write(fp, "Test\n", 5) !=3D 5) { (gdb) n warning: 00B0D48B:A5B5091A: write(0, 5, 255b3fc6) warning: 00B0D6E8:A5B5091A: write to fd =3D 0 with stdio uninitialized 41 close(fp); (gdb) c Continuing. warning: 00B154C6:A5B5091A: close(0) warning: 00B15723:A5B5091A: close: fd 0 type 1 flags 0 hnd 0x255b3fc6 cxt 0x0 I think this means that we're getting a 0 file descriptor allright, but newlib thinks this is stdin and it's not initialised so it refuses. So the next step is to check in another way whether this is true : void doit(const TCHAR *text) { int fp0 =3D open("/My Documents/testfile1.txt", O_RDONLY); int fp1 =3D open("/My Documents/testfile1.txt", O_RDONLY); int fp2 =3D open("/My Documents/testfile1.txt", O_RDONLY); int fp =3D open("/My Documents/testfile2.txt", O_CREAT | O_TRUNC | O_WRONLY); if (fp < 0) { show_errmsg_dll("open"); } else { if (write(fp, "test\n", 5) !=3D 5) { show_errmsg_dll("write"); } close(fp); } close(fp0); close(fp1); close(fp2); MessageBoxW(0, L"Message from DLL", text, 0); } And this works. So (1) you have a workaround, and (2) I have something to debug. In the process of testing this I also discovered that -mno-cegcc and --shared don't mix well. But since Pedro is saying he'll replace -mno-cegcc by something else, I won't try to debug that right now. By the way, this little exercise also showed that our gdb can step into DLLs :-) Danny On Sun, 2006-08-27 at 15:54 +0200, Erik van Pienbroek wrote: > Hi, >=20 > Now that it's possible to compile DLL's using CeGCC I'm trying to port > one of my projects to WinCE. However, I'm stumbling across a strange > problem. Every time a file read/write action needs to be performed from > inside the DLL (read, write, fread and fwrite), no data is actually > read or written. I've adjusted Danny's test code so it contains some > stdio test code. >=20 > What the attached code does is that it tries to write a file from both > the .exe file and the .dll file. The write from the .exe file succeeds, > but the write from the .dll file always causes a 0-byte file. What is > even more strange is that the open function returns file pointer 0, > which is the default file pointer for stdin (should by 3 or higher). >=20 > Any ideas? >=20 > Regards, >=20 > Erik van Pienbroek > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job ea= sier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ Cegcc-devel mailing list = Ceg...@li... https://lists.sourceforge.net/lists/listi= nfo/cegcc-devel --=20 Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info |