Solved

passing string to container from Active-X

Posted on 2001-09-12
10
948 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:gymsam
ID: 6485448
Then what exactly you mean.Then what is the solution?
0
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…

803 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