- Convert HDRVR to a void*.
[wine/multimedia.git] / dlls / commdlg / filetitle.c
blob6c55e5eebc81bb50c2af0dce36c905d173285f6f
1 /*
2 * COMMDLG - File Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <string.h>
24 #include "winbase.h"
25 #include "winnls.h"
26 #include "commdlg.h"
27 #include "wine/debug.h"
29 #include "heap.h" /* Has to go */
31 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
33 #include "cdlg.h"
35 /***********************************************************************
36 * GetFileTitleA (COMDLG32.@)
39 short WINAPI GetFileTitleA(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
41 int i, len;
43 TRACE("(%p %p %d); \n", lpFile, lpTitle, cbBuf);
45 if(lpFile == NULL || lpTitle == NULL)
46 return -1;
48 len = strlen(lpFile);
50 if (len == 0)
51 return -1;
53 if(strpbrk(lpFile, "*[]"))
54 return -1;
56 len--;
58 if(lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
59 return -1;
61 for(i = len; i >= 0; i--)
63 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
65 i++;
66 break;
70 if(i == -1)
71 i++;
73 TRACE("---> '%s' \n", &lpFile[i]);
75 len = strlen(lpFile+i)+1;
76 if(cbBuf < len)
77 return len;
79 strncpy(lpTitle, &lpFile[i], len);
80 return 0;
84 /***********************************************************************
85 * GetFileTitleW (COMDLG32.@)
88 short WINAPI GetFileTitleW(LPCWSTR lpFile, LPWSTR lpTitle, UINT cbBuf)
90 LPSTR file = HEAP_strdupWtoA(GetProcessHeap(), 0, lpFile); /* Has to go */
91 LPSTR title = HeapAlloc(GetProcessHeap(), 0, cbBuf);
92 short ret;
94 ret = GetFileTitleA(file, title, cbBuf);
96 if (cbBuf > 0 && !MultiByteToWideChar( CP_ACP, 0, title, -1, lpTitle, cbBuf ))
97 lpTitle[cbBuf-1] = 0;
98 HeapFree(GetProcessHeap(), 0, file);
99 HeapFree(GetProcessHeap(), 0, title);
100 return ret;
104 /***********************************************************************
105 * GetFileTitle (COMMDLG.27)
107 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
109 return GetFileTitleA(lpFile, lpTitle, cbBuf);