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.

164 lines
4.7 KiB

  1. // DlgExtensionData.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ConfigTest.h"
  5. #include "DlgExtensionData.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. typedef unsigned long ULONG_PTR, *PULONG_PTR;
  12. typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
  13. #include "..\..\..\inc\fxsapip.h"
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CDlgExtensionData dialog
  16. CDlgExtensionData::CDlgExtensionData(HANDLE hFax, CWnd* pParent /*=NULL*/)
  17. : CDialog(CDlgExtensionData::IDD, pParent), m_hFax (hFax)
  18. {
  19. //{{AFX_DATA_INIT(CDlgExtensionData)
  20. m_cstrData = _T("");
  21. m_cstrGUID = _T("");
  22. //}}AFX_DATA_INIT
  23. }
  24. void CDlgExtensionData::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CDlgExtensionData)
  28. DDX_Control(pDX, IDC_CMDDEVICES, m_cmbDevices);
  29. DDX_Text(pDX, IDC_DATA, m_cstrData);
  30. DDX_Text(pDX, IDC_GUID, m_cstrGUID);
  31. //}}AFX_DATA_MAP
  32. }
  33. BEGIN_MESSAGE_MAP(CDlgExtensionData, CDialog)
  34. //{{AFX_MSG_MAP(CDlgExtensionData)
  35. ON_BN_CLICKED(IDC_READ, OnRead)
  36. ON_BN_CLICKED(IDC_WRITE, OnWrite)
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CDlgExtensionData message handlers
  41. BOOL CDlgExtensionData::OnInitDialog()
  42. {
  43. CDialog::OnInitDialog();
  44. //
  45. // Fill list of devices
  46. //
  47. PFAX_PORT_INFO_EX pDevices;
  48. DWORD dwNumDevices;
  49. CString cs;
  50. if (!FaxEnumPortsEx (m_hFax, &pDevices, &dwNumDevices))
  51. {
  52. CString cs;
  53. cs.Format ("Failed while calling FaxEnumPortsEx (%ld)", GetLastError());
  54. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  55. return TRUE;
  56. }
  57. m_cmbDevices.ResetContent();
  58. int iIndex = m_cmbDevices.AddString ("<Unassigned>");
  59. m_cmbDevices.SetItemData (iIndex, 0);
  60. for (DWORD dw = 0; dw < dwNumDevices; dw++)
  61. {
  62. //
  63. // Insert device
  64. //
  65. cs.Format ("%s (%ld)", pDevices[dw].lpctstrDeviceName, pDevices[dw].dwDeviceID);
  66. iIndex = m_cmbDevices.AddString (cs);
  67. m_cmbDevices.SetItemData (iIndex, pDevices[dw].dwDeviceID);
  68. }
  69. UpdateData (FALSE);
  70. m_cmbDevices.SetCurSel (0);
  71. FaxFreeBuffer (LPVOID(pDevices));
  72. return TRUE; // return TRUE unless you set the focus to a control
  73. // EXCEPTION: OCX Property Pages should return FALSE
  74. }
  75. void CDlgExtensionData::OnRead()
  76. {
  77. UpdateData ();
  78. LPVOID lpData = NULL;
  79. DWORD dwSize;
  80. char sz[1024];
  81. DWORD dwDeviceId = m_cmbDevices.GetItemData(m_cmbDevices.GetCurSel());
  82. if (!FaxGetExtensionData ( m_hFax,
  83. dwDeviceId,
  84. m_cstrGUID,
  85. &lpData,
  86. &dwSize
  87. ))
  88. {
  89. CString cs;
  90. cs.Format ("Failed while calling FaxGetExtensionData (%ld)", GetLastError());
  91. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  92. return;
  93. }
  94. if (!WideCharToMultiByte (CP_ACP,
  95. 0,
  96. (LPCWSTR)(lpData),
  97. -1,
  98. sz,
  99. sizeof (sz),
  100. NULL,
  101. NULL))
  102. {
  103. CString cs;
  104. cs.Format ("Failed while calling WideCharToMultiByte (%ld)", GetLastError());
  105. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  106. FaxFreeBuffer (lpData);
  107. return;
  108. }
  109. m_cstrData = sz;
  110. UpdateData (FALSE);
  111. FaxFreeBuffer (lpData);
  112. }
  113. void CDlgExtensionData::OnWrite()
  114. {
  115. UpdateData ();
  116. WCHAR wsz[1024];
  117. DWORD dwDeviceId = m_cmbDevices.GetItemData(m_cmbDevices.GetCurSel());
  118. if (!MultiByteToWideChar (CP_ACP,
  119. 0,
  120. (LPCTSTR)(m_cstrData),
  121. -1,
  122. wsz,
  123. sizeof (wsz) / sizeof (wsz[0])))
  124. {
  125. CString cs;
  126. cs.Format ("Failed while calling MulityByteToWideChar (%ld)", GetLastError());
  127. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  128. return;
  129. }
  130. if (!FaxSetExtensionData ( m_hFax,
  131. dwDeviceId,
  132. m_cstrGUID,
  133. (LPVOID)(wsz),
  134. sizeof (WCHAR) * (m_cstrData.GetLength () + 1)
  135. ))
  136. {
  137. CString cs;
  138. cs.Format ("Failed while calling FaxSetExtensionData (%ld)", GetLastError());
  139. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  140. return;
  141. }
  142. }