by jasper » 18 April 2016, 09:52
You are not showing in your snippet the declaration of the variable material, unless it is the same variable as mat.
The one but last argument to CoCreateInstance is an IID, you pass the CLSID. The IID (interface ID) is the identifier of the interface you want to have returned via CoCreateInstance. You could pass IID_ICapeThermoMaterial for example, and then your material variable should be an ICapeThermoMaterial *. You can also get other interfaces by using QueryInterface. Please note that if you are using raw pointers, you should be aware of the fact that each CoCreateInstance and each QueryInterface must be paired by a Release() to manage the life time of the COM object. One way to get around that would be to use smart pointers to manage the life span of your objects.
Also note that you do not need to access your material object via the CAPE-OPEN interfaces. As you supply the material object, you have control over how it looks. Often it is implemented in the same process, instead of in a separate COM server, and not registered in the Windows Registry (if you are using ATL, use DECLARE_NO_REGISTRY()). Then create the object with MyCapeOpenCOM::CreateObject() (presuming this is the name of your class) instead of CoCreateInstance, and access the methods or data members in the object directly. Only the property package that you talk to needs to access your material object over the CAPE-OPEN interfaces.
Be also aware of the ownership of data arguments. Arguments marked by [in] may not be changed by the called method. Arguments marked [out] are allocated by the called method, and must be released or deallocated by the caller. Arguments marked [in,out] must in addition have a valid value on entry. For both [out] and [in,out] the safe thing to do is to initialize objects by NULL (unless input is actually required for the method). COM programming is a bit tricky once in a while when it comes to memory management, and memory leaks are fairly hard to debug.