Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
7.0 KiB

  1. // autoans.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "t3test.h"
  5. #include "t3testd.h"
  6. #include "confdlg.h"
  7. #include "strings.h"
  8. #include "resource.h"
  9. #ifdef _DEBUG
  10. #ifndef _WIN64 // mfc 4.2's heap debugging features generate warnings on win64
  11. #define new DEBUG_NEW
  12. #endif
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. CConfDlg::CConfDlg(CWnd* pParent /*=NULL*/)
  17. : CDialog(CConfDlg::IDD, pParent)
  18. {
  19. m_bstrDestAddress = NULL;
  20. }
  21. void CConfDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. }
  25. BOOL CConfDlg::OnInitDialog()
  26. {
  27. CDialog::OnInitDialog();
  28. PopulateConferences();
  29. return TRUE;
  30. }
  31. void CConfDlg::PopulateConferences()
  32. {
  33. ITRendezvous * pRend;
  34. IEnumDirectory * pEnumDirectory;
  35. HRESULT hr;
  36. ITDirectory * pDirectory;
  37. LPWSTR * ppServers;
  38. DWORD dw;
  39. //
  40. // create the rendezvous control.
  41. //
  42. hr = ::CoCreateInstance(
  43. CLSID_Rendezvous,
  44. NULL,
  45. CLSCTX_INPROC_SERVER,
  46. IID_ITRendezvous,
  47. (void **)&pRend
  48. );
  49. if (FAILED(hr))
  50. {
  51. return;
  52. }
  53. hr = pRend->EnumerateDefaultDirectories(
  54. &pEnumDirectory
  55. );
  56. if (FAILED(hr))
  57. {
  58. pRend->Release();
  59. return;
  60. }
  61. while (TRUE)
  62. {
  63. DWORD dwFetched = 0;
  64. hr = pEnumDirectory->Next(
  65. 1,
  66. &pDirectory,
  67. &dwFetched
  68. );
  69. if ( S_OK != hr )
  70. {
  71. break;
  72. }
  73. DIRECTORY_TYPE type;
  74. // print out the names of the conference found.
  75. hr = pDirectory->get_DirectoryType(&type);
  76. if ( FAILED(hr) )
  77. {
  78. pDirectory->Release();
  79. continue;
  80. }
  81. if (type == DT_ILS)
  82. {
  83. break;
  84. }
  85. pDirectory->Release();
  86. }
  87. pEnumDirectory->Release();
  88. //
  89. // if hr is s_false, we went through the enumerate
  90. // without finding an ils server
  91. //
  92. if ( S_OK == hr )
  93. {
  94. hr = pDirectory->Connect(FALSE);
  95. if ( SUCCEEDED(hr))
  96. {
  97. ListObjects( pDirectory );
  98. }
  99. pDirectory->Release();
  100. }
  101. hr = ListILSServers(
  102. &ppServers,
  103. &dw
  104. );
  105. if ( !SUCCEEDED(hr) )
  106. {
  107. return;
  108. }
  109. while ( dw )
  110. {
  111. dw--;
  112. hr = pRend->CreateDirectory(
  113. DT_ILS,
  114. ppServers[dw],
  115. &pDirectory
  116. );
  117. if ( SUCCEEDED(hr) )
  118. {
  119. hr = pDirectory->Connect(FALSE);
  120. if ( SUCCEEDED(hr) )
  121. {
  122. ListObjects( pDirectory );
  123. }
  124. pDirectory->Release();
  125. }
  126. CoTaskMemFree( ppServers[dw] );
  127. }
  128. CoTaskMemFree( ppServers );
  129. }
  130. void
  131. CConfDlg::ListObjects( ITDirectory * pDirectory )
  132. {
  133. BSTR bstrNameToSearch;
  134. BSTR bstrDirName;
  135. HRESULT hr;
  136. int i;
  137. bstrNameToSearch = SysAllocString(L"*");
  138. if (bstrNameToSearch == NULL)
  139. {
  140. return;
  141. }
  142. IEnumDirectoryObject * pEnum;
  143. hr = pDirectory->EnumerateDirectoryObjects(
  144. OT_CONFERENCE,
  145. bstrNameToSearch,
  146. &pEnum
  147. );
  148. SysFreeString( bstrNameToSearch );
  149. if (FAILED(hr))
  150. {
  151. return;
  152. }
  153. pDirectory->get_DisplayName( &bstrDirName );
  154. // print out the names of all the users found.
  155. while (TRUE)
  156. {
  157. ITDirectoryObject * pObject;
  158. BSTR bstrObjectName;
  159. WCHAR szBuffer[256];
  160. hr = pEnum->Next(
  161. 1,
  162. &pObject,
  163. NULL
  164. );
  165. if ( S_OK != hr )
  166. {
  167. break;
  168. }
  169. hr = pObject->get_Name(&bstrObjectName);
  170. if (FAILED(hr))
  171. {
  172. continue;
  173. }
  174. wsprintf(szBuffer, L"%s: %s", bstrDirName, bstrObjectName );
  175. i = SendDlgItemMessage(
  176. IDC_CONFLIST,
  177. LB_ADDSTRING,
  178. 0,
  179. (LPARAM)szBuffer
  180. );
  181. SysFreeString(bstrObjectName);
  182. SendDlgItemMessage(
  183. IDC_CONFLIST,
  184. LB_SETITEMDATA,
  185. i,
  186. (LPARAM) pObject
  187. );
  188. }
  189. SysFreeString( bstrDirName );
  190. pEnum->Release();
  191. }
  192. void CConfDlg::OnOK()
  193. {
  194. DWORD i;
  195. HRESULT hr;
  196. i = SendDlgItemMessage(
  197. IDC_CONFLIST,
  198. LB_GETCURSEL,
  199. 0,
  200. 0
  201. );
  202. if (LB_ERR != i)
  203. {
  204. ITDirectoryObject * pObject;
  205. IEnumDialableAddrs * pEnumAddress;
  206. pObject = (ITDirectoryObject *)SendDlgItemMessage(
  207. IDC_CONFLIST,
  208. LB_GETITEMDATA,
  209. i,
  210. 0
  211. );
  212. hr = pObject->EnumerateDialableAddrs(
  213. LINEADDRESSTYPE_SDP,
  214. &pEnumAddress
  215. );
  216. if ( !SUCCEEDED(hr) )
  217. {
  218. }
  219. hr = pEnumAddress->Next(
  220. 1,
  221. &m_bstrDestAddress,
  222. NULL
  223. );
  224. if ( S_OK != hr )
  225. {
  226. }
  227. pEnumAddress->Release();
  228. }
  229. CDialog::OnOK();
  230. }
  231. void CConfDlg::OnDestroy()
  232. {
  233. DWORD count;
  234. CDialog::OnDestroy();
  235. count = SendDlgItemMessage(
  236. IDC_CONFLIST,
  237. LB_GETCOUNT,
  238. 0,
  239. 0
  240. );
  241. while ( 0 != count )
  242. {
  243. ITDirectoryObject * pObject;
  244. count--;
  245. pObject = (ITDirectoryObject *)SendDlgItemMessage(
  246. IDC_CONFLIST,
  247. LB_GETITEMDATA,
  248. count,
  249. 0
  250. );
  251. pObject->Release();
  252. }
  253. }
  254. BEGIN_MESSAGE_MAP(CConfDlg, CDialog)
  255. ON_WM_DESTROY()
  256. END_MESSAGE_MAP()