-
Notifications
You must be signed in to change notification settings - Fork 3
/
DDEString.cpp
59 lines (48 loc) · 1.4 KB
/
DDEString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: DDESTRING.CPP
** COMPONENT: Network & Comms Library
** DESCRIPTION: The CDDEString class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "DDEString.hpp"
#include "DDEInst.hpp"
#include "DDEException.hpp"
CDDEString::CDDEString(CDDEInst* pInst, const tchar* pszString, bool bOwn)
: m_pInst(pInst)
, m_hsz()
, m_bOwn(bOwn)
{
ASSERT(pInst != nullptr);
ASSERT(pszString != nullptr);
// Create the string handle.
m_hsz = ::DdeCreateStringHandle(m_pInst->Handle(), pszString, CP_WIN_TCHAR);
if (m_hsz == NULL)
throw CDDEException(CDDEException::E_STRING_FAILED, m_pInst->LastError());
// Save original string.
tstrncpy(m_sz, pszString, MAX_LENGTH);
m_sz[MAX_LENGTH] = '\0';
}
CDDEString::CDDEString(CDDEInst* pInst, HSZ hsz, bool bOwn)
: m_pInst(pInst)
, m_hsz(hsz)
, m_bOwn(bOwn)
{
ASSERT(pInst != nullptr);
// Extract original string.
DWORD result = ::DdeQueryString(m_pInst->Handle(), m_hsz, m_sz, MAX_LENGTH+1, CP_WIN_TCHAR);
if (result == 0)
throw CDDEException(CDDEException::E_STRCOPY_FAILED, m_pInst->LastError());
}
CDDEString::~CDDEString()
{
// Free the string, if owned.
if (m_bOwn)
{
BOOL okay = ::DdeFreeStringHandle(m_pInst->Handle(), m_hsz);
ASSERT_RESULT(okay, okay != FALSE);
}
}