4 * Copyright 1998 Andrew Taylor
5 * Copyright 1998 Ove Kåven
6 * Copyright 2000,2002 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * + correct handling of global/local IOProcs (and temporary IOProcs)
25 * + mode of mmio objects is not used (read vs write vs readwrite)
27 * + 32 A <=> W message mapping
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(mmio
);
49 static WINE_MMIO
*MMIOList
;
52 static HANDLE
create_file_OF( LPCSTR path
, INT mode
)
54 DWORD access
, sharing
, creation
;
55 char full_path
[MAX_PATH
];
59 creation
= CREATE_ALWAYS
;
60 access
= GENERIC_READ
| GENERIC_WRITE
;
64 creation
= OPEN_EXISTING
;
67 case OF_READ
: access
= GENERIC_READ
; break;
68 case OF_WRITE
: access
= GENERIC_WRITE
; break;
69 case OF_READWRITE
: access
= GENERIC_READ
| GENERIC_WRITE
; break;
70 default: access
= 0; break;
76 case OF_SHARE_EXCLUSIVE
: sharing
= 0; break;
77 case OF_SHARE_DENY_WRITE
: sharing
= FILE_SHARE_READ
; break;
78 case OF_SHARE_DENY_READ
: sharing
= FILE_SHARE_WRITE
; break;
79 case OF_SHARE_DENY_NONE
:
81 default: sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
; break;
85 return CreateFileA( path
, access
, sharing
, NULL
, creation
, FILE_ATTRIBUTE_NORMAL
, 0 );
87 if (!SearchPathA( NULL
, path
, NULL
, MAX_PATH
, full_path
, NULL
))
88 return INVALID_HANDLE_VALUE
;
89 return CreateFileA( full_path
, access
, sharing
, NULL
, creation
, FILE_ATTRIBUTE_NORMAL
, 0 );
92 /**************************************************************************
93 * mmioDosIOProc [internal]
95 static LRESULT CALLBACK
mmioDosIOProc(LPMMIOINFO lpmmioinfo
, UINT uMessage
,
96 LPARAM lParam1
, LPARAM lParam2
)
98 LRESULT ret
= MMSYSERR_NOERROR
;
100 TRACE("(%p, %X, 0x%Ix, 0x%Ix);\n", lpmmioinfo
, uMessage
, lParam1
, lParam2
);
106 * lParam1 = szFileName parameter from mmioOpen
108 * Returns: zero on success, error code on error
109 * NOTE: lDiskOffset automatically set to zero
111 LPCSTR szFileName
= (LPCSTR
)lParam1
;
113 if (lpmmioinfo
->dwFlags
& MMIO_GETTEMP
) {
114 FIXME("MMIO_GETTEMP not implemented\n");
115 return MMIOERR_CANNOTOPEN
;
118 /* if filename NULL, assume open file handle in adwInfo[0] */
122 file
= create_file_OF( szFileName
, lpmmioinfo
->dwFlags
);
123 if (file
!= INVALID_HANDLE_VALUE
)
124 lpmmioinfo
->adwInfo
[0] = HandleToLong(file
);
126 lpmmioinfo
->adwInfo
[0] = HFILE_ERROR
;
128 if (lpmmioinfo
->adwInfo
[0] == HFILE_ERROR
)
129 ret
= MMIOERR_FILENOTFOUND
;
135 * lParam1 = wFlags parameter from mmioClose
137 * Returns: zero on success, error code on error
139 if (!(lParam1
& MMIO_FHOPEN
))
140 _lclose((HFILE
)lpmmioinfo
->adwInfo
[0]);
145 * lParam1 = huge pointer to read buffer
146 * lParam2 = number of bytes to read
147 * Returns: number of bytes read, 0 for EOF, -1 for error (error code
150 ret
= _lread((HFILE
)lpmmioinfo
->adwInfo
[0], (HPSTR
)lParam1
, (LONG
)lParam2
);
152 lpmmioinfo
->lDiskOffset
+= ret
;
157 case MMIOM_WRITEFLUSH
:
158 /* no internal buffering, so WRITEFLUSH handled same as WRITE */
161 * lParam1 = huge pointer to write buffer
162 * lParam2 = number of bytes to write
163 * Returns: number of bytes written, -1 for error (error code in
166 ret
= _hwrite((HFILE
)lpmmioinfo
->adwInfo
[0], (HPSTR
)lParam1
, (LONG
)lParam2
);
168 lpmmioinfo
->lDiskOffset
+= ret
;
173 * lParam1 = new position
174 * lParam2 = from whence to seek (SEEK_SET, SEEK_CUR, SEEK_END)
175 * Returns: new file position, -1 on error
177 if (lParam2
== SEEK_END
)
178 ret
= _llseek((HFILE
)lpmmioinfo
->adwInfo
[0], -(LONG
)lParam1
, (LONG
)lParam2
);
180 ret
= _llseek((HFILE
)lpmmioinfo
->adwInfo
[0], (LONG
)lParam1
, (LONG
)lParam2
);
182 lpmmioinfo
->lDiskOffset
= ret
;
189 * Returns: zero on success, non-zero on failure
191 if (!MoveFileA((const char*)lParam1
, (const char*)lParam2
))
192 ret
= MMIOERR_FILENOTFOUND
;
196 FIXME("unexpected message %u\n", uMessage
);
203 /**************************************************************************
204 * mmioMemIOProc [internal]
206 static LRESULT CALLBACK
mmioMemIOProc(LPMMIOINFO lpmmioinfo
, UINT uMessage
,
207 LPARAM lParam1
, LPARAM lParam2
)
209 TRACE("(%p,0x%04x,0x%08Ix,0x%08Ix)\n", lpmmioinfo
, uMessage
, lParam1
, lParam2
);
215 * lParam1 = filename (must be NULL)
217 * Returns: zero on success, error code on error
218 * NOTE: lDiskOffset automatically set to zero
220 /* FIXME: io proc shouldn't change it */
221 if (!(lpmmioinfo
->dwFlags
& MMIO_CREATE
))
222 lpmmioinfo
->pchEndRead
= lpmmioinfo
->pchEndWrite
;
223 lpmmioinfo
->adwInfo
[0] = HFILE_ERROR
;
228 * lParam1 = wFlags parameter from mmioClose
230 * Returns: zero on success, error code on error
236 * lParam1 = huge pointer to read buffer
237 * lParam2 = number of bytes to read
238 * Returns: number of bytes read, 0 for EOF, -1 for error (error code
240 * NOTE: lDiskOffset should be updated
242 FIXME("MMIOM_READ on memory files should not occur, buffer may be lost!\n");
246 case MMIOM_WRITEFLUSH
:
247 /* no internal buffering, so WRITEFLUSH handled same as WRITE */
250 * lParam1 = huge pointer to write buffer
251 * lParam2 = number of bytes to write
252 * Returns: number of bytes written, -1 for error (error code in
254 * NOTE: lDiskOffset should be updated
256 FIXME("MMIOM_WRITE on memory files should not occur, buffer may be lost!\n");
261 * lParam1 = new position
262 * lParam2 = from whence to seek (SEEK_SET, SEEK_CUR, SEEK_END)
263 * Returns: new file position, -1 on error
264 * NOTE: lDiskOffset should be updated
266 FIXME("MMIOM_SEEK on memory files should not occur, buffer may be lost!\n");
270 FIXME("unexpected message %u\n", uMessage
);
275 /* This array will be the entire list for most apps
276 * Note that temporary ioProcs will be stored with a 0 fourCC code
279 static struct IOProcList defaultProcs
[] = {
280 {&defaultProcs
[1], FOURCC_DOS
, (LPMMIOPROC
)mmioDosIOProc
, FALSE
, 0},
281 {NULL
, FOURCC_MEM
, (LPMMIOPROC
)mmioMemIOProc
, FALSE
, 0},
284 static struct IOProcList
* pIOProcListAnchor
= &defaultProcs
[0];
286 /****************************************************************
287 * MMIO_FindProcNode [INTERNAL]
289 * Finds the ProcList node associated with a given FOURCC code.
291 static struct IOProcList
* MMIO_FindProcNode(FOURCC fccIOProc
)
293 struct IOProcList
* pListNode
;
295 for (pListNode
= pIOProcListAnchor
; pListNode
; pListNode
= pListNode
->pNext
) {
296 if (pListNode
->fourCC
== fccIOProc
) {
303 /****************************************************************
304 * MMIO_InstallIOProc [INTERNAL]
306 static LPMMIOPROC
MMIO_InstallIOProc(FOURCC fccIOProc
, LPMMIOPROC pIOProc
,
307 DWORD dwFlags
, BOOL is_unicode
)
309 LPMMIOPROC lpProc
= NULL
;
310 struct IOProcList
* pListNode
;
311 struct IOProcList
** ppListNode
;
313 TRACE("(%08lx, %p, %08lX, %s)\n", fccIOProc
, pIOProc
, dwFlags
, is_unicode
? "unicode" : "ansi");
315 if (dwFlags
& MMIO_GLOBALPROC
)
316 FIXME("Global procedures not implemented\n");
318 /* just handle the known procedures for now */
319 switch (dwFlags
& (MMIO_INSTALLPROC
|MMIO_REMOVEPROC
|MMIO_FINDPROC
)) {
320 case MMIO_INSTALLPROC
:
321 /* Create new entry for the IOProc list */
322 pListNode
= HeapAlloc(GetProcessHeap(), 0, sizeof(*pListNode
));
324 /* Fill in this node */
325 pListNode
->fourCC
= fccIOProc
;
326 pListNode
->pIOProc
= pIOProc
;
327 pListNode
->is_unicode
= is_unicode
;
328 pListNode
->count
= 0;
330 /* Stick it on the end of the list */
331 pListNode
->pNext
= pIOProcListAnchor
;
332 pIOProcListAnchor
= pListNode
;
334 /* Return this IOProc - that's how the caller knows we succeeded */
339 case MMIO_REMOVEPROC
:
341 * Search for the node that we're trying to remove
342 * We search for a matching fourCC code if it's non null, or the proc
344 * note that this method won't find the first item on the list, but
345 * since the first two items on this list are ones we won't
346 * let the user delete anyway, that's okay
348 ppListNode
= &pIOProcListAnchor
;
349 while ((*ppListNode
) &&
351 (*ppListNode
)->fourCC
!= fccIOProc
:
352 (*ppListNode
)->pIOProc
!= pIOProc
))
353 ppListNode
= &((*ppListNode
)->pNext
);
355 if (*ppListNode
) { /* found it */
356 /* FIXME: what should be done if an open mmio object uses this proc ?
357 * shall we return an error, nuke the mmio object ?
359 if ((*ppListNode
)->count
) {
360 ERR("Cannot remove a mmIOProc while in use\n");
363 /* remove it, but only if it isn't builtin */
364 if ((*ppListNode
) >= defaultProcs
&&
365 (*ppListNode
) < defaultProcs
+ ARRAY_SIZE(defaultProcs
)) {
366 WARN("Tried to remove built-in mmio proc. Skipping\n");
369 struct IOProcList
* ptmpNode
= *ppListNode
;
370 lpProc
= (*ppListNode
)->pIOProc
;
371 *ppListNode
= (*ppListNode
)->pNext
;
372 HeapFree(GetProcessHeap(), 0, ptmpNode
);
378 if ((pListNode
= MMIO_FindProcNode(fccIOProc
))) {
379 lpProc
= pListNode
->pIOProc
;
387 /****************************************************************
388 * send_message [INTERNAL]
390 static LRESULT
send_message(struct IOProcList
* ioProc
, LPMMIOINFO mmioinfo
,
391 DWORD wMsg
, LPARAM lParam1
,
392 LPARAM lParam2
, BOOL is_unicode
)
394 LRESULT result
= MMSYSERR_ERROR
;
395 LPARAM lp1
= lParam1
, lp2
= lParam2
;
398 ERR("ioProc NULL\n");
399 return MMSYSERR_INVALPARAM
;
402 if (ioProc
->is_unicode
!= is_unicode
) {
403 /* map (lParam1, lParam2) into (lp1, lp2) 32 A<=>W */
404 FIXME("NIY 32 A<=>W mapping\n");
406 result
= (ioProc
->pIOProc
)((LPSTR
)mmioinfo
, wMsg
, lp1
, lp2
);
409 if (ioProc
->is_unicode
!= is_unicode
) {
410 /* unmap (lParam1, lParam2) into (lp1, lp2) 32 A<=>W */
417 /**************************************************************************
418 * MMIO_ParseExtA [internal]
420 * Parses a filename for the extension.
423 * The FOURCC code for the extension if found, else 0.
425 static FOURCC
MMIO_ParseExtA(LPCSTR szFileName
)
427 /* Filenames are of the form file.ext{+ABC}
428 For now, we take the last '+' if present */
432 /* Note that ext{Start,End} point to the . and + respectively */
438 TRACE("(%s)\n", debugstr_a(szFileName
));
443 /* Find the last '+' */
444 extEnd
= strrchr(szFileName
,'+');
447 /* No + so just an extension */
450 /* Find the first '.' before '+' */
451 extStart
= extEnd
- 1;
452 while (extStart
>= szFileName
&& *extStart
!= '.') {
455 if (extStart
< szFileName
) {
456 ERR("No extension in szFileName: %s\n", debugstr_a(szFileName
));
461 if (extEnd
- extStart
- 1 > 4)
462 WARN("Extension length > 4\n");
463 lstrcpynA(ext
, extStart
+ 1, min(extEnd
-extStart
,5));
465 TRACE("Got extension: %s\n", debugstr_a(ext
));
467 /* FOURCC codes identifying file-extensions must be uppercase */
468 ret
= mmioStringToFOURCCA(ext
, MMIO_TOUPPER
);
473 /**************************************************************************
474 * MMIO_Get [internal]
476 * Retrieves the mmio object from current process
478 static LPWINE_MMIO
MMIO_Get(HMMIO h
)
480 LPWINE_MMIO wm
= NULL
;
482 EnterCriticalSection(&WINMM_cs
);
483 for (wm
= MMIOList
; wm
; wm
= wm
->lpNext
) {
484 if (wm
->info
.hmmio
== h
)
487 LeaveCriticalSection(&WINMM_cs
);
491 /**************************************************************************
492 * MMIO_Create [internal]
494 * Creates an internal representation for a mmio instance
496 static LPWINE_MMIO
MMIO_Create(void)
498 static WORD MMIO_counter
= 0;
501 wm
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MMIO
));
503 EnterCriticalSection(&WINMM_cs
);
504 /* lookup next unallocated WORD handle, with a non NULL value */
505 while (++MMIO_counter
== 0 || MMIO_Get((HMMIO
)(ULONG_PTR
)MMIO_counter
));
506 wm
->info
.hmmio
= (HMMIO
)(ULONG_PTR
)MMIO_counter
;
507 wm
->lpNext
= MMIOList
;
509 LeaveCriticalSection(&WINMM_cs
);
514 /**************************************************************************
515 * MMIO_Destroy [internal]
517 * Destroys an internal representation for a mmio instance
519 static BOOL
MMIO_Destroy(LPWINE_MMIO wm
)
523 EnterCriticalSection(&WINMM_cs
);
524 /* search for the matching one... */
526 while (*m
&& *m
!= wm
) m
= &(*m
)->lpNext
;
530 HeapFree(GetProcessHeap(), 0, wm
);
533 LeaveCriticalSection(&WINMM_cs
);
537 /****************************************************************
538 * MMIO_Flush [INTERNAL]
540 static MMRESULT
MMIO_Flush(WINE_MMIO
* wm
, UINT uFlags
)
542 if (wm
->info
.cchBuffer
&& (wm
->info
.fccIOProc
!= FOURCC_MEM
)) {
543 /* not quite sure what to do here, but I'll guess */
544 if (wm
->info
.dwFlags
& MMIO_DIRTY
) {
545 /* FIXME: error handling */
546 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, wm
->info
.lBufOffset
, SEEK_SET
, FALSE
);
547 send_message(wm
->ioProc
, &wm
->info
, MMIOM_WRITE
,
548 (LPARAM
)wm
->info
.pchBuffer
,
549 wm
->info
.pchNext
- wm
->info
.pchBuffer
, FALSE
);
551 if (uFlags
& MMIO_EMPTYBUF
)
552 wm
->info
.pchNext
= wm
->info
.pchEndRead
= wm
->info
.pchBuffer
;
554 wm
->info
.dwFlags
&= ~MMIO_DIRTY
;
556 return MMSYSERR_NOERROR
;
559 /***************************************************************************
560 * MMIO_GrabNextBuffer [INTERNAL]
562 static LONG
MMIO_GrabNextBuffer(LPWINE_MMIO wm
, int for_read
)
564 LONG size
= wm
->info
.cchBuffer
;
566 TRACE("bo=%lx do=%lx\n",
567 wm
->info
.lBufOffset
, wm
->info
.lDiskOffset
);
569 wm
->info
.lBufOffset
= wm
->info
.lDiskOffset
;
570 wm
->info
.pchNext
= wm
->info
.pchBuffer
;
571 wm
->info
.pchEndRead
= wm
->info
.pchBuffer
;
572 wm
->info
.pchEndWrite
= wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
;
574 wm
->bBufferLoaded
= TRUE
;
576 size
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_READ
,
577 (LPARAM
)wm
->info
.pchBuffer
, size
, FALSE
);
579 wm
->info
.pchEndRead
+= size
;
581 wm
->bBufferLoaded
= FALSE
;
587 /***************************************************************************
588 * MMIO_SetBuffer [INTERNAL]
590 static MMRESULT
MMIO_SetBuffer(WINE_MMIO
* wm
, void* pchBuffer
, LONG cchBuffer
,
593 TRACE("(%p %p %ld %u)\n", wm
, pchBuffer
, cchBuffer
, uFlags
);
595 if (cchBuffer
> 0xFFFF)
596 WARN("Untested handling of huge mmio buffers (%ld >= 64k)\n", cchBuffer
);
598 if (MMIO_Flush(wm
, 0) != MMSYSERR_NOERROR
)
599 return MMIOERR_CANNOTWRITE
;
601 /* free previous buffer if allocated */
602 if (wm
->info
.dwFlags
& MMIO_ALLOCBUF
) {
603 HeapFree(GetProcessHeap(), 0, wm
->info
.pchBuffer
);
604 wm
->info
.pchBuffer
= NULL
;
605 wm
->info
.dwFlags
&= ~MMIO_ALLOCBUF
;
609 wm
->info
.pchBuffer
= pchBuffer
;
610 } else if (cchBuffer
) {
611 if (!(wm
->info
.pchBuffer
= HeapAlloc(GetProcessHeap(), 0, cchBuffer
)))
612 return MMIOERR_OUTOFMEMORY
;
613 wm
->info
.dwFlags
|= MMIO_ALLOCBUF
;
615 wm
->info
.pchBuffer
= NULL
;
618 wm
->info
.cchBuffer
= cchBuffer
;
619 wm
->info
.pchNext
= wm
->info
.pchBuffer
;
620 wm
->info
.pchEndRead
= wm
->info
.pchBuffer
;
621 wm
->info
.pchEndWrite
= wm
->info
.pchBuffer
+ cchBuffer
;
622 wm
->info
.lBufOffset
= wm
->info
.lDiskOffset
;
623 wm
->bBufferLoaded
= (wm
->info
.fccIOProc
== FOURCC_MEM
);
625 return MMSYSERR_NOERROR
;
628 /**************************************************************************
629 * MMIO_Open [internal]
631 static HMMIO
MMIO_Open(LPSTR szFileName
, MMIOINFO
* refmminfo
, DWORD dwOpenFlags
, BOOL is_unicode
)
637 TRACE("(%s, %p, %08lX, %s);\n", debugstr_a(szFileName
), refmminfo
, dwOpenFlags
, is_unicode
? "unicode" : "ansi");
640 refmminfo
= &mmioinfo
;
641 memset(&mmioinfo
, 0, sizeof(mmioinfo
));
645 if (dwOpenFlags
& (MMIO_PARSE
|MMIO_EXIST
)) {
646 char buffer
[MAX_PATH
];
650 if (GetFullPathNameA(szFileName
, sizeof(buffer
), buffer
, NULL
) >= sizeof(buffer
))
652 if ((dwOpenFlags
& MMIO_EXIST
) && (GetFileAttributesA(buffer
) == INVALID_FILE_ATTRIBUTES
))
654 strcpy(szFileName
, buffer
);
658 if ((wm
= MMIO_Create()) == NULL
)
661 /* If both params are NULL, then parse the file name if available */
662 if (refmminfo
->fccIOProc
== 0 && refmminfo
->pIOProc
== NULL
) {
663 wm
->info
.fccIOProc
= MMIO_ParseExtA(szFileName
);
664 /* Handle any unhandled/error case. Assume DOS file */
665 if (wm
->info
.fccIOProc
== 0) {
666 wm
->info
.fccIOProc
= FOURCC_DOS
;
667 wm
->ioProc
= &defaultProcs
[0];
669 else if (!(wm
->ioProc
= MMIO_FindProcNode(wm
->info
.fccIOProc
))) {
670 /* If not found, assume DOS file */
671 wm
->ioProc
= &defaultProcs
[0];
673 wm
->bTmpIOProc
= FALSE
;
675 /* if just the four character code is present, look up IO proc */
676 else if (refmminfo
->pIOProc
== NULL
) {
677 wm
->info
.fccIOProc
= refmminfo
->fccIOProc
;
678 if (!(wm
->ioProc
= MMIO_FindProcNode(wm
->info
.fccIOProc
))) goto error2
;
679 wm
->bTmpIOProc
= FALSE
;
681 /* if IO proc specified, use it and specified four character code */
683 wm
->info
.fccIOProc
= refmminfo
->fccIOProc
;
684 MMIO_InstallIOProc(wm
->info
.fccIOProc
, refmminfo
->pIOProc
,
685 MMIO_INSTALLPROC
, is_unicode
);
686 if (!(wm
->ioProc
= MMIO_FindProcNode(wm
->info
.fccIOProc
))) goto error2
;
687 assert(wm
->ioProc
->pIOProc
== refmminfo
->pIOProc
);
688 wm
->bTmpIOProc
= TRUE
;
692 wm
->info
.dwFlags
= dwOpenFlags
;
694 if (dwOpenFlags
& MMIO_ALLOCBUF
) {
695 refmminfo
->wErrorRet
= MMIO_SetBuffer(wm
, refmminfo
->pchBuffer
,
696 refmminfo
->cchBuffer
? refmminfo
->cchBuffer
: MMIO_DEFAULTBUFFER
, 0);
697 if (refmminfo
->wErrorRet
!= MMSYSERR_NOERROR
)
700 refmminfo
->wErrorRet
= MMIO_SetBuffer(wm
, refmminfo
->pchBuffer
, refmminfo
->cchBuffer
, 0);
701 if (refmminfo
->wErrorRet
!= MMSYSERR_NOERROR
)
705 /* see mmioDosIOProc for that one */
706 memcpy( wm
->info
.adwInfo
, refmminfo
->adwInfo
, sizeof(wm
->info
.adwInfo
) );
708 /* call IO proc to actually open file */
709 refmminfo
->wErrorRet
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_OPEN
,
710 (LPARAM
)szFileName
, 0, FALSE
);
712 /* update offsets and grab file size, when possible */
713 if (wm
->info
.fccIOProc
== FOURCC_DOS
&& (send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, 0, SEEK_CUR
, FALSE
)) != -1) {
714 pos
= wm
->info
.lBufOffset
= wm
->info
.lDiskOffset
;
715 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, 0, SEEK_END
, FALSE
);
716 wm
->dwFileSize
= wm
->info
.lDiskOffset
;
717 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, pos
, SEEK_SET
, FALSE
);
719 else wm
->dwFileSize
= 0;
721 if (refmminfo
->wErrorRet
== 0)
722 return wm
->info
.hmmio
;
724 if (wm
->info
.dwFlags
& MMIO_ALLOCBUF
)
725 HeapFree(GetProcessHeap(), 0, wm
->info
.pchBuffer
);
726 if (wm
->ioProc
) wm
->ioProc
->count
--;
732 /**************************************************************************
733 * mmioOpenW [WINMM.@]
735 HMMIO WINAPI
mmioOpenW(LPWSTR szFileName
, MMIOINFO
* lpmmioinfo
,
743 INT len
= WideCharToMultiByte( CP_ACP
, 0, szFileName
, -1, NULL
, 0, NULL
, NULL
);
744 if (len
< MAX_PATH
) len
= MAX_PATH
;
745 szFn
= HeapAlloc( GetProcessHeap(), 0, len
);
746 if (!szFn
) return NULL
;
747 WideCharToMultiByte( CP_ACP
, 0, szFileName
, -1, szFn
, len
, NULL
, NULL
);
750 ret
= MMIO_Open(szFn
, lpmmioinfo
, dwOpenFlags
, TRUE
);
752 HeapFree(GetProcessHeap(), 0, szFn
);
756 /**************************************************************************
757 * mmioOpenA [WINMM.@]
759 HMMIO WINAPI
mmioOpenA(LPSTR szFileName
, MMIOINFO
* lpmmioinfo
,
762 return MMIO_Open(szFileName
, lpmmioinfo
, dwOpenFlags
, FALSE
);
765 /**************************************************************************
766 * mmioClose [WINMM.@]
768 MMRESULT WINAPI
mmioClose(HMMIO hmmio
, UINT uFlags
)
773 TRACE("(%p, %04X);\n", hmmio
, uFlags
);
775 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
776 return MMSYSERR_INVALHANDLE
;
778 if ((result
= MMIO_Flush(wm
, 0)) != MMSYSERR_NOERROR
)
781 result
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_CLOSE
, uFlags
, 0, FALSE
);
783 MMIO_SetBuffer(wm
, NULL
, 0, 0);
788 MMIO_InstallIOProc(wm
->info
.fccIOProc
, wm
->ioProc
->pIOProc
,
789 MMIO_REMOVEPROC
, wm
->ioProc
->is_unicode
);
796 /**************************************************************************
799 LONG WINAPI
mmioRead(HMMIO hmmio
, HPSTR pch
, LONG cch
)
804 TRACE("(%p, %p, %ld);\n", hmmio
, pch
, cch
);
806 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
809 /* unbuffered case first */
810 if (!wm
->info
.pchBuffer
)
811 return send_message(wm
->ioProc
, &wm
->info
, MMIOM_READ
, (LPARAM
)pch
, cch
, FALSE
);
813 /* first try from current buffer */
814 if (cch
&& wm
->info
.fccIOProc
!= FOURCC_MEM
&& wm
->info
.pchNext
== wm
->info
.pchEndRead
)
815 MMIO_GrabNextBuffer(wm
, TRUE
);
816 if (wm
->info
.pchNext
!= wm
->info
.pchEndRead
) {
817 count
= wm
->info
.pchEndRead
- wm
->info
.pchNext
;
818 if (count
> cch
|| count
< 0) count
= cch
;
819 memcpy(pch
, wm
->info
.pchNext
, count
);
820 wm
->info
.pchNext
+= count
;
826 if (cch
&& (wm
->info
.fccIOProc
!= FOURCC_MEM
)) {
827 assert(wm
->info
.cchBuffer
);
832 size
= MMIO_GrabNextBuffer(wm
, TRUE
);
833 if (size
<= 0) break;
834 if (size
> cch
) size
= cch
;
835 memcpy(pch
, wm
->info
.pchBuffer
, size
);
836 wm
->info
.pchNext
+= size
;
841 wm
->bBufferLoaded
= FALSE
;
842 mmioSeek(hmmio
, 0, SEEK_CUR
);
845 TRACE("count=%ld\n", count
);
849 /**************************************************************************
850 * mmioWrite [WINMM.@]
852 LONG WINAPI
mmioWrite(HMMIO hmmio
, HPCSTR pch
, LONG cch
)
857 TRACE("(%p, %p, %ld);\n", hmmio
, pch
, cch
);
859 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
862 if (wm
->info
.cchBuffer
) {
866 if (wm
->info
.pchNext
!= wm
->info
.pchEndWrite
) {
867 count
= wm
->info
.pchEndWrite
- wm
->info
.pchNext
;
868 if (count
> cch
|| count
< 0) count
= cch
;
869 memcpy(wm
->info
.pchNext
, pch
, count
);
870 wm
->info
.pchNext
+= count
;
874 wm
->info
.dwFlags
|= MMIO_DIRTY
;
876 if (wm
->info
.fccIOProc
== FOURCC_MEM
) {
877 if (wm
->info
.adwInfo
[0]) {
878 /* from where would we get the memory handle? */
879 FIXME("memory file expansion not implemented!\n");
885 if (wm
->info
.pchNext
== wm
->info
.pchEndWrite
)
887 MMIO_Flush(wm
, MMIO_EMPTYBUF
);
888 MMIO_GrabNextBuffer(wm
, FALSE
);
894 count
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_WRITE
, (LPARAM
)pch
, cch
, FALSE
);
895 wm
->info
.lBufOffset
= wm
->info
.lDiskOffset
;
898 TRACE("bytes written=%ld\n", count
);
902 /**************************************************************************
905 LONG WINAPI
mmioSeek(HMMIO hmmio
, LONG lOffset
, INT iOrigin
)
910 TRACE("(%p, %08lX, %d);\n", hmmio
, lOffset
, iOrigin
);
912 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
913 return MMSYSERR_INVALHANDLE
;
915 /* not buffered, direct seek on file */
916 if (!wm
->info
.pchBuffer
&& wm
->info
.fccIOProc
!= FOURCC_MEM
) {
917 LRESULT ret
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, lOffset
, iOrigin
, FALSE
);
919 wm
->info
.lBufOffset
= wm
->info
.lDiskOffset
;
928 offset
= wm
->info
.lBufOffset
+ (wm
->info
.pchNext
- wm
->info
.pchBuffer
) + lOffset
;
931 switch (wm
->info
.fccIOProc
) {
933 offset
= wm
->info
.cchBuffer
- lOffset
;
936 offset
= wm
->dwFileSize
- lOffset
;
939 offset
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, lOffset
, SEEK_END
, FALSE
);
947 /* stay in same buffer ? */
948 /* some memory mapped buffers are defined with -1 as a size */
949 if ((wm
->info
.cchBuffer
> 0) &&
950 ((offset
< wm
->info
.lBufOffset
) ||
951 (offset
> wm
->info
.lBufOffset
+ wm
->info
.cchBuffer
) ||
952 (offset
> wm
->dwFileSize
&& wm
->info
.fccIOProc
== FOURCC_DOS
) ||
953 !wm
->bBufferLoaded
)) {
955 /* condition to change buffer */
956 if ((wm
->info
.fccIOProc
== FOURCC_MEM
) ||
957 MMIO_Flush(wm
, 0) != MMSYSERR_NOERROR
||
958 /* this also sets the wm->info.lDiskOffset field */
959 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
,
960 offset
, SEEK_SET
, FALSE
) == -1)
962 wm
->info
.lBufOffset
= offset
;
963 wm
->bBufferLoaded
= FALSE
;
964 wm
->info
.pchNext
= wm
->info
.pchEndRead
= wm
->info
.pchBuffer
;
967 wm
->info
.pchNext
= wm
->info
.pchBuffer
+ (offset
- wm
->info
.lBufOffset
);
969 TRACE("=> %ld\n", offset
);
973 /**************************************************************************
974 * mmioGetInfo [WINMM.@]
976 MMRESULT WINAPI
mmioGetInfo(HMMIO hmmio
, MMIOINFO
* lpmmioinfo
, UINT uFlags
)
980 TRACE("(%p,%p,0x%08x)\n",hmmio
,lpmmioinfo
,uFlags
);
982 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
983 return MMSYSERR_INVALHANDLE
;
985 *lpmmioinfo
= wm
->info
;
987 return MMSYSERR_NOERROR
;
990 /**************************************************************************
991 * mmioSetInfo [WINMM.@]
993 MMRESULT WINAPI
mmioSetInfo(HMMIO hmmio
, const MMIOINFO
* lpmmioinfo
, UINT uFlags
)
997 TRACE("(%p,%p,0x%08x)\n",hmmio
,lpmmioinfo
,uFlags
);
999 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
1000 return MMSYSERR_INVALHANDLE
;
1002 /* check pointers coherence */
1003 if (lpmmioinfo
->pchNext
< wm
->info
.pchBuffer
||
1004 lpmmioinfo
->pchNext
> wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
||
1005 lpmmioinfo
->pchEndRead
< wm
->info
.pchBuffer
||
1006 lpmmioinfo
->pchEndRead
> wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
||
1007 lpmmioinfo
->pchEndWrite
< wm
->info
.pchBuffer
||
1008 lpmmioinfo
->pchEndWrite
> wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
)
1009 return MMSYSERR_INVALPARAM
;
1011 wm
->info
= *lpmmioinfo
;
1012 return MMSYSERR_NOERROR
;
1015 /**************************************************************************
1016 * mmioSetBuffer [WINMM.@]
1018 MMRESULT WINAPI
mmioSetBuffer(HMMIO hmmio
, LPSTR pchBuffer
, LONG cchBuffer
, UINT uFlags
)
1022 TRACE("(hmmio=%p, pchBuf=%p, cchBuf=%ld, uFlags=%#08x)\n",
1023 hmmio
, pchBuffer
, cchBuffer
, uFlags
);
1025 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
1026 return MMSYSERR_INVALHANDLE
;
1028 return MMIO_SetBuffer(wm
, pchBuffer
, cchBuffer
, uFlags
);
1031 /**************************************************************************
1032 * mmioFlush [WINMM.@]
1034 MMRESULT WINAPI
mmioFlush(HMMIO hmmio
, UINT uFlags
)
1038 TRACE("(%p, %04X)\n", hmmio
, uFlags
);
1040 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
1041 return MMSYSERR_INVALHANDLE
;
1043 return MMIO_Flush(wm
, uFlags
);
1046 /**************************************************************************
1047 * mmioAdvance [WINMM.@]
1049 MMRESULT WINAPI
mmioAdvance(HMMIO hmmio
, MMIOINFO
* lpmmioinfo
, UINT uFlags
)
1053 TRACE("hmmio=%p, lpmmioinfo=%p, uFlags=%04X\n", hmmio
, lpmmioinfo
, uFlags
);
1055 /* NOTE: mmioAdvance16 heavily relies on parameters from lpmmioinfo we're using
1056 * here. be sure if you change something here to check mmioAdvance16 as well
1058 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
1059 return MMSYSERR_INVALHANDLE
;
1061 if (!wm
->info
.cchBuffer
)
1062 return MMIOERR_UNBUFFERED
;
1064 if (uFlags
!= MMIO_READ
&& uFlags
!= MMIO_WRITE
)
1065 return MMSYSERR_INVALPARAM
;
1067 if (MMIO_Flush(wm
, 0) != MMSYSERR_NOERROR
)
1068 return MMIOERR_CANNOTWRITE
;
1069 if (uFlags
== MMIO_WRITE
&& (lpmmioinfo
->dwFlags
& MMIO_DIRTY
))
1071 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, lpmmioinfo
->lBufOffset
, SEEK_SET
, FALSE
);
1072 send_message(wm
->ioProc
, &wm
->info
, MMIOM_WRITE
, (LPARAM
)lpmmioinfo
->pchBuffer
,
1073 lpmmioinfo
->pchNext
- lpmmioinfo
->pchBuffer
, FALSE
);
1074 lpmmioinfo
->dwFlags
&= ~MMIO_DIRTY
;
1077 if (lpmmioinfo
&& lpmmioinfo
->fccIOProc
== FOURCC_DOS
) {
1078 wm
->dwFileSize
= max(wm
->dwFileSize
, lpmmioinfo
->lBufOffset
+
1079 (lpmmioinfo
->pchNext
- lpmmioinfo
->pchBuffer
));
1081 MMIO_GrabNextBuffer(wm
, uFlags
== MMIO_READ
);
1084 lpmmioinfo
->pchNext
= lpmmioinfo
->pchBuffer
;
1085 lpmmioinfo
->pchEndRead
= lpmmioinfo
->pchBuffer
+
1086 (wm
->info
.pchEndRead
- wm
->info
.pchBuffer
);
1087 lpmmioinfo
->pchEndWrite
= lpmmioinfo
->pchBuffer
+
1088 (wm
->info
.pchEndWrite
- wm
->info
.pchBuffer
);
1089 lpmmioinfo
->lDiskOffset
= wm
->info
.lDiskOffset
;
1090 lpmmioinfo
->lBufOffset
= wm
->info
.lBufOffset
;
1092 return MMSYSERR_NOERROR
;
1095 /**************************************************************************
1096 * mmioStringToFOURCCA [WINMM.@]
1098 FOURCC WINAPI
mmioStringToFOURCCA(LPCSTR sz
, UINT uFlags
)
1103 for (i
= 0; i
< 4 && sz
[i
]; i
++) {
1104 if (uFlags
& MMIO_TOUPPER
) {
1105 cc
[i
] = RtlUpperChar(sz
[i
]);
1111 /* Pad with spaces */
1112 while (i
< 4) cc
[i
++] = ' ';
1114 TRACE("Got %s\n",debugstr_an(cc
,4));
1115 return mmioFOURCC(cc
[0],cc
[1],cc
[2],cc
[3]);
1118 /**************************************************************************
1119 * mmioStringToFOURCCW [WINMM.@]
1121 FOURCC WINAPI
mmioStringToFOURCCW(LPCWSTR sz
, UINT uFlags
)
1125 WideCharToMultiByte( CP_ACP
, 0, sz
, 4, szA
, sizeof(szA
), NULL
, NULL
);
1126 return mmioStringToFOURCCA(szA
,uFlags
);
1129 /**************************************************************************
1130 * mmioInstallIOProcA [WINMM.@]
1132 LPMMIOPROC WINAPI
mmioInstallIOProcA(FOURCC fccIOProc
,
1133 LPMMIOPROC pIOProc
, DWORD dwFlags
)
1135 return MMIO_InstallIOProc(fccIOProc
, pIOProc
, dwFlags
, FALSE
);
1138 /**************************************************************************
1139 * mmioInstallIOProcW [WINMM.@]
1141 LPMMIOPROC WINAPI
mmioInstallIOProcW(FOURCC fccIOProc
,
1142 LPMMIOPROC pIOProc
, DWORD dwFlags
)
1144 return MMIO_InstallIOProc(fccIOProc
, pIOProc
, dwFlags
, TRUE
);
1147 /******************************************************************
1152 static LRESULT
MMIO_SendMessage(HMMIO hmmio
, UINT uMessage
, LPARAM lParam1
,
1153 LPARAM lParam2
, BOOL is_unicode
)
1157 TRACE("(%p, %u, %Id, %Id, %s)\n", hmmio
, uMessage
, lParam1
, lParam2
, is_unicode
? "unicode" : "ansi");
1159 if (uMessage
< MMIOM_USER
)
1160 return MMSYSERR_INVALPARAM
;
1162 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
1163 return MMSYSERR_INVALHANDLE
;
1165 return send_message(wm
->ioProc
, &wm
->info
, uMessage
, lParam1
, lParam2
, is_unicode
);
1168 /**************************************************************************
1169 * mmioSendMessage [WINMM.@]
1171 LRESULT WINAPI
mmioSendMessage(HMMIO hmmio
, UINT uMessage
,
1172 LPARAM lParam1
, LPARAM lParam2
)
1174 return MMIO_SendMessage(hmmio
, uMessage
, lParam1
, lParam2
, FALSE
);
1177 /**************************************************************************
1178 * mmioDescend [WINMM.@]
1180 MMRESULT WINAPI
mmioDescend(HMMIO hmmio
, LPMMCKINFO lpck
,
1181 const MMCKINFO
* lpckParent
, UINT uFlags
)
1187 TRACE("(%p, %p, %p, %04X);\n", hmmio
, lpck
, lpckParent
, uFlags
);
1190 return MMSYSERR_INVALPARAM
;
1192 dwOldPos
= mmioSeek(hmmio
, 0, SEEK_CUR
);
1193 TRACE("dwOldPos=%ld\n", dwOldPos
);
1195 if (lpckParent
!= NULL
) {
1196 TRACE("seek inside parent at %ld !\n", lpckParent
->dwDataOffset
);
1197 /* EPP: was dwOldPos = mmioSeek(hmmio,lpckParent->dwDataOffset,SEEK_SET); */
1198 if (dwOldPos
< lpckParent
->dwDataOffset
||
1199 dwOldPos
>= lpckParent
->dwDataOffset
+ lpckParent
->cksize
) {
1200 WARN("outside parent chunk\n");
1201 return MMIOERR_CHUNKNOTFOUND
;
1205 /* The SDK docu says 'ckid' is used for all cases. Real World
1206 * examples disagree -Marcus,990216.
1212 /* find_chunk looks for 'ckid' */
1213 if (uFlags
& MMIO_FINDCHUNK
)
1214 srchCkId
= lpck
->ckid
;
1216 /* find_riff and find_list look for 'fccType' */
1217 if (uFlags
& MMIO_FINDLIST
)
1219 srchCkId
= FOURCC_LIST
;
1220 srchType
= lpck
->fccType
;
1223 if (uFlags
& MMIO_FINDRIFF
)
1225 srchCkId
= FOURCC_RIFF
;
1226 srchType
= lpck
->fccType
;
1229 TRACE("searching for %s.%s\n",
1230 debugstr_an((LPCSTR
)&srchCkId
, 4), srchType
? debugstr_an((LPCSTR
)&srchType
, 4) : "<any>");
1236 ix
= mmioRead(hmmio
, (LPSTR
)lpck
, 3 * sizeof(DWORD
));
1237 if (ix
< 0 || ix
< 2*sizeof(DWORD
))
1239 mmioSeek(hmmio
, dwOldPos
, SEEK_SET
);
1240 WARN("return ChunkNotFound\n");
1241 return MMIOERR_CHUNKNOTFOUND
;
1244 lpck
->dwDataOffset
= dwOldPos
+ 2 * sizeof(DWORD
);
1245 TRACE("ckid=%s fcc=%s cksize=%08lX !\n",
1246 debugstr_an((LPCSTR
)&lpck
->ckid
, 4),
1247 srchType
? debugstr_an((LPCSTR
)&lpck
->fccType
, 4) : "<na>",
1249 if ( (!srchCkId
|| (srchCkId
== lpck
->ckid
)) &&
1250 (!srchType
|| (srchType
== lpck
->fccType
)) )
1253 dwOldPos
= lpck
->dwDataOffset
+ ((lpck
->cksize
+ 1) & ~1);
1254 mmioSeek(hmmio
, dwOldPos
, SEEK_SET
);
1258 /* If we were looking for RIFF/LIST chunks, the final file position
1259 * is after the chunkid. If we were just looking for the chunk
1260 * it is after the cksize. So add 4 in RIFF/LIST case.
1262 if (lpck
->ckid
== FOURCC_RIFF
|| lpck
->ckid
== FOURCC_LIST
)
1263 mmioSeek(hmmio
, lpck
->dwDataOffset
+ sizeof(DWORD
), SEEK_SET
);
1266 mmioSeek(hmmio
, lpck
->dwDataOffset
, SEEK_SET
);
1269 TRACE("lpck: ckid=%s, cksize=%ld, dwDataOffset=%ld fccType=%08lX (%s)!\n",
1270 debugstr_an((LPSTR
)&lpck
->ckid
, 4), lpck
->cksize
, lpck
->dwDataOffset
,
1271 lpck
->fccType
, srchType
? debugstr_an((LPSTR
)&lpck
->fccType
, 4):"");
1272 return MMSYSERR_NOERROR
;
1275 /**************************************************************************
1276 * mmioAscend [WINMM.@]
1278 MMRESULT WINAPI
mmioAscend(HMMIO hmmio
, LPMMCKINFO lpck
, UINT uFlags
)
1280 TRACE("(%p, %p, %04X);\n", hmmio
, lpck
, uFlags
);
1282 if (lpck
->dwFlags
& MMIO_DIRTY
) {
1283 DWORD dwOldPos
, dwNewSize
;
1285 TRACE("Chunk is dirty, checking if chunk's size is correct\n");
1286 dwOldPos
= mmioSeek(hmmio
, 0, SEEK_CUR
);
1287 TRACE("dwOldPos=%ld lpck->dwDataOffset = %ld\n", dwOldPos
, lpck
->dwDataOffset
);
1288 dwNewSize
= dwOldPos
- lpck
->dwDataOffset
;
1289 if (dwNewSize
!= lpck
->cksize
) {
1290 TRACE("Nope: lpck->cksize=%ld dwNewSize=%ld\n", lpck
->cksize
, dwNewSize
);
1291 lpck
->cksize
= dwNewSize
;
1293 /* pad odd size with 0 */
1294 if (dwNewSize
& 1) {
1296 mmioWrite(hmmio
, &ch
, 1);
1298 mmioSeek(hmmio
, lpck
->dwDataOffset
- sizeof(DWORD
), SEEK_SET
);
1299 mmioWrite(hmmio
, (LPSTR
)&dwNewSize
, sizeof(DWORD
));
1304 mmioSeek(hmmio
, lpck
->dwDataOffset
+ ((lpck
->cksize
+ 1) & ~1), SEEK_SET
);
1306 return MMSYSERR_NOERROR
;
1309 /**************************************************************************
1310 * mmioCreateChunk [WINMM.@]
1312 MMRESULT WINAPI
mmioCreateChunk(HMMIO hmmio
, MMCKINFO
* lpck
, UINT uFlags
)
1318 TRACE("(%p, %p, %04X);\n", hmmio
, lpck
, uFlags
);
1320 dwOldPos
= mmioSeek(hmmio
, 0, SEEK_CUR
);
1321 TRACE("dwOldPos=%ld\n", dwOldPos
);
1323 if (uFlags
== MMIO_CREATELIST
)
1324 lpck
->ckid
= FOURCC_LIST
;
1325 else if (uFlags
== MMIO_CREATERIFF
)
1326 lpck
->ckid
= FOURCC_RIFF
;
1328 TRACE("ckid=%s\n", debugstr_an((LPSTR
)&lpck
->ckid
, 4));
1330 size
= 2 * sizeof(DWORD
);
1331 lpck
->dwDataOffset
= dwOldPos
+ size
;
1333 if (lpck
->ckid
== FOURCC_RIFF
|| lpck
->ckid
== FOURCC_LIST
)
1334 size
+= sizeof(DWORD
);
1335 lpck
->dwFlags
= MMIO_DIRTY
;
1337 ix
= mmioWrite(hmmio
, (LPSTR
)lpck
, size
);
1338 TRACE("after mmioWrite ix = %ld req = %ld, errno = %d\n", ix
, size
, errno
);
1340 mmioSeek(hmmio
, dwOldPos
, SEEK_SET
);
1341 WARN("return CannotWrite\n");
1342 return MMIOERR_CANNOTWRITE
;
1345 return MMSYSERR_NOERROR
;
1348 /**************************************************************************
1349 * mmioRenameA [WINMM.@]
1351 MMRESULT WINAPI
mmioRenameA(LPCSTR szFileName
, LPCSTR szNewFileName
,
1352 const MMIOINFO
* lpmmioinfo
, DWORD dwFlags
)
1354 struct IOProcList
* ioProc
= NULL
;
1355 struct IOProcList tmp
;
1358 TRACE("(%s, %s, %p, %08lX);\n",
1359 debugstr_a(szFileName
), debugstr_a(szNewFileName
), lpmmioinfo
, dwFlags
);
1361 /* If both params are NULL, then parse the file name */
1362 if (lpmmioinfo
&& lpmmioinfo
->fccIOProc
== 0 && lpmmioinfo
->pIOProc
== NULL
)
1364 fcc
= MMIO_ParseExtA(szFileName
);
1365 if (fcc
) ioProc
= MMIO_FindProcNode(fcc
);
1368 /* Handle any unhandled/error case from above. Assume DOS file */
1369 if (!lpmmioinfo
|| (lpmmioinfo
->fccIOProc
== 0 && lpmmioinfo
->pIOProc
== NULL
&& ioProc
== NULL
))
1370 ioProc
= &defaultProcs
[0];
1371 /* if just the four character code is present, look up IO proc */
1372 else if (lpmmioinfo
->pIOProc
== NULL
)
1373 ioProc
= MMIO_FindProcNode(lpmmioinfo
->fccIOProc
);
1374 else /* use relevant ioProc */
1377 tmp
.fourCC
= lpmmioinfo
->fccIOProc
;
1378 tmp
.pIOProc
= lpmmioinfo
->pIOProc
;
1379 tmp
.is_unicode
= FALSE
;
1383 /* FIXME: should we actually pass lpmmioinfo down the drain ???
1384 * or make a copy of it because it's const ???
1386 return send_message(ioProc
, (MMIOINFO
*)lpmmioinfo
, MMIOM_RENAME
,
1387 (LPARAM
)szFileName
, (LPARAM
)szNewFileName
, FALSE
);
1390 /**************************************************************************
1391 * mmioRenameW [WINMM.@]
1393 MMRESULT WINAPI
mmioRenameW(LPCWSTR szFileName
, LPCWSTR szNewFileName
,
1394 const MMIOINFO
* lpmmioinfo
, DWORD dwFlags
)
1398 UINT ret
= MMSYSERR_NOMEM
;
1403 len
= WideCharToMultiByte( CP_ACP
, 0, szFileName
, -1, NULL
, 0, NULL
, NULL
);
1404 szFn
= HeapAlloc( GetProcessHeap(), 0, len
);
1405 if (!szFn
) goto done
;
1406 WideCharToMultiByte( CP_ACP
, 0, szFileName
, -1, szFn
, len
, NULL
, NULL
);
1410 len
= WideCharToMultiByte( CP_ACP
, 0, szNewFileName
, -1, NULL
, 0, NULL
, NULL
);
1411 sznFn
= HeapAlloc( GetProcessHeap(), 0, len
);
1412 if (!sznFn
) goto done
;
1413 WideCharToMultiByte( CP_ACP
, 0, szNewFileName
, -1, sznFn
, len
, NULL
, NULL
);
1416 ret
= mmioRenameA(szFn
, sznFn
, lpmmioinfo
, dwFlags
);
1419 HeapFree(GetProcessHeap(),0,szFn
);
1420 HeapFree(GetProcessHeap(),0,sznFn
);