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?
LVL 27
BigRatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.