|
-
April 19th, 2004, 07:46 PM
#1
ActiveX properties
I currently am coding an activeX control and I need to have a property that is a string. The only string type that it appears I can use is the BSTR type. But I need it to be a LPCTSTR type. What is the code for changing the type from a BSTR to a LPCTSTR type? Iam not familiar with type casting in c++ as I usually deal with java so sorry if this is a stupid question!
-
April 20th, 2004, 09:18 AM
#2
Strings in COM interfaces are typically BSTRs which are WCHAR based. LPCTSTR are sometimes char based. LPCTSTR changes based on whether you are doing a unicode build or not. Therefore you cannot use LPCTSTR in a COM interface. All strings surfaced as properties in an ActiveX control must be BSTRs.
If you still want to you can convert to/from unicode strings try MSDN TN059: Using MFC MBCS/Unicode Conversion Macros. OLE2CT will convert from a BSTR to a LPCTSTR.
Sincerely,
- Ron
-
April 20th, 2004, 10:19 AM
#3
Re: ActiveX properties
Originally posted by Mikewithersone
I currently am coding an activeX control and I need to have a property that is a string. The only string type that it appears I can use is the BSTR type. But I need it to be a LPCTSTR type. What is the code for changing the type from a BSTR to a LPCTSTR type? Iam not familiar with type casting in c++ as I usually deal with java so sorry if this is a stupid question!
Not need to think about casting BSTR to LPCTSTR or whatever.
Let Class(good)Wizard to add a property of BSTR type (e.g. "TestProperty"), then...
add a member variable of type CString:
Code:
class C_test_ocxCtrl : public COleControl
{
// Atributes:
protected:
CString m_strTestProperty;
//...
};
modify the corresponding Get/Set functions as follows:
Code:
BSTR C_test_ocxCtrl::GetTestProperty()
{
return m_strTestProperty.AllocSysString();
}
void C_test_ocxCtrl::SetTestProperty(LPCTSTR lpszNewValue)
{
m_strTestProperty = lpszNewValue;
SetModifiedFlag();
}
When inserting the control into a project, you will see in generated wrapper class something more familiar (and no BSTRs
Code:
class C_test_ocx : public CWnd
{
// ...
// Attributes
public:
CString GetTestProperty();
void SetTestProperty(LPCTSTR);
};
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|