[TAPI32]
[reactos.git] / reactos / 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 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 #include <config.h>
27 //#include "wine/port.h"
28
29 //#include <stdarg.h>
30 #include <stdio.h>
31 #include <windef.h>
32 #include <winbase.h>
33 //#include "wingdi.h"
34 #include <winreg.h>
35 #include <objbase.h>
36 #include <tapi.h>
37 #include <wine/unicode.h>
38 #include <wine/debug.h>
39
40 WINE_DEFAULT_DEBUG_CHANNEL(tapi);
41
42 /***********************************************************************
43 * tapiGetLocationInfoW (TAPI32.@)
44 */
45 DWORD WINAPI tapiGetLocationInfoW(LPWSTR countrycode, LPWSTR citycode)
46 {
47 HKEY hkey, hsubkey;
48 DWORD currid;
49 DWORD valsize;
50 DWORD type;
51 DWORD bufsize;
52 BYTE buf[200];
53 WCHAR szlockey[20];
54
55 static const WCHAR currentidW[] = {'C','u','r','r','e','n','t','I','D',0};
56 static const WCHAR locationW[] = {'L','o','c','a','t','i','o','n','%','u',0};
57 static const WCHAR areacodeW[] = {'A','r','e','a','C','o','d','e',0};
58 static const WCHAR countryW[] = {'C','o','u','n','t','r','y',0};
59 static const WCHAR fmtW[] = {'%','u',0};
60
61 static const WCHAR locations_keyW[] =
62 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
63 'W','i','n','d','o','w','s','\\',
64 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
65 'T','e','l','e','p','h','o','n','y','\\','L','o','c','a','t','i','o','n','s',0};
66
67 if(!RegOpenKeyW(HKEY_LOCAL_MACHINE, locations_keyW, &hkey) != ERROR_SUCCESS) {
68 valsize = sizeof( DWORD);
69 if(!RegQueryValueExW(hkey, currentidW, 0, &type, (LPBYTE) &currid, &valsize) &&
70 type == REG_DWORD) {
71 /* find a subkey called Location1, Location2... */
72 sprintfW( szlockey, locationW, currid);
73 if( !RegOpenKeyW( hkey, szlockey, &hsubkey)) {
74 if( citycode) {
75 bufsize=sizeof(buf);
76 if( !RegQueryValueExW( hsubkey, areacodeW, 0, &type, buf, &bufsize) &&
77 type == REG_SZ) {
78 lstrcpynW( citycode, (WCHAR *) buf, 8);
79 } else
80 citycode[0] = '\0';
81 }
82 if( countrycode) {
83 bufsize=sizeof(buf);
84 if( !RegQueryValueExW( hsubkey, countryW, 0, &type, buf, &bufsize) &&
85 type == REG_DWORD)
86 snprintfW( countrycode, 8, fmtW, *(LPDWORD) buf );
87 else
88 countrycode[0] = '\0';
89 }
90 TRACE("(%p \"%s\", %p \"%s\"): success.\n", countrycode, debugstr_w(countrycode),
91 citycode, debugstr_w(citycode));
92 RegCloseKey( hkey);
93 RegCloseKey( hsubkey);
94 return 0; /* SUCCESS */
95 }
96 }
97 RegCloseKey( hkey);
98 }
99 WARN("(%p, %p): failed (no telephony registry entries?).\n", countrycode, citycode);
100 return TAPIERR_REQUESTFAILED;
101 }
102
103
104 /***********************************************************************
105 * tapiGetLocationInfoA (TAPI32.@)
106 */
107 DWORD WINAPI tapiGetLocationInfoA(LPSTR countrycode, LPSTR citycode)
108 {
109 DWORD ret, len;
110 LPWSTR country, city;
111
112 len = MultiByteToWideChar( CP_ACP, 0, countrycode, -1, NULL, 0 );
113 country = HeapAlloc( GetProcessHeap(), 0, len );
114 MultiByteToWideChar( CP_ACP, 0, countrycode, -1, country, len );
115
116 len = MultiByteToWideChar( CP_ACP, 0, citycode, -1, NULL, 0 );
117 city = HeapAlloc( GetProcessHeap(), 0, len );
118 MultiByteToWideChar( CP_ACP, 0, citycode, -1, city, len );
119
120 ret = tapiGetLocationInfoW(country, city);
121
122 HeapFree( GetProcessHeap(), 0, city );
123 HeapFree( GetProcessHeap(), 0, country );
124 return ret;
125 }
126
127 /***********************************************************************
128 * tapiRequestMakeCall (TAPI32.@)
129 */
130 DWORD WINAPI tapiRequestMakeCallA(LPCSTR lpszDestAddress, LPCSTR lpszAppName,
131 LPCSTR lpszCalledParty, LPCSTR lpszComment)
132 {
133 FIXME("(%s, %s, %s, %s): stub.\n", lpszDestAddress, lpszAppName, lpszCalledParty, lpszComment);
134 return 0;
135 }