Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
655 Views, 3 Replies

VC++ addin to create a ClientFeature

Hi,

I've been trying to create a ClientFeature with a c++ addin for a few hours, without success.

Here is a sample of my code :

 

Document * doc = m_pApp->GetActiveDocument();
PartDocument * partDoc;
HRESULT hr = doc->QueryInterface(__uuidof(PartDocument), (void**)&partDoc);
if (!SUCCEEDED(hr) || !partDoc) return E_FAIL;
PartComponentDefinition * oCompDef = partDoc->ComponentDefinition;
if(!oCompDef) return E_FAIL;
PartFeatures * partFeatures = oCompDef->GetFeatures();
if (!partFeatures) return E_FAIL;
ClientFeatures * clientFeatures = partFeatures->ClientFeatures;
if (!clientFeatures) return E_FAIL;
CComPtr<ClientFeatureDefinition> clientFeatureDef;
CComBSTR featType = "FeatName";
VARIANT nothing; hr = clientFeatures->CreateDefinition(featType, nothing, nothing, nothing, &clientFeatureDef); // crash

 

I use "nothing" because these arguments are optional but as the C++ function return the result in the last argument I have to provid the previous arguments.

 

When trying to execute this code, Inventor throw an exception and crash at the "CreateDefinition" line.

I also tried with 

 

_bstr_t featTypebstr = "FeatName";
clientFeatureDef = clientFeatures->MethodCreateDefinition(featTypebstr);

and got the same result (crash).

 

If anyone could tell me what I am doing wrong that would be really helpful.

Thank you,

Thomas