Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

CString in ActiveX Control

I'm using VC++ 6.0 and am writing an ActiveX control (in a dll) which the Wizard has produce 90% of the code so far.

I have to remember an "active printer" with these two property functions :-

STDMETHODIMP CRatPrint::get_activePrinter(BSTR *pVal)
{
      // ZU ERLEDIGEN: Implementierungscode hier hinzufügen
      return S_OK;
}

STDMETHODIMP CRatPrint::put_activePrinter(BSTR newVal)
{
      // ZU ERLEDIGEN: Implementierungscode hier hinzufügen
      return S_OK;
}

but if I declare a private member variable in my CRatPrint class, viz :

    CString m_activePrinter;

I get an "CString not declared" error although I've included stdafx and windows.h.

What is really the best way of storing a string in an ActiveX control? And if it is CString what am I doing wrong?
0
BigRat
Asked:
BigRat
3 Solutions
 
jkrCommented:
>>What is really the best way of storing a string in an ActiveX control?

Well, what ever suits the case best - I'd probably use a std::string.

>>And if it is CString what am I doing wrong?

Check your stdafx.h whther it includes 'afx.h' - ATL does not necessarily utilize MFC strings.
0
 
jweston1Commented:
A CString class is also part of the Windows Template Library, an extension of ATL. It's defined in atlmisc.h. You can download it at http://www.microsoft.com/downloads/details.aspx?FamilyID=1be1eb52-aa96-4685-99a5-4256737781c5&DisplayLang=en.
0
 
BigRatAuthor Commented:
That didn't actually help me, since I'm not a C++ programmer. The last ActiveX control I wrote was done entirely in traditional C.

I need
1) to delcare a private member string (Unicode!)
2) assign it from a BSTR
3) assign a BSTR from it.
0
 
Dariusz DziaraProgrammerCommented:
You could use CComBSTR class and call Copy() method to get BSTR string from data member and operator=() to assign it to the member.
Something similar should work (more or less):

class CMyClass : public [...] {
[...]
CComBSTR m_bstrText;
};

STDMETHODIMP CMyClass::put_Text(BSTR text)
{
  m_bstrText = text;
  return S_OK;
}

STDMETHODIMP CMyClass::get_Text(BSTR *text)
{
  if(text == NULL) return E_POINTER;
  (*text) = m_bstrText.Copy()
  return S_OK;
}
0
 
BigRatAuthor Commented:
mrblue, I tried that as well, but I kept getting "not declared errors". I just can't get all these silly include files right.

I have simply done it using the SysString API. Free the old string if allocated and copy the new one.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now