[Webinar] Streamline your web hosting managementRegister Today

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

passing string to container from Active-X

I have ole enabled container which has active-x.When i click the GUI of Active-x control, the control inturn should fire event passing a string value to the container.Now i have created the custom event in the active-x control.Now when the event is fired i am able to get the string to the container but only the first charecter i want the entire string.How to get the entire string? listing as follows

Active-x control
BEGIN_EVENT_MAP(CFilterCtrl, COleControl)
     //{{AFX_EVENT_MAP(CFilterCtrl)
     EVENT_CUSTOM("Group", FireGroup, VTS_BSTR)
     //}}AFX_EVENT_MAP
END_EVENT_MAP()

void FireGroup(BSTR bstrVal)
{FireEvent(eventidGroup,EVENT_PARAM(VTS_BSTR),bstrVal);}
DECLARE_EVENT_MAP()

//when this control is clicked

COleVariant varVal(group.m_DisplayName);
varVal.ChangeType( VT_BSTR );
FireGroup(varVal.bstrVal);


///////// container ///////////////
BEGIN_EVENTSINK_MAP(CMISReportView, CFormView)
    //{{AFX_EVENTSINK_MAP(CEntityView)
ON_EVENT(CMISReportView, IDC_FILTERCTRL_GROUP, 10 /* Group */, OnGroup, VTS_BSTR)
     //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

afx_msg void OnGroup(BSTR bstrGroup)
DECLARE_EVENTSINK_MAP()

void CMISReportView::OnGroup(BSTR bstrGroup)
{
     COleVariant varVal((LPCTSTR)bstrGroup);
     varVal.ChangeType( VT_BSTR );
     MessageBox((char *)varVal.bstrVal);// ONELY THE FIRST CHARACTER IS OBTAINED
     theApp.m_strGpNames = (LPCTSTR)bstrGroup;
}
0
gymsam
Asked:
gymsam
  • 5
  • 3
1 Solution
 
ShaunWildeCommented:
your problem is this line of code

>MessageBox((char *)varVal.bstrVal);//  

a BSTR is define as a short* eg UNICODE like

so what you need to do is convert the BSTR to ANSI - however CString (I think) does this for you

void CMISReportView::OnGroup(BSTR bstrGroup)
{
    theApp.m_strGpNames = (LPCTSTR)bstrGroup;
    MessageBox(theApp.m_strGpNames);
}


0
 
ShaunWildeCommented:
oops cut and paste hell again

void CMISReportView::OnGroup(BSTR bstrGroup)
{
   theApp.m_strGpNames = (LPCWSTR)bstrGroup;
   MessageBox(theApp.m_strGpNames);
}





0
 
ShaunWildeCommented:
actually the problem could lie here as this is where you first mangle the name

> COleVariant varVal((LPCTSTR)bstrGroup);
   
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
gymsamAuthor Commented:
Then what exactly you mean.Then what is the solution?
0
 
ShaunWildeCommented:
use, as CString already understands how to convert from wide char (UNICODE) to its internal format
void CMISReportView::OnGroup(BSTR bstrGroup)
{
  theApp.m_strGpNames = (LPCWSTR)bstrGroup;
  MessageBox(theApp.m_strGpNames);
}


what was happening befre was that you was forcing the compiler to treat the BSTR as a char* - which is not good as BSTR are short* - as you know in a char* the terminator is '\0' however in UNICODE these single character nulls are nearly on every alternate byte - this when you cast a UNICODE string to an ANSI string (char*)myBSTR - you will only show the first character which was what you were seeing

you do this in 2 locations

>    COleVariant varVal((LPCTSTR)bstrGroup);
this is where the damage was done
and

>    MessageBox((char *)varVal.bstrVal);// ONLY THE FIRST CHARACTER IS OBTAINED
you do the same again but the damage has already been done as the BSTR in varVal only contains 1 character
0
 
gymsamAuthor Commented:
So what is the solution? i want the answere.

0
 
ShaunWildeCommented:
What with what I have given you don't you understand - the answer is there or should be - does it not work?



void CMISReportView::OnGroup(BSTR bstrGroup)
{
 theApp.m_strGpNames = (LPCWSTR)bstrGroup;
 MessageBox(theApp.m_strGpNames);
}


0
 
gymsamAuthor Commented:
Now iam out of my office(On leave) i will soon try you suggestion and let you know.
0
 
Roshan DavisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: ShaunWilde

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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