Solved

passing string to container from Active-X

Posted on 2001-09-12
10
975 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…

630 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