Update of /cvsroot/perl-win32-gui/Win32-GUI
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9313
Modified Files:
GUI.xs
Log Message:
Allow LoadImage() to cope with cygwin paths
Index: GUI.xs
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/GUI.xs,v
retrieving revision 1.66
retrieving revision 1.67
diff -C2 -d -r1.66 -r1.67
*** GUI.xs 16 Jul 2007 19:31:50 -0000 1.66
--- GUI.xs 31 Jan 2008 00:28:14 -0000 1.67
***************
*** 1564,1567 ****
--- 1564,1571 ----
###########################################################################
# (@)INTERNAL:LoadImage(FILENAME, [TYPE, X, Y, FLAGS])
+ # The return value is a handle to the bitmap, or 0 on failure.
+ #
+ # Directory seperators are normalised to windows seperators (C<\>).
+ # Under Cygwin, cygwin paths are converted to windows paths
HBITMAP
LoadImage(filename,iType=IMAGE_BITMAP,iX=0,iY=0,iFlags=LR_DEFAULTCOLOR)
***************
*** 1574,1577 ****
--- 1578,1584 ----
HINSTANCE moduleHandle;
HBITMAP bitmap = NULL;
+ char buffer[MAX_PATH+1];
+ char *name;
+ int i;
CODE:
/* Try to find the resource in the current EXE */
***************
*** 1610,1615 ****
/* if filename looks like a string, try it as a file name */
if((bitmap == NULL) && SvPOK(filename)) {
bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
! SvPV_nolen(filename), iType, iX, iY, iFlags|LR_LOADFROMFILE);
}
--- 1617,1648 ----
/* if filename looks like a string, try it as a file name */
if((bitmap == NULL) && SvPOK(filename)) {
+ name = SvPV_nolen(filename);
+ #ifdef __CYGWIN__
+ /* Under Cygwin, convert paths to windows
+ * paths. E.g. convert /usr/local... and /cygdrive/c/...
+ */
+ if(cygwin_conv_to_win32_path(name,buffer) != 0)
+ XSRETURN_UNDEF;
+ #else
+ /* LoadImage on Win98 (at least) doesn't like unix
+ * path seperators, so normalise to windows path seperators
+ */
+ for(i=0; *name && (i<MAX_PATH); ++name,++i) {
+ buffer[i] = (*name == '/' ? '\\' : *name);
+ }
+ if(*name) {
+ /* XXX Path too long - although this appears to be what
+ * LoadImage would return with such a path, it might be
+ * better to find a more specific error code. E.g.
+ * ENAMETOOLONG?
+ */
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ errno = ENOENT;
+ XSRETURN_UNDEF;
+ }
+ buffer[i] = 0;
+ #endif
bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
! buffer, iType, iX, iY, iFlags|LR_LOADFROMFILE);
}
|