views:

169

answers:

2

Hi

Can any body help me in converting Interface Pointer to list variable in vc++ since i am getting the error while typeconversion

error 2440 "type cast" :cannot convert from '_bstr_t' to 'std::list<_Ty>'

so any one plz help me....

Thanks in advance.

Reply:

i Hav done liki this 


in C# com i have done like

List Disp()

{ List li =new List();

li.Add("Ravi"); li.Add("Raj"); Return li; }
in c++ Main

void main() {

HRESULT Hr=CoInitilize(NULL);

ITestPtr p(__uuid("DemoClass");

std::list l=(std::list)p->Disp();

}

} But strangely some times it shows that Disp is not a member of ITest and sometimes that type conversion error. I have verified this is only because of when the return type is List

any help will Greately Appreciated

A: 

I would expect the best thing to do unless there's a Really Nice Shortcut is manually walk the CLI list and push_back() onto the std::list.

As a possible example of what it might look like(I don't know C++/CLI)

std::list<T> stdlist;
foreach(T t in CLIlist)
{
    stdlist.push_back(t);
}
Paul Nathan
Give me clear explanation yar......
Cute
@Cute. that's about as clear as it gets.
Paul Nathan
+1  A: 

You could also use the Boost Range MFC/ATL Extenstion

CList<CString> vcList;
std::list<T> stdList;
BOOST_FOREACH( CString s, vcList)
{
    stdList.push_back(s);
}
fmuecke