The return value type of GetPhaseInfo

Questions related to Thermodynamic and Physical Properties interface specification in version 1.1
Post Reply
bcbooo
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

The return value type of GetPhaseInfo

Post by bcbooo »

GetPhaseInfo is defined as following:

GetPhaseInfo(BSTR phaseLabel, BSTR phaseAttribute, VARIANT * value);

where when phaseAttribute is 'StateOfAggregation', 'Vapor' or 'Liquid' or 'Solid' will be returned as string.

I have finished one Property Package, and tested in COFE environment, the following codes are wrong:

====== C++ codes start =============
CVaraint v;
v.MakeArray(1,VT_BSTR);
if(phase==_T("Vapor")) v.AllocStringAt(0,_T("Vapor"));
else if.......
......;
*value=v.ReturnValue();
return S_OK;
====== C++ codes end =============

COFE shows that:
"error: GetPhaseInfo() failed for phase Vapor: Failed to get state of aggregation, string value expected"

Then I changed the codes into the following:

====== C++ codes start =============
CVaraint v;
if(phase==_T("Vapor")) v.bstrVal=CBSTR(_T("Vapor"));
else if.......
......;
*value=v.ReturnValue();
return S_OK;
====== C++ codes end =============

The error tip of COFE still exists.

So I am not sure which VARIANT type of 'value' should I return?
User avatar
jasper
Posts: 1129
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: The return value type of GetPhaseInfo

Post by jasper »

A string:

v.vt=VT_BSTR;
v.bstrVal=SysAllocString(L"Liquid");
User avatar
jasper
Posts: 1129
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: The return value type of GetPhaseInfo

Post by jasper »

Also noting a problem with your second attempt (other than not setting the .vt field): the CBSTR will surely destroy the string in its destructor, and once you return the string, it is no longer owned by you (the callee should destroy it). This will likely lead to a crash. Not sure which CBSTR this is exactly, but most implementations have some sort of 'detach' member to release ownership.
bcbooo
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: The return value type of GetPhaseInfo

Post by bcbooo »

Thank you Jasper
Post Reply

Return to “Thermodynamic v1.1”