Click to See Complete Forum and Search --> : ATL - get project's full name


AviLaviad
February 1st, 2005, 08:58 AM
hi,
im trying to get the project's full name by iterating the projects array.

EnvDTE::Projects *l_pProjects;
l_pSolution->get_Projects(&l_pProjects);
long *l_Count = new long;
l_pProjects->get_Count(l_Count);

for(long l = 0; l < *l_Count; l++)
{
EnvDTE::Project *l_pPrj;
VARIANT v;
v.lVal = 0;
l_pProjects->Item(v,&l_pPrj);
BSTR fullname;
l_pPrj->get_FullName(&fullname); // PROBLEM!
}

the problem is where the comment "// PROBLEM!" is. it just won't work?
what am i doing wrong?

Avi.

Mutilated1
February 1st, 2005, 10:56 AM
A BSTR is in actuality a pointer, and while you can just declare a BSTR if you want too, if you don't initialize it, it points to void and you will be in trouble if you use it. Thats whats happening to you.

Change the part where you are having a problem like this...



//BSTR fullname;// NO! Raw BSTRs == BAD programming practice
CComBSTR fullname; // Safer and is a properly initialized BSTR

l_pPrj->get_FullName(&fullname); // Now fullname actually points to a BSTR



Your code is leaking Release()s also, so use the ALT smart pointers CComPtr<EnvDTE::Project> instead of a raw EnvDTE::Project *

And check your HRESULTS while you are at it. If you program safely and hygenically in the first place you will be much better off.