* Sync up to trunk HEAD (r62502).
[reactos.git] / dll / win32 / tapi32 / assisted.c
1 /*
2 * TAPI32 Assisted Telephony
3 *
4 * Copyright 1999 Andreas Mohr
5 * Copyright 2011 André Hentschel
6 *
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.
11 *
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.
16 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "precomp.h"
23
24 /***********************************************************************
25 * tapiGetLocationInfoW (TAPI32.@)
26 */
27 DWORD WINAPI tapiGetLocationInfoW(LPWSTR countrycode, LPWSTR citycode)
28 {
29 HKEY hkey, hsubkey;
30 DWORD currid;
31 DWORD valsize;
32 DWORD type;
33 DWORD bufsize;
34 BYTE buf[200];
35 WCHAR szlockey[20];
36
37 static const WCHAR currentidW[] = {'C','u','r','r','e','n','t','I','D',0};
38 static const WCHAR locationW[] = {'L','o','c','a','t','i','o','n','%','u',0};
39 static const WCHAR areacodeW[] = {'A','r','e','a','C','o','d','e',0};
40 static const WCHAR countryW[] = {'C','o','u','n','t','r','y',0};
41 static const WCHAR fmtW[] = {'%','u',0};
42
43 static const WCHAR locations_keyW[] =
44 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
45 'W','i','n','d','o','w','s','\\',
46 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
47 'T','e','l','e','p','h','o','n','y','\\','L','o','c','a','t','i','o','n','s',0};
48
49 if(!RegOpenKeyW(HKEY_LOCAL_MACHINE, locations_keyW, &hkey) != ERROR_SUCCESS) {
50 valsize = sizeof( DWORD);
51 if(!RegQueryValueExW(hkey, currentidW, 0, &type, (LPBYTE) &currid, &valsize) &&
52 type == REG_DWORD) {
53 /* find a subkey called Location1, Location2... */
54 sprintfW( szlockey, locationW, currid);
55 if( !RegOpenKeyW( hkey, szlockey, &hsubkey)) {
56 if( citycode) {
57 bufsize=sizeof(buf);
58 if( !RegQueryValueExW( hsubkey, areacodeW, 0, &type, buf, &bufsize) &&
59 type == REG_SZ) {
60 lstrcpynW( citycode, (WCHAR *) buf, 8);
61 } else
62 citycode[0] = '\0';
63 }
64 if( countrycode) {
65 bufsize=sizeof(buf);
66 if( !RegQueryValueExW( hsubkey, countryW, 0, &type, buf, &bufsize) &&
67 type == REG_DWORD)
68 snprintfW( countrycode, 8, fmtW, *(LPDWORD) buf );
69 else
70 countrycode[0] = '\0';
71 }
72 TRACE("(%p \"%s\", %p \"%s\"): success.\n", countrycode, debugstr_w(countrycode),
73 citycode, debugstr_w(citycode));
74 RegCloseKey( hkey);
75 RegCloseKey( hsubkey);
76 return 0; /* SUCCESS */
77 }
78 }
79 RegCloseKey( hkey);
80 }
81 WARN("(%p, %p): failed (no telephony registry entries?).\n", countrycode, citycode);
82 return TAPIERR_REQUESTFAILED;
83 }
84
85
86 /***********************************************************************
87 * tapiGetLocationInfoA (TAPI32.@)
88 */
89 DWORD WINAPI tapiGetLocationInfoA(LPSTR countrycode, LPSTR citycode)
90 {
91 DWORD ret, len;
92 LPWSTR country, city;
93
94 len = MultiByteToWideChar( CP_ACP, 0, countrycode, -1, NULL, 0 );
95 country = HeapAlloc( GetProcessHeap(), 0, len );
96 MultiByteToWideChar( CP_ACP, 0, countrycode, -1, country, len );
97
98 len = MultiByteToWideChar( CP_ACP, 0, citycode, -1, NULL, 0 );
99 city = HeapAlloc( GetProcessHeap(), 0, len );
100 MultiByteToWideChar( CP_ACP, 0, citycode, -1, city, len );
101
102 ret = tapiGetLocationInfoW(country, city);
103
104 HeapFree( GetProcessHeap(), 0, city );
105 HeapFree( GetProcessHeap(), 0, country );
106 return ret;
107 }
108
109 /***********************************************************************
110 * tapiRequestMakeCall (TAPI32.@)
111 */
112 DWORD WINAPI tapiRequestMakeCallA(LPCSTR lpszDestAddress, LPCSTR lpszAppName,
113 LPCSTR lpszCalledParty, LPCSTR lpszComment)
114 {
115 FIXME("(%s, %s, %s, %s): stub.\n", lpszDestAddress, lpszAppName, lpszCalledParty, lpszComment);
116 return 0;
117 }