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
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(mmio
);
48 static WINE_MMIO
*MMIOList
;
50 /**************************************************************************
51 * mmioDosIOProc [internal]
53 static LRESULT CALLBACK
mmioDosIOProc(LPMMIOINFO lpmmioinfo
, UINT uMessage
,
54 LPARAM lParam1
, LPARAM lParam2
)
56 LRESULT ret
= MMSYSERR_NOERROR
;
58 TRACE("(%p, %X, 0x%lx, 0x%lx);\n", lpmmioinfo
, uMessage
, lParam1
, lParam2
);
64 * lParam1 = szFileName parameter from mmioOpen
66 * Returns: zero on success, error code on error
67 * NOTE: lDiskOffset automatically set to zero
69 LPCSTR szFileName
= (LPCSTR
)lParam1
;
71 if (lpmmioinfo
->dwFlags
& MMIO_GETTEMP
) {
72 FIXME("MMIO_GETTEMP not implemented\n");
73 return MMIOERR_CANNOTOPEN
;
76 /* if filename NULL, assume open file handle in adwInfo[0] */
79 lpmmioinfo
->adwInfo
[0] = OpenFile(szFileName
, &ofs
, lpmmioinfo
->dwFlags
& 0xFFFF);
81 if (lpmmioinfo
->adwInfo
[0] == HFILE_ERROR
)
82 ret
= MMIOERR_CANNOTOPEN
;
88 * lParam1 = wFlags parameter from mmioClose
90 * Returns: zero on success, error code on error
92 if (!(lParam1
& MMIO_FHOPEN
))
93 _lclose((HFILE
)lpmmioinfo
->adwInfo
[0]);
98 * lParam1 = huge pointer to read buffer
99 * lParam2 = number of bytes to read
100 * Returns: number of bytes read, 0 for EOF, -1 for error (error code
103 ret
= _lread((HFILE
)lpmmioinfo
->adwInfo
[0], (HPSTR
)lParam1
, (LONG
)lParam2
);
105 lpmmioinfo
->lDiskOffset
+= ret
;
110 case MMIOM_WRITEFLUSH
:
111 /* no internal buffering, so WRITEFLUSH handled same as WRITE */
114 * lParam1 = huge pointer to write buffer
115 * lParam2 = number of bytes to write
116 * Returns: number of bytes written, -1 for error (error code in
119 ret
= _hwrite((HFILE
)lpmmioinfo
->adwInfo
[0], (HPSTR
)lParam1
, (LONG
)lParam2
);
121 lpmmioinfo
->lDiskOffset
+= ret
;
126 * lParam1 = new position
127 * lParam2 = from whence to seek (SEEK_SET, SEEK_CUR, SEEK_END)
128 * Returns: new file postion, -1 on error
130 ret
= _llseek((HFILE
)lpmmioinfo
->adwInfo
[0], (LONG
)lParam1
, (LONG
)lParam2
);
132 lpmmioinfo
->lDiskOffset
= ret
;
139 * Returns: zero on success, non-zero on failure
141 if (!MoveFileA((const char*)lParam1
, (const char*)lParam2
))
142 ret
= MMIOERR_FILENOTFOUND
;
146 FIXME("unexpected message %u\n", uMessage
);
153 /**************************************************************************
154 * mmioMemIOProc [internal]
156 static LRESULT CALLBACK
mmioMemIOProc(LPMMIOINFO lpmmioinfo
, UINT uMessage
,
157 LPARAM lParam1
, LPARAM lParam2
)
159 TRACE("(%p,0x%04x,0x%08lx,0x%08lx)\n", lpmmioinfo
, uMessage
, lParam1
, lParam2
);
165 * lParam1 = filename (must be NULL)
167 * Returns: zero on success, error code on error
168 * NOTE: lDiskOffset automatically set to zero
170 /* FIXME: io proc shouldn't change it */
171 if (!(lpmmioinfo
->dwFlags
& MMIO_CREATE
))
172 lpmmioinfo
->pchEndRead
= lpmmioinfo
->pchEndWrite
;
173 lpmmioinfo
->adwInfo
[0] = HFILE_ERROR
;
178 * lParam1 = wFlags parameter from mmioClose
180 * Returns: zero on success, error code on error
186 * lParam1 = huge pointer to read buffer
187 * lParam2 = number of bytes to read
188 * Returns: number of bytes read, 0 for EOF, -1 for error (error code
190 * NOTE: lDiskOffset should be updated
192 FIXME("MMIOM_READ on memory files should not occur, buffer may be lost!\n");
196 case MMIOM_WRITEFLUSH
:
197 /* no internal buffering, so WRITEFLUSH handled same as WRITE */
200 * lParam1 = huge pointer to write buffer
201 * lParam2 = number of bytes to write
202 * Returns: number of bytes written, -1 for error (error code in
204 * NOTE: lDiskOffset should be updated
206 FIXME("MMIOM_WRITE on memory files should not occur, buffer may be lost!\n");
211 * lParam1 = new position
212 * lParam2 = from whence to seek (SEEK_SET, SEEK_CUR, SEEK_END)
213 * Returns: new file postion, -1 on error
214 * NOTE: lDiskOffset should be updated
216 FIXME("MMIOM_SEEK on memory files should not occur, buffer may be lost!\n");
220 FIXME("unexpected message %u\n", uMessage
);
225 /* This array will be the entire list for most apps
226 * Note that temporary ioProcs will be stored with a 0 fourCC code
229 static struct IOProcList defaultProcs
[] = {
230 {&defaultProcs
[1], FOURCC_DOS
, (LPMMIOPROC
)mmioDosIOProc
, FALSE
, 0},
231 {NULL
, FOURCC_MEM
, (LPMMIOPROC
)mmioMemIOProc
, FALSE
, 0},
234 static struct IOProcList
* pIOProcListAnchor
= &defaultProcs
[0];
236 /****************************************************************
237 * MMIO_FindProcNode [INTERNAL]
239 * Finds the ProcList node associated with a given FOURCC code.
241 static struct IOProcList
* MMIO_FindProcNode(FOURCC fccIOProc
)
243 struct IOProcList
* pListNode
;
245 for (pListNode
= pIOProcListAnchor
; pListNode
; pListNode
= pListNode
->pNext
) {
246 if (pListNode
->fourCC
== fccIOProc
) {
253 /****************************************************************
254 * MMIO_InstallIOProc [INTERNAL]
256 static LPMMIOPROC
MMIO_InstallIOProc(FOURCC fccIOProc
, LPMMIOPROC pIOProc
,
257 DWORD dwFlags
, BOOL is_unicode
)
259 LPMMIOPROC lpProc
= NULL
;
260 struct IOProcList
* pListNode
;
261 struct IOProcList
** ppListNode
;
263 TRACE("(%08x, %p, %08X, %s)\n", fccIOProc
, pIOProc
, dwFlags
, is_unicode
? "unicode" : "ansi");
265 if (dwFlags
& MMIO_GLOBALPROC
)
266 FIXME("Global procedures not implemented\n");
268 /* just handle the known procedures for now */
269 switch (dwFlags
& (MMIO_INSTALLPROC
|MMIO_REMOVEPROC
|MMIO_FINDPROC
)) {
270 case MMIO_INSTALLPROC
:
271 /* Create new entry for the IOProc list */
272 pListNode
= HeapAlloc(GetProcessHeap(), 0, sizeof(*pListNode
));
274 /* Fill in this node */
275 pListNode
->fourCC
= fccIOProc
;
276 pListNode
->pIOProc
= pIOProc
;
277 pListNode
->is_unicode
= is_unicode
;
278 pListNode
->count
= 0;
280 /* Stick it on the end of the list */
281 pListNode
->pNext
= pIOProcListAnchor
;
282 pIOProcListAnchor
= pListNode
;
284 /* Return this IOProc - that's how the caller knows we succeeded */
289 case MMIO_REMOVEPROC
:
291 * Search for the node that we're trying to remove
292 * We search for a matching fourCC code if it's non null, or the proc
294 * note that this method won't find the first item on the list, but
295 * since the first two items on this list are ones we won't
296 * let the user delete anyway, that's okay
298 ppListNode
= &pIOProcListAnchor
;
299 while ((*ppListNode
) &&
301 (*ppListNode
)->fourCC
!= fccIOProc
:
302 (*ppListNode
)->pIOProc
!= pIOProc
))
303 ppListNode
= &((*ppListNode
)->pNext
);
305 if (*ppListNode
) { /* found it */
306 /* FIXME: what should be done if an open mmio object uses this proc ?
307 * shall we return an error, nuke the mmio object ?
309 if ((*ppListNode
)->count
) {
310 ERR("Cannot remove a mmIOProc while in use\n");
313 /* remove it, but only if it isn't builtin */
314 if ((*ppListNode
) >= defaultProcs
&&
315 (*ppListNode
) < defaultProcs
+ sizeof(defaultProcs
) / sizeof(defaultProcs
[0])) {
316 WARN("Tried to remove built-in mmio proc. Skipping\n");
319 struct IOProcList
* ptmpNode
= *ppListNode
;
320 lpProc
= (*ppListNode
)->pIOProc
;
321 *ppListNode
= (*ppListNode
)->pNext
;
322 HeapFree(GetProcessHeap(), 0, ptmpNode
);
328 if ((pListNode
= MMIO_FindProcNode(fccIOProc
))) {
329 lpProc
= pListNode
->pIOProc
;
337 /****************************************************************
338 * send_message [INTERNAL]
340 static LRESULT
send_message(struct IOProcList
* ioProc
, LPMMIOINFO mmioinfo
,
341 DWORD wMsg
, LPARAM lParam1
,
342 LPARAM lParam2
, BOOL is_unicode
)
344 LRESULT result
= MMSYSERR_ERROR
;
345 LPARAM lp1
= lParam1
, lp2
= lParam2
;
348 ERR("ioProc NULL\n");
349 return MMSYSERR_INVALPARAM
;
352 if (ioProc
->is_unicode
!= is_unicode
) {
353 /* map (lParam1, lParam2) into (lp1, lp2) 32 A<=>W */
354 FIXME("NIY 32 A<=>W mapping\n");
356 result
= (ioProc
->pIOProc
)((LPSTR
)mmioinfo
, wMsg
, lp1
, lp2
);
359 if (ioProc
->is_unicode
!= is_unicode
) {
360 /* unmap (lParam1, lParam2) into (lp1, lp2) 32 A<=>W */
367 /**************************************************************************
368 * MMIO_ParseExtA [internal]
370 * Parses a filename for the extension.
373 * The FOURCC code for the extension if found, else 0.
375 static FOURCC
MMIO_ParseExtA(LPCSTR szFileName
)
377 /* Filenames are of the form file.ext{+ABC}
378 For now, we take the last '+' if present */
382 /* Note that ext{Start,End} point to the . and + respectively */
386 TRACE("(%s)\n", debugstr_a(szFileName
));
391 /* Find the last '.' */
392 extStart
= strrchr(szFileName
,'.');
395 ERR("No . in szFileName: %s\n", debugstr_a(szFileName
));
399 /* Find the '+' afterwards */
400 extEnd
= strchr(extStart
,'+');
403 if (extEnd
- extStart
- 1 > 4)
404 WARN("Extension length > 4\n");
405 lstrcpynA(ext
, extStart
+ 1, min(extEnd
-extStart
,5));
408 /* No + so just an extension */
409 if (strlen(extStart
) > 4) {
410 WARN("Extension length > 4\n");
412 lstrcpynA(ext
, extStart
+ 1, 5);
414 TRACE("Got extension: %s\n", debugstr_a(ext
));
416 /* FOURCC codes identifying file-extensions must be uppercase */
417 ret
= mmioStringToFOURCCA(ext
, MMIO_TOUPPER
);
422 /**************************************************************************
423 * MMIO_Get [internal]
425 * Retrieves the mmio object from current process
427 static LPWINE_MMIO
MMIO_Get(HMMIO h
)
429 LPWINE_MMIO wm
= NULL
;
431 EnterCriticalSection(&WINMM_cs
);
432 for (wm
= MMIOList
; wm
; wm
= wm
->lpNext
) {
433 if (wm
->info
.hmmio
== h
)
436 LeaveCriticalSection(&WINMM_cs
);
440 /**************************************************************************
441 * MMIO_Create [internal]
443 * Creates an internal representation for a mmio instance
445 static LPWINE_MMIO
MMIO_Create(void)
447 static WORD MMIO_counter
= 0;
450 wm
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MMIO
));
452 EnterCriticalSection(&WINMM_cs
);
453 /* lookup next unallocated WORD handle, with a non NULL value */
454 while (++MMIO_counter
== 0 || MMIO_Get((HMMIO
)(ULONG_PTR
)MMIO_counter
));
455 wm
->info
.hmmio
= (HMMIO
)(ULONG_PTR
)MMIO_counter
;
456 wm
->lpNext
= MMIOList
;
458 LeaveCriticalSection(&WINMM_cs
);
463 /**************************************************************************
464 * MMIO_Destroy [internal]
466 * Destroys an internal representation for a mmio instance
468 static BOOL
MMIO_Destroy(LPWINE_MMIO wm
)
472 EnterCriticalSection(&WINMM_cs
);
473 /* search for the matching one... */
475 while (*m
&& *m
!= wm
) m
= &(*m
)->lpNext
;
479 HeapFree(GetProcessHeap(), 0, wm
);
482 LeaveCriticalSection(&WINMM_cs
);
483 return wm
? FALSE
: TRUE
;
486 /****************************************************************
487 * MMIO_Flush [INTERNAL]
489 static MMRESULT
MMIO_Flush(WINE_MMIO
* wm
, UINT uFlags
)
491 if (wm
->info
.cchBuffer
&& (wm
->info
.fccIOProc
!= FOURCC_MEM
)) {
492 /* not quite sure what to do here, but I'll guess */
493 if (wm
->info
.dwFlags
& MMIO_DIRTY
) {
494 /* FIXME: error handling */
495 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, wm
->info
.lBufOffset
, SEEK_SET
, FALSE
);
496 send_message(wm
->ioProc
, &wm
->info
, MMIOM_WRITE
,
497 (LPARAM
)wm
->info
.pchBuffer
,
498 wm
->info
.pchNext
- wm
->info
.pchBuffer
, FALSE
);
500 if (uFlags
& MMIO_EMPTYBUF
)
501 wm
->info
.pchNext
= wm
->info
.pchEndRead
= wm
->info
.pchBuffer
;
503 wm
->info
.dwFlags
&= ~MMIO_DIRTY
;
505 return MMSYSERR_NOERROR
;
508 /***************************************************************************
509 * MMIO_GrabNextBuffer [INTERNAL]
511 static LONG
MMIO_GrabNextBuffer(LPWINE_MMIO wm
, int for_read
)
513 LONG size
= wm
->info
.cchBuffer
;
515 TRACE("bo=%x do=%x of=%lx\n",
516 wm
->info
.lBufOffset
, wm
->info
.lDiskOffset
,
517 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, 0, SEEK_CUR
, FALSE
));
519 wm
->info
.lBufOffset
= wm
->info
.lDiskOffset
;
520 wm
->info
.pchNext
= wm
->info
.pchBuffer
;
521 wm
->info
.pchEndRead
= wm
->info
.pchBuffer
;
522 wm
->info
.pchEndWrite
= wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
;
524 wm
->bBufferLoaded
= TRUE
;
526 size
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_READ
,
527 (LPARAM
)wm
->info
.pchBuffer
, size
, FALSE
);
529 wm
->info
.pchEndRead
+= size
;
531 wm
->bBufferLoaded
= FALSE
;
537 /***************************************************************************
538 * MMIO_SetBuffer [INTERNAL]
540 static MMRESULT
MMIO_SetBuffer(WINE_MMIO
* wm
, void* pchBuffer
, LONG cchBuffer
,
543 TRACE("(%p %p %d %u)\n", wm
, pchBuffer
, cchBuffer
, uFlags
);
545 if (cchBuffer
> 0xFFFF)
546 WARN("Untested handling of huge mmio buffers (%d >= 64k)\n", cchBuffer
);
548 if (MMIO_Flush(wm
, 0) != MMSYSERR_NOERROR
)
549 return MMIOERR_CANNOTWRITE
;
551 /* free previous buffer if allocated */
552 if (wm
->info
.dwFlags
& MMIO_ALLOCBUF
) {
553 HeapFree(GetProcessHeap(), 0, wm
->info
.pchBuffer
);
554 wm
->info
.pchBuffer
= NULL
;
555 wm
->info
.dwFlags
&= ~MMIO_ALLOCBUF
;
559 wm
->info
.pchBuffer
= pchBuffer
;
560 } else if (cchBuffer
) {
561 if (!(wm
->info
.pchBuffer
= HeapAlloc(GetProcessHeap(), 0, cchBuffer
)))
562 return MMIOERR_OUTOFMEMORY
;
563 wm
->info
.dwFlags
|= MMIO_ALLOCBUF
;
565 wm
->info
.pchBuffer
= NULL
;
568 wm
->info
.cchBuffer
= cchBuffer
;
569 wm
->info
.pchNext
= wm
->info
.pchBuffer
;
570 wm
->info
.pchEndRead
= wm
->info
.pchBuffer
;
571 wm
->info
.pchEndWrite
= wm
->info
.pchBuffer
+ cchBuffer
;
572 wm
->info
.lBufOffset
= wm
->info
.lDiskOffset
;
573 wm
->bBufferLoaded
= FALSE
;
575 return MMSYSERR_NOERROR
;
578 /**************************************************************************
579 * MMIO_Open [internal]
581 static HMMIO
MMIO_Open(LPSTR szFileName
, MMIOINFO
* refmminfo
, DWORD dwOpenFlags
, BOOL is_unicode
)
587 TRACE("('%s', %p, %08X, %s);\n", szFileName
, refmminfo
, dwOpenFlags
, is_unicode
? "unicode" : "ansi");
590 refmminfo
= &mmioinfo
;
592 mmioinfo
.fccIOProc
= 0;
593 mmioinfo
.pIOProc
= NULL
;
594 mmioinfo
.pchBuffer
= NULL
;
595 mmioinfo
.cchBuffer
= 0;
599 if (dwOpenFlags
& (MMIO_PARSE
|MMIO_EXIST
)) {
600 char buffer
[MAX_PATH
];
604 if (GetFullPathNameA(szFileName
, sizeof(buffer
), buffer
, NULL
) >= sizeof(buffer
))
606 if ((dwOpenFlags
& MMIO_EXIST
) && (GetFileAttributesA(buffer
) == INVALID_FILE_ATTRIBUTES
))
608 strcpy(szFileName
, buffer
);
612 if ((wm
= MMIO_Create()) == NULL
)
615 /* If both params are NULL, then parse the file name if available */
616 if (refmminfo
->fccIOProc
== 0 && refmminfo
->pIOProc
== NULL
) {
617 wm
->info
.fccIOProc
= MMIO_ParseExtA(szFileName
);
618 /* Handle any unhandled/error case. Assume DOS file */
619 if (wm
->info
.fccIOProc
== 0)
620 wm
->info
.fccIOProc
= FOURCC_DOS
;
621 if (!(wm
->ioProc
= MMIO_FindProcNode(wm
->info
.fccIOProc
))) {
622 /* If not found, retry with FOURCC_DOS */
623 wm
->info
.fccIOProc
= FOURCC_DOS
;
624 if (!(wm
->ioProc
= MMIO_FindProcNode(wm
->info
.fccIOProc
)))
627 wm
->bTmpIOProc
= FALSE
;
629 /* if just the four character code is present, look up IO proc */
630 else if (refmminfo
->pIOProc
== NULL
) {
631 wm
->info
.fccIOProc
= refmminfo
->fccIOProc
;
632 if (!(wm
->ioProc
= MMIO_FindProcNode(wm
->info
.fccIOProc
))) goto error2
;
633 wm
->bTmpIOProc
= FALSE
;
635 /* if IO proc specified, use it and specified four character code */
637 wm
->info
.fccIOProc
= refmminfo
->fccIOProc
;
638 MMIO_InstallIOProc(wm
->info
.fccIOProc
, refmminfo
->pIOProc
,
639 MMIO_INSTALLPROC
, is_unicode
);
640 if (!(wm
->ioProc
= MMIO_FindProcNode(wm
->info
.fccIOProc
))) goto error2
;
641 assert(wm
->ioProc
->pIOProc
== refmminfo
->pIOProc
);
642 wm
->bTmpIOProc
= TRUE
;
646 wm
->info
.dwFlags
= dwOpenFlags
;
648 if (dwOpenFlags
& MMIO_ALLOCBUF
) {
649 refmminfo
->wErrorRet
= MMIO_SetBuffer(wm
, refmminfo
->pchBuffer
,
650 refmminfo
->cchBuffer
? refmminfo
->cchBuffer
: MMIO_DEFAULTBUFFER
, 0);
651 if (refmminfo
->wErrorRet
!= MMSYSERR_NOERROR
)
654 refmminfo
->wErrorRet
= MMIO_SetBuffer(wm
, refmminfo
->pchBuffer
, refmminfo
->cchBuffer
, 0);
655 if (refmminfo
->wErrorRet
!= MMSYSERR_NOERROR
)
659 if (wm
->info
.fccIOProc
== FOURCC_MEM
&& !(wm
->info
.dwFlags
& MMIO_ALLOCBUF
))
660 wm
->bBufferLoaded
= TRUE
;
662 /* see mmioDosIOProc for that one */
663 wm
->info
.adwInfo
[0] = refmminfo
->adwInfo
[0];
665 /* call IO proc to actually open file */
666 refmminfo
->wErrorRet
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_OPEN
,
667 (LPARAM
)szFileName
, 0, FALSE
);
669 /* grab file size, when possible */
670 if ((pos
= _llseek((HFILE
)wm
->info
.adwInfo
[0], 0, SEEK_CUR
)) != -1)
672 wm
->dwFileSize
= _llseek((HFILE
)wm
->info
.adwInfo
[0], 0, SEEK_END
);
673 _llseek((HFILE
)wm
->info
.adwInfo
[0], pos
, SEEK_SET
);
675 else wm
->dwFileSize
= 0;
677 if (refmminfo
->wErrorRet
== 0)
678 return wm
->info
.hmmio
;
680 if (wm
->ioProc
) wm
->ioProc
->count
--;
686 /**************************************************************************
687 * mmioOpenW [WINMM.@]
689 HMMIO WINAPI
mmioOpenW(LPWSTR szFileName
, MMIOINFO
* lpmmioinfo
,
697 INT len
= WideCharToMultiByte( CP_ACP
, 0, szFileName
, -1, NULL
, 0, NULL
, NULL
);
698 szFn
= HeapAlloc( GetProcessHeap(), 0, len
);
699 if (!szFn
) return NULL
;
700 WideCharToMultiByte( CP_ACP
, 0, szFileName
, -1, szFn
, len
, NULL
, NULL
);
703 ret
= MMIO_Open(szFn
, lpmmioinfo
, dwOpenFlags
, TRUE
);
705 HeapFree(GetProcessHeap(), 0, szFn
);
709 /**************************************************************************
710 * mmioOpenA [WINMM.@]
712 HMMIO WINAPI
mmioOpenA(LPSTR szFileName
, MMIOINFO
* lpmmioinfo
,
715 return MMIO_Open(szFileName
, lpmmioinfo
, dwOpenFlags
, FALSE
);
718 /**************************************************************************
719 * mmioClose [WINMM.@]
721 MMRESULT WINAPI
mmioClose(HMMIO hmmio
, UINT uFlags
)
726 TRACE("(%p, %04X);\n", hmmio
, uFlags
);
728 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
729 return MMSYSERR_INVALHANDLE
;
731 if ((result
= MMIO_Flush(wm
, 0)) != MMSYSERR_NOERROR
)
734 result
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_CLOSE
, uFlags
, 0, FALSE
);
736 MMIO_SetBuffer(wm
, NULL
, 0, 0);
741 MMIO_InstallIOProc(wm
->info
.fccIOProc
, wm
->ioProc
->pIOProc
,
742 MMIO_REMOVEPROC
, wm
->ioProc
->is_unicode
);
749 /**************************************************************************
752 LONG WINAPI
mmioRead(HMMIO hmmio
, HPSTR pch
, LONG cch
)
757 TRACE("(%p, %p, %d);\n", hmmio
, pch
, cch
);
759 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
762 /* unbuffered case first */
763 if (!wm
->info
.pchBuffer
)
764 return send_message(wm
->ioProc
, &wm
->info
, MMIOM_READ
, (LPARAM
)pch
, cch
, FALSE
);
766 /* first try from current buffer */
767 if (wm
->info
.pchNext
!= wm
->info
.pchEndRead
) {
768 count
= wm
->info
.pchEndRead
- wm
->info
.pchNext
;
769 if (count
> cch
|| count
< 0) count
= cch
;
770 memcpy(pch
, wm
->info
.pchNext
, count
);
771 wm
->info
.pchNext
+= count
;
777 if (cch
&& (wm
->info
.fccIOProc
!= FOURCC_MEM
)) {
778 assert(wm
->info
.cchBuffer
);
783 size
= MMIO_GrabNextBuffer(wm
, TRUE
);
784 if (size
<= 0) break;
785 if (size
> cch
) size
= cch
;
786 memcpy(pch
, wm
->info
.pchBuffer
, size
);
787 wm
->info
.pchNext
+= size
;
794 TRACE("count=%d\n", count
);
798 /**************************************************************************
799 * mmioWrite [WINMM.@]
801 LONG WINAPI
mmioWrite(HMMIO hmmio
, HPCSTR pch
, LONG cch
)
806 TRACE("(%p, %p, %d);\n", hmmio
, pch
, cch
);
808 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
811 if (wm
->info
.cchBuffer
) {
816 if (wm
->info
.pchNext
!= wm
->info
.pchEndWrite
) {
817 count
= wm
->info
.pchEndWrite
- wm
->info
.pchNext
;
818 if (count
> cch
|| count
< 0) count
= cch
;
819 memcpy(wm
->info
.pchNext
, pch
, count
);
820 wm
->info
.pchNext
+= count
;
824 wm
->info
.dwFlags
|= MMIO_DIRTY
;
826 if (wm
->info
.fccIOProc
== FOURCC_MEM
) {
827 if (wm
->info
.adwInfo
[0]) {
828 /* from where would we get the memory handle? */
829 FIXME("memory file expansion not implemented!\n");
835 if (wm
->info
.pchNext
== wm
->info
.pchEndWrite
)
837 MMIO_Flush(wm
, MMIO_EMPTYBUF
);
838 MMIO_GrabNextBuffer(wm
, FALSE
);
844 count
= send_message(wm
->ioProc
, &wm
->info
, MMIOM_WRITE
, (LPARAM
)pch
, cch
, FALSE
);
845 wm
->info
.lBufOffset
= wm
->info
.lDiskOffset
;
848 TRACE("bytes written=%d\n", count
);
852 /**************************************************************************
855 LONG WINAPI
mmioSeek(HMMIO hmmio
, LONG lOffset
, INT iOrigin
)
860 TRACE("(%p, %08X, %d);\n", hmmio
, lOffset
, iOrigin
);
862 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
863 return MMSYSERR_INVALHANDLE
;
865 /* not buffered, direct seek on file */
866 if (!wm
->info
.pchBuffer
)
867 return send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, lOffset
, iOrigin
, FALSE
);
874 offset
= wm
->info
.lBufOffset
+ (wm
->info
.pchNext
- wm
->info
.pchBuffer
) + lOffset
;
877 offset
= ((wm
->info
.fccIOProc
== FOURCC_MEM
)? wm
->info
.cchBuffer
: wm
->dwFileSize
) - lOffset
;
883 if (offset
&& offset
>= wm
->dwFileSize
&& wm
->info
.fccIOProc
!= FOURCC_MEM
) {
884 /* should check that write mode exists */
885 if (MMIO_Flush(wm
, 0) != MMSYSERR_NOERROR
)
887 wm
->info
.lBufOffset
= offset
;
888 wm
->info
.pchEndRead
= wm
->info
.pchBuffer
;
889 wm
->info
.pchEndWrite
= wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
;
890 if ((wm
->info
.dwFlags
& MMIO_RWMODE
) == MMIO_READ
) {
891 wm
->info
.lDiskOffset
= wm
->dwFileSize
;
893 } else if ((wm
->info
.cchBuffer
> 0) &&
894 ((offset
< wm
->info
.lBufOffset
) ||
895 (offset
>= wm
->info
.lBufOffset
+ wm
->info
.cchBuffer
) ||
896 !wm
->bBufferLoaded
)) {
897 /* stay in same buffer ? */
898 /* some memory mapped buffers are defined with -1 as a size */
900 /* condition to change buffer */
901 if ((wm
->info
.fccIOProc
== FOURCC_MEM
) ||
902 MMIO_Flush(wm
, 0) != MMSYSERR_NOERROR
||
903 /* this also sets the wm->info.lDiskOffset field */
904 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
,
905 (offset
/ wm
->info
.cchBuffer
) * wm
->info
.cchBuffer
,
906 SEEK_SET
, FALSE
) == -1)
908 MMIO_GrabNextBuffer(wm
, TRUE
);
911 wm
->info
.pchNext
= wm
->info
.pchBuffer
+ (offset
- wm
->info
.lBufOffset
);
913 TRACE("=> %d\n", offset
);
917 /**************************************************************************
918 * mmioGetInfo [WINMM.@]
920 MMRESULT WINAPI
mmioGetInfo(HMMIO hmmio
, MMIOINFO
* lpmmioinfo
, UINT uFlags
)
924 TRACE("(%p,%p,0x%08x)\n",hmmio
,lpmmioinfo
,uFlags
);
926 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
927 return MMSYSERR_INVALHANDLE
;
929 *lpmmioinfo
= wm
->info
;
931 return MMSYSERR_NOERROR
;
934 /**************************************************************************
935 * mmioSetInfo [WINMM.@]
937 MMRESULT WINAPI
mmioSetInfo(HMMIO hmmio
, const MMIOINFO
* lpmmioinfo
, UINT uFlags
)
941 TRACE("(%p,%p,0x%08x)\n",hmmio
,lpmmioinfo
,uFlags
);
943 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
944 return MMSYSERR_INVALHANDLE
;
946 /* check pointers coherence */
947 if (lpmmioinfo
->pchNext
< wm
->info
.pchBuffer
||
948 lpmmioinfo
->pchNext
> wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
||
949 lpmmioinfo
->pchEndRead
< wm
->info
.pchBuffer
||
950 lpmmioinfo
->pchEndRead
> wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
||
951 lpmmioinfo
->pchEndWrite
< wm
->info
.pchBuffer
||
952 lpmmioinfo
->pchEndWrite
> wm
->info
.pchBuffer
+ wm
->info
.cchBuffer
)
953 return MMSYSERR_INVALPARAM
;
955 wm
->info
.pchNext
= lpmmioinfo
->pchNext
;
956 wm
->info
.pchEndRead
= lpmmioinfo
->pchEndRead
;
958 return MMSYSERR_NOERROR
;
961 /**************************************************************************
962 * mmioSetBuffer [WINMM.@]
964 MMRESULT WINAPI
mmioSetBuffer(HMMIO hmmio
, LPSTR pchBuffer
, LONG cchBuffer
, UINT uFlags
)
968 TRACE("(hmmio=%p, pchBuf=%p, cchBuf=%d, uFlags=%#08x)\n",
969 hmmio
, pchBuffer
, cchBuffer
, uFlags
);
971 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
972 return MMSYSERR_INVALHANDLE
;
974 return MMIO_SetBuffer(wm
, pchBuffer
, cchBuffer
, uFlags
);
977 /**************************************************************************
978 * mmioFlush [WINMM.@]
980 MMRESULT WINAPI
mmioFlush(HMMIO hmmio
, UINT uFlags
)
984 TRACE("(%p, %04X)\n", hmmio
, uFlags
);
986 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
987 return MMSYSERR_INVALHANDLE
;
989 return MMIO_Flush(wm
, uFlags
);
992 /**************************************************************************
993 * mmioAdvance [WINMM.@]
995 MMRESULT WINAPI
mmioAdvance(HMMIO hmmio
, MMIOINFO
* lpmmioinfo
, UINT uFlags
)
999 TRACE("hmmio=%p, lpmmioinfo=%p, uFlags=%04X\n", hmmio
, lpmmioinfo
, uFlags
);
1001 /* NOTE: mmioAdvance16 heavily relies on parameters from lpmmioinfo we're using
1002 * here. be sure if you change something here to check mmioAdvance16 as well
1004 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
1005 return MMSYSERR_INVALHANDLE
;
1007 if (!wm
->info
.cchBuffer
)
1008 return MMIOERR_UNBUFFERED
;
1010 if (uFlags
!= MMIO_READ
&& uFlags
!= MMIO_WRITE
)
1011 return MMSYSERR_INVALPARAM
;
1013 if (uFlags
== MMIO_WRITE
&& (lpmmioinfo
->dwFlags
& MMIO_DIRTY
))
1015 send_message(wm
->ioProc
, &wm
->info
, MMIOM_SEEK
, lpmmioinfo
->lBufOffset
, SEEK_SET
, FALSE
);
1016 send_message(wm
->ioProc
, &wm
->info
, MMIOM_WRITE
, (LPARAM
)lpmmioinfo
->pchBuffer
,
1017 lpmmioinfo
->pchNext
- lpmmioinfo
->pchBuffer
, FALSE
);
1018 lpmmioinfo
->dwFlags
&= ~MMIO_DIRTY
;
1020 if (MMIO_Flush(wm
, 0) != MMSYSERR_NOERROR
)
1021 return MMIOERR_CANNOTWRITE
;
1024 wm
->dwFileSize
= max(wm
->dwFileSize
, lpmmioinfo
->lBufOffset
+
1025 (lpmmioinfo
->pchNext
- lpmmioinfo
->pchBuffer
));
1027 MMIO_GrabNextBuffer(wm
, uFlags
== MMIO_READ
);
1030 lpmmioinfo
->pchNext
= lpmmioinfo
->pchBuffer
;
1031 lpmmioinfo
->pchEndRead
= lpmmioinfo
->pchBuffer
+
1032 (wm
->info
.pchEndRead
- wm
->info
.pchBuffer
);
1033 lpmmioinfo
->pchEndWrite
= lpmmioinfo
->pchBuffer
+
1034 (wm
->info
.pchEndWrite
- wm
->info
.pchBuffer
);
1035 lpmmioinfo
->lDiskOffset
= wm
->info
.lDiskOffset
;
1036 lpmmioinfo
->lBufOffset
= wm
->info
.lBufOffset
;
1038 return MMSYSERR_NOERROR
;
1041 /**************************************************************************
1042 * mmioStringToFOURCCA [WINMM.@]
1044 FOURCC WINAPI
mmioStringToFOURCCA(LPCSTR sz
, UINT uFlags
)
1049 for (i
= 0; i
< 4 && sz
[i
]; i
++) {
1050 if (uFlags
& MMIO_TOUPPER
) {
1051 cc
[i
] = toupper(sz
[i
]);
1057 /* Pad with spaces */
1058 while (i
< 4) cc
[i
++] = ' ';
1060 TRACE("Got '%.4s'\n",cc
);
1061 return mmioFOURCC(cc
[0],cc
[1],cc
[2],cc
[3]);
1064 /**************************************************************************
1065 * mmioStringToFOURCCW [WINMM.@]
1067 FOURCC WINAPI
mmioStringToFOURCCW(LPCWSTR sz
, UINT uFlags
)
1071 WideCharToMultiByte( CP_ACP
, 0, sz
, 4, szA
, sizeof(szA
), NULL
, NULL
);
1072 return mmioStringToFOURCCA(szA
,uFlags
);
1075 /**************************************************************************
1076 * mmioInstallIOProcA [WINMM.@]
1078 LPMMIOPROC WINAPI
mmioInstallIOProcA(FOURCC fccIOProc
,
1079 LPMMIOPROC pIOProc
, DWORD dwFlags
)
1081 return MMIO_InstallIOProc(fccIOProc
, pIOProc
, dwFlags
, FALSE
);
1084 /**************************************************************************
1085 * mmioInstallIOProcW [WINMM.@]
1087 LPMMIOPROC WINAPI
mmioInstallIOProcW(FOURCC fccIOProc
,
1088 LPMMIOPROC pIOProc
, DWORD dwFlags
)
1090 return MMIO_InstallIOProc(fccIOProc
, pIOProc
, dwFlags
, TRUE
);
1093 /******************************************************************
1098 static LRESULT
MMIO_SendMessage(HMMIO hmmio
, UINT uMessage
, LPARAM lParam1
,
1099 LPARAM lParam2
, BOOL is_unicode
)
1103 TRACE("(%p, %u, %ld, %ld, %s)\n", hmmio
, uMessage
, lParam1
, lParam2
, is_unicode
? "unicode" : "ansi");
1105 if (uMessage
< MMIOM_USER
)
1106 return MMSYSERR_INVALPARAM
;
1108 if ((wm
= MMIO_Get(hmmio
)) == NULL
)
1109 return MMSYSERR_INVALHANDLE
;
1111 return send_message(wm
->ioProc
, &wm
->info
, uMessage
, lParam1
, lParam2
, is_unicode
);
1114 /**************************************************************************
1115 * mmioSendMessage [WINMM.@]
1117 LRESULT WINAPI
mmioSendMessage(HMMIO hmmio
, UINT uMessage
,
1118 LPARAM lParam1
, LPARAM lParam2
)
1120 return MMIO_SendMessage(hmmio
, uMessage
, lParam1
, lParam2
, FALSE
);
1123 /**************************************************************************
1124 * mmioDescend [WINMM.@]
1126 MMRESULT WINAPI
mmioDescend(HMMIO hmmio
, LPMMCKINFO lpck
,
1127 const MMCKINFO
* lpckParent
, UINT uFlags
)
1133 TRACE("(%p, %p, %p, %04X);\n", hmmio
, lpck
, lpckParent
, uFlags
);
1136 return MMSYSERR_INVALPARAM
;
1138 dwOldPos
= mmioSeek(hmmio
, 0, SEEK_CUR
);
1139 TRACE("dwOldPos=%d\n", dwOldPos
);
1141 if (lpckParent
!= NULL
) {
1142 TRACE("seek inside parent at %d !\n", lpckParent
->dwDataOffset
);
1143 /* EPP: was dwOldPos = mmioSeek(hmmio,lpckParent->dwDataOffset,SEEK_SET); */
1144 if (dwOldPos
< lpckParent
->dwDataOffset
||
1145 dwOldPos
>= lpckParent
->dwDataOffset
+ lpckParent
->cksize
) {
1146 WARN("outside parent chunk\n");
1147 return MMIOERR_CHUNKNOTFOUND
;
1151 /* The SDK docu says 'ckid' is used for all cases. Real World
1152 * examples disagree -Marcus,990216.
1158 /* find_chunk looks for 'ckid' */
1159 if (uFlags
& MMIO_FINDCHUNK
)
1160 srchCkId
= lpck
->ckid
;
1162 /* find_riff and find_list look for 'fccType' */
1163 if (uFlags
& MMIO_FINDLIST
)
1165 srchCkId
= FOURCC_LIST
;
1166 srchType
= lpck
->fccType
;
1169 if (uFlags
& MMIO_FINDRIFF
)
1171 srchCkId
= FOURCC_RIFF
;
1172 srchType
= lpck
->fccType
;
1175 TRACE("searching for %4.4s.%4.4s\n",
1176 (LPCSTR
)&srchCkId
, srchType
? (LPCSTR
)&srchType
: "any");
1182 ix
= mmioRead(hmmio
, (LPSTR
)lpck
, 3 * sizeof(DWORD
));
1183 if (ix
< 2*sizeof(DWORD
))
1185 mmioSeek(hmmio
, dwOldPos
, SEEK_SET
);
1186 WARN("return ChunkNotFound\n");
1187 return MMIOERR_CHUNKNOTFOUND
;
1190 lpck
->dwDataOffset
= dwOldPos
+ 2 * sizeof(DWORD
);
1191 TRACE("ckid=%4.4s fcc=%4.4s cksize=%08X !\n",
1192 (LPCSTR
)&lpck
->ckid
,
1193 srchType
? (LPCSTR
)&lpck
->fccType
:"<na>",
1195 if ( (!srchCkId
|| (srchCkId
== lpck
->ckid
)) &&
1196 (!srchType
|| (srchType
== lpck
->fccType
)) )
1199 dwOldPos
= lpck
->dwDataOffset
+ ((lpck
->cksize
+ 1) & ~1);
1200 mmioSeek(hmmio
, dwOldPos
, SEEK_SET
);
1204 /* If we were looking for RIFF/LIST chunks, the final file position
1205 * is after the chunkid. If we were just looking for the chunk
1206 * it is after the cksize. So add 4 in RIFF/LIST case.
1208 if (lpck
->ckid
== FOURCC_RIFF
|| lpck
->ckid
== FOURCC_LIST
)
1209 mmioSeek(hmmio
, lpck
->dwDataOffset
+ sizeof(DWORD
), SEEK_SET
);
1212 mmioSeek(hmmio
, lpck
->dwDataOffset
, SEEK_SET
);
1215 TRACE("lpck: ckid=%.4s, cksize=%d, dwDataOffset=%d fccType=%08X (%.4s)!\n",
1216 (LPSTR
)&lpck
->ckid
, lpck
->cksize
, lpck
->dwDataOffset
,
1217 lpck
->fccType
, srchType
?(LPSTR
)&lpck
->fccType
:"");
1218 return MMSYSERR_NOERROR
;
1221 /**************************************************************************
1222 * mmioAscend [WINMM.@]
1224 MMRESULT WINAPI
mmioAscend(HMMIO hmmio
, LPMMCKINFO lpck
, UINT uFlags
)
1226 TRACE("(%p, %p, %04X);\n", hmmio
, lpck
, uFlags
);
1228 if (lpck
->dwFlags
& MMIO_DIRTY
) {
1229 DWORD dwOldPos
, dwNewSize
;
1231 TRACE("Chunk is dirty, checking if chunk's size is correct\n");
1232 dwOldPos
= mmioSeek(hmmio
, 0, SEEK_CUR
);
1233 TRACE("dwOldPos=%d lpck->dwDataOffset = %d\n", dwOldPos
, lpck
->dwDataOffset
);
1234 dwNewSize
= dwOldPos
- lpck
->dwDataOffset
;
1235 if (dwNewSize
!= lpck
->cksize
) {
1236 TRACE("Nope: lpck->cksize=%d dwNewSize=%d\n", lpck
->cksize
, dwNewSize
);
1237 lpck
->cksize
= dwNewSize
;
1239 /* pad odd size with 0 */
1240 if (dwNewSize
& 1) {
1242 mmioWrite(hmmio
, &ch
, 1);
1244 mmioSeek(hmmio
, lpck
->dwDataOffset
- sizeof(DWORD
), SEEK_SET
);
1245 mmioWrite(hmmio
, (LPSTR
)&dwNewSize
, sizeof(DWORD
));
1250 mmioSeek(hmmio
, lpck
->dwDataOffset
+ ((lpck
->cksize
+ 1) & ~1), SEEK_SET
);
1252 return MMSYSERR_NOERROR
;
1255 /**************************************************************************
1256 * mmioCreateChunk [WINMM.@]
1258 MMRESULT WINAPI
mmioCreateChunk(HMMIO hmmio
, MMCKINFO
* lpck
, UINT uFlags
)
1264 TRACE("(%p, %p, %04X);\n", hmmio
, lpck
, uFlags
);
1266 dwOldPos
= mmioSeek(hmmio
, 0, SEEK_CUR
);
1267 TRACE("dwOldPos=%d\n", dwOldPos
);
1269 if (uFlags
== MMIO_CREATELIST
)
1270 lpck
->ckid
= FOURCC_LIST
;
1271 else if (uFlags
== MMIO_CREATERIFF
)
1272 lpck
->ckid
= FOURCC_RIFF
;
1274 TRACE("ckid=%.4s\n", (LPSTR
)&lpck
->ckid
);
1276 size
= 2 * sizeof(DWORD
);
1277 lpck
->dwDataOffset
= dwOldPos
+ size
;
1279 if (lpck
->ckid
== FOURCC_RIFF
|| lpck
->ckid
== FOURCC_LIST
)
1280 size
+= sizeof(DWORD
);
1281 lpck
->dwFlags
= MMIO_DIRTY
;
1283 ix
= mmioWrite(hmmio
, (LPSTR
)lpck
, size
);
1284 TRACE("after mmioWrite ix = %d req = %d, errno = %d\n", ix
, size
, errno
);
1286 mmioSeek(hmmio
, dwOldPos
, SEEK_SET
);
1287 WARN("return CannotWrite\n");
1288 return MMIOERR_CANNOTWRITE
;
1291 return MMSYSERR_NOERROR
;
1294 /**************************************************************************
1295 * mmioRenameA [WINMM.@]
1297 MMRESULT WINAPI
mmioRenameA(LPCSTR szFileName
, LPCSTR szNewFileName
,
1298 const MMIOINFO
* lpmmioinfo
, DWORD dwFlags
)
1300 struct IOProcList
* ioProc
= NULL
;
1301 struct IOProcList tmp
;
1304 TRACE("('%s', '%s', %p, %08X);\n",
1305 debugstr_a(szFileName
), debugstr_a(szNewFileName
), lpmmioinfo
, dwFlags
);
1307 /* If both params are NULL, then parse the file name */
1308 if (lpmmioinfo
&& lpmmioinfo
->fccIOProc
== 0 && lpmmioinfo
->pIOProc
== NULL
)
1310 fcc
= MMIO_ParseExtA(szFileName
);
1311 if (fcc
) ioProc
= MMIO_FindProcNode(fcc
);
1314 /* Handle any unhandled/error case from above. Assume DOS file */
1315 if (!lpmmioinfo
|| (lpmmioinfo
->fccIOProc
== 0 && lpmmioinfo
->pIOProc
== NULL
&& ioProc
== NULL
))
1316 ioProc
= MMIO_FindProcNode(FOURCC_DOS
);
1317 /* if just the four character code is present, look up IO proc */
1318 else if (lpmmioinfo
->pIOProc
== NULL
)
1319 ioProc
= MMIO_FindProcNode(lpmmioinfo
->fccIOProc
);
1320 else /* use relevant ioProc */
1323 tmp
.fourCC
= lpmmioinfo
->fccIOProc
;
1324 tmp
.pIOProc
= lpmmioinfo
->pIOProc
;
1325 tmp
.is_unicode
= FALSE
;
1329 /* FIXME: should we actually pass lpmmioinfo down the drain ???
1330 * or make a copy of it because it's const ???
1332 return send_message(ioProc
, (MMIOINFO
*)lpmmioinfo
, MMIOM_RENAME
,
1333 (LPARAM
)szFileName
, (LPARAM
)szNewFileName
, FALSE
);
1336 /**************************************************************************
1337 * mmioRenameW [WINMM.@]
1339 MMRESULT WINAPI
mmioRenameW(LPCWSTR szFileName
, LPCWSTR szNewFileName
,
1340 const MMIOINFO
* lpmmioinfo
, DWORD dwFlags
)
1344 UINT ret
= MMSYSERR_NOMEM
;
1349 len
= WideCharToMultiByte( CP_ACP
, 0, szFileName
, -1, NULL
, 0, NULL
, NULL
);
1350 szFn
= HeapAlloc( GetProcessHeap(), 0, len
);
1351 if (!szFn
) goto done
;
1352 WideCharToMultiByte( CP_ACP
, 0, szFileName
, -1, szFn
, len
, NULL
, NULL
);
1356 len
= WideCharToMultiByte( CP_ACP
, 0, szNewFileName
, -1, NULL
, 0, NULL
, NULL
);
1357 sznFn
= HeapAlloc( GetProcessHeap(), 0, len
);
1358 if (!sznFn
) goto done
;
1359 WideCharToMultiByte( CP_ACP
, 0, szNewFileName
, -1, sznFn
, len
, NULL
, NULL
);
1362 ret
= mmioRenameA(szFn
, sznFn
, lpmmioinfo
, dwFlags
);
1365 HeapFree(GetProcessHeap(),0,szFn
);
1366 HeapFree(GetProcessHeap(),0,sznFn
);