The return value type of GetPhaseInfo

Questions related to Thermodynamic and Physical Properties interface specification in version 1.1

The return value type of GetPhaseInfo

Postby bcbooo » 04 September 2018, 01:53

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?
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: The return value type of GetPhaseInfo

Postby jasper » 04 September 2018, 07:14

A string:

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

Re: The return value type of GetPhaseInfo

Postby jasper » 04 September 2018, 07:17

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.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: The return value type of GetPhaseInfo

Postby bcbooo » 04 September 2018, 08:43

Thank you Jasper
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China


Return to Thermodynamic v1.1

Who is online

Users browsing this forum: No registered users and 1 guest