Returning a string in c++ UO as UO Parameter

User avatar
jasper
Posts: 1129
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: Returning a string in c++ UO as UO Parameter

Post by jasper »

Perhaps you can add all known python versions to the list?
SLiebschner
Posts: 19
Joined: 01 February 2022, 10:14

Re: Returning a string in c++ UO as UO Parameter

Post by SLiebschner »

I hoped that I could avoid this, but there seems to be no other way.
For the record, here are my changes to get_OptionList and get_RestrictedToList:

Code: Select all

STDMETHOD(get_OptionList)(VARIANT* v)
{
	// This function specifies all allowed version numbers.
	// Pro-II displays only version numbers, which are allowed by this function.

	// set type to string array
	v->vt = VT_ARRAY | VT_BSTR;	

	// specify allowed versions
	vector<BSTR> allowed_versions = { SysAllocString(L"x.y.z") };
	for(unsigned int major = 0; major <=2; major++)
	{
		for (unsigned int minor = 0; minor <= 11; minor++)
		{
			for (unsigned int bugfix = 0; bugfix <= 11; bugfix++)
			{
				// build version STL string
				string version_STLstring = to_string(major) + "." + to_string(minor) + "."  + to_string(bugfix);
				// convert STL string to BSTR and append to vector
				CComBSTR temp(version_STLstring.c_str());
				allowed_versions.push_back(temp.Detach());
			}
		}
	}

	// write allowed versions to output parameter
	v->parray = SafeArrayCreateVector(VT_BSTR, 0, (unsigned int) allowed_versions.size()); // start indexing at 0
	long i = 0;
	for (vector<BSTR>::iterator it = allowed_versions.begin(); it != allowed_versions.end(); it++, i++ )
	{
		SafeArrayPutElement(v->parray, &i, *it);
	}

		return NOERROR;
	}
	STDMETHOD(get_RestrictedToList)(VARIANT_BOOL * vb)
	{
		*vb = VARIANT_TRUE;
		return NOERROR;
	}
I think this solves this issue.
The clue was that one has to specify all possible string values in get_OptionList in order to display one of them in Pro-II.
Many thanks Jasper for your help!
User avatar
jasper
Posts: 1129
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: Returning a string in c++ UO as UO Parameter

Post by jasper »

Glad to hear it works now.
Post Reply

Return to “Unit Operations”