|
cosmosworks object is returning null (c++)
hello all,
i am currently working on a project that runs a macro for cosmosworks in c++. however, for some reason, when i run my code my cosmosworks object is equal to null. i have supplied a section of my code to explain exactly how i am working it, could someone possibly steer me in the right direction, or inform me of any steps that i am missing.
void foo()
{
//pre: m_isldworks is a pointer to the sldworks object
ccombstr cwbstr = (_t("cosmosworks.cosmosworks));
ccomptr [icosmosworks] m_icosworks;
ccomptr[idispatch] swdispatch;
ccomptr[icwmodeldoc] cwmodel;
hresult hres;
if(m_isldworks->getaddinobject(cwbstr, &swdispatch) == s_ok)
{
checkpt
if(swdispatch)
{
hres = swdispatch->queryinterface(__uuidof(icosmosworks), (void **)&m_icosworks);
if(hres == s_false)
{
checkpt
return s_false;
}
if(m_icosworks)
{
hres = m_icosworks->get_activedoc(&cwmodel);
}
}
}
...
any help would be greatly appreciated.
brendan l
edited: 08/11/2008 at 01:26 pm by brendan l
is the cosmosworks add-in already loaded into solidworks before running this code? if not you need to call sldwors::loadaddin
i thought that might have been an issue and have actually tried that as well. both with cw already loaded.. and using the loadaddin function.
brendan leahy
so are you saying this line passes:
m_isldworks->getaddinobject(cwbstr, &swdispatch) == s_ok
and then this line does not evaluate true so is skipped:
if(swdispatch)
? also, not all code paths return a value (if the above if statement is not satisfied the function ends with no return, and on top of that the function specifies not to return any value anyway (void) yet you do inside the if statement.
and finally, can you clarify what checkpt is doing in this code? (my c++ brain is a bit sleepy today)
or is it that the query interface fails here:
hres = swdispatch->queryinterface(__uuidof(icosmosworks), (void **)&m_icosworks);
returning s_false?
oh, about checkpt, its a macro i wrote that tells me if it got to that line - i use it to debug the program. i thought i had taken them out. the problem is at the line
hres = swdispatch->queryinterface(__uuidof(icosmosworks),(void **)&m_icosworks);
when i am connected to a license of cosmosworks, and cw is loaded, this line sets m_icosworks == null. when i am not connected to a license (license on server)... this line returns a valid pointer to the m_icosworks. (which is something i just figured out).
this is a small tidbit of the code... there is a return s_ok at the very end of the function call that catchs anything that fails.
edited: 08/12/2008 at 10:33 am by brendan l
answer alright, so i figured it out. with the call:
if(m_isldworks->getaddinobject(cwbstr, &swdispatch) == s_ok),
the dispatch pointer is one to a cwaddincallback object instead of a cosmosworks object. changing the queryinterface to read:
if(swdispatch->queryinterface(iid_icwaddincallback, (void **) &cwaddincallback) == s_ok)
and then calling the
cwaddincallback->get_cosmosworks( &m_icosworks);
does the trick. i just am putting it up here for other people who might be interested in it.
thank you again for your help.
brendan l
quick |
|