Solved

passing string to container from Active-X

Posted on 2001-09-12
10
930 Views
Last Modified: 2013-11-25
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
Comment
Question by:gymsam
  • 5
  • 3
10 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6482606
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
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6482609
oops cut and paste hell again

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





0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6482614
actually the problem could lie here as this is where you first mangle the name

> COleVariant varVal((LPCTSTR)bstrGroup);
   
0
 

Author Comment

by:gymsam
ID: 6485448
Then what exactly you mean.Then what is the solution?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6485513
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
 

Author Comment

by:gymsam
ID: 6490358
So what is the solution? i want the answere.

0
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 50 total points
ID: 6490814
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
 

Author Comment

by:gymsam
ID: 6492393
Now iam out of my office(On leave) i will soon try you suggestion and let you know.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9532242
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now