Page 1 of 1

How to write CAPE-OPEN registry entries under C#

Posted: 17 August 2021, 17:29
by bcbooo
When implementing a Unit Operation in C++, there are some registry information stored in .rgs file, and these information will be wrote to Windows registry automatically when the C++ dll file is registered, as follows:

HKCU
{
NoRemove Software
{
NoRemove Classes
{
CPPMixerSplitterexample.CPPMixerSplit.1 = s 'CPPMixerSplitterUnitOperation Class'
{
CLSID = s '{3B7FDF53-EC5A-4BF8-99F2-819A8BF90579}'
}
CPPMixerSplitterexample.CPPMixerSplitte = s 'CPPMixerSplitterUnitOperation Class'
{
CLSID = s '{3B7FDF53-EC5A-4BF8-99F2-819A8BF90579}'
CurVer = s 'CPPMixerSplitterexample.CPPMixerSplit.1'
}
NoRemove CLSID
{
ForceRemove {3B7FDF53-EC5A-4BF8-99F2-819A8BF90579} = s 'CPPMixerSplitterUnitOperation Class'
{
ProgID = s 'CPPMixerSplitterexample.CPPMixerSplit.1'
VersionIndependentProgID = s 'CPPMixerSplitterexample.CPPMixerSplitte'
ForceRemove 'Programmable'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
val AppID = s '%APPID%'
'TypeLib' = s '{D2588024-AC34-4F37-BC66-3B020A481366}'
'Implemented Categories'
{
{678C09A5-7D66-11D2-A67D-00105A42887F}
{678C09A1-7D66-11D2-A67D-00105A42887F}
}
CapeDescription
{ val Name = s 'CPP Mixer Splitter Example'
val Description = s 'Microsoft Visual C++ 2005 Mixer and Splitter Example according to CAPE-OPEN Unit Operation specification'
val CapeVersion = s '1.0'
val ComponentVersion = s '1.0.1'
val VendorURL = s 'http://www.colan.org/'
val About = s 'See http://www.colan.org/ for more information'
}

}
}
}
}
}


And now I want to develop a Unit Operation under C# class library environment, and I found COLAN provided a class library to write to registry:

[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.Guid("B41DECE0-6C99-4CA4-B0EB-EFADBDCE23E9")]//ICapeThermoMaterialObject_IID)
[CapeOpen.CapeNameAttribute("UnitOperationWrapper")]
[CapeOpen.CapeDescriptionAttribute("This class provides access to unit operations based upon .Net-based assembly location rules.")]
[CapeOpen.CapeVersionAttribute("1.0")]
[CapeOpen.CapeVendorURLAttribute("http:\\www.epa.gov")]
[CapeOpen.CapeHelpURLAttribute("http:\\www.epa.gov")]
[CapeOpen.CapeAboutAttribute("US Environmental Protection Agency\nCincinnati, Ohio")]

[System.Runtime.InteropServices.ComSourceInterfaces(typeof(ICapeIdentificationEvents), typeof(System.ComponentModel.INotifyPropertyChanged))]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public class UnitOperationWrapper : CapeUnitBase,
ICapeUnitReport,
ICapeUnitReportCOM,
//ICloneable,
System.ComponentModel.INotifyPropertyChanged,
//IDisposable,
System.Runtime.Serialization.ISerializable

But I want to implement the C# unit operation without CAPE-OPEN class library, therefore I need to write the registry information of red color by myself. I don't know how to add these information in my C# source code, could you help me by providing the sample code? Any response is appreciated.

Re: How to write CAPE-OPEN registry entries under C#

Posted: 18 August 2021, 07:46
by jasper
You could add COM registration functions to your class, like so:

Code: Select all


        [ComRegisterFunctionAttribute]
        public static void RegisterFunction(Type t)
        {
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID\\{" + clsid + "}", true);
            //implemented categories
            Microsoft.Win32.RegistryKey catsKey = key.CreateSubKey("Implemented Categories");
            catsKey.CreateSubKey("{678C09A5-7D66-11D2-A67D-00105A42887F}").Close(); //unit op
            catsKey.CreateSubKey("{678C09A1-7D66-11D2-A67D-00105A42887F}").Close(); //cape-open PMC
            catsKey.CreateSubKey("{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}").Close(); //.NET COM object
            catsKey.CreateSubKey("{4150C28A-EE06-403f-A871-87AFEC38A249}").Close(); //thermo consuming PMC
            catsKey.CreateSubKey("{0D562DC8-EA8E-4210-AB39-B66513C0CD09}").Close(); //supports 1.0 thermo
            catsKey.CreateSubKey("{4667023A-5A8E-4CCA-AB6D-9D78C5112FED}").Close(); //supports 1.1 thermo
            catsKey.Close();
            //CapeDescription
            Microsoft.Win32.RegistryKey descKey = key.CreateSubKey("CapeDescription");
            descKey.SetValue("Name", defaultName);
            descKey.SetValue("Description", defaultDescription);
            descKey.SetValue("CapeVersion", "1.0");
            descKey.SetValue("ComponentVersion", System.Reflection.Assembly.GetAssembly(typeof(UnitOperation)).GetName().Version.ToString());
            descKey.SetValue("VendorURL", "https://A_URL_to_my_web_site"); 
            descKey.SetValue("About", "Some information about this unit operation");
            descKey.Close();
        }

        [ComUnregisterFunctionAttribute]
        public static void UnregisterFunction(Type t)
        {
            //Remove additional keys
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID\\{" + clsid + "}", true);
            key.DeleteSubKeyTree("Implemented Categories");
            key.DeleteSubKeyTree("CapeDescription");
            key.Close();
        }


Re: How to write CAPE-OPEN registry entries under C#

Posted: 18 August 2021, 12:05
by bcbooo
Jasper you are so great.
I am investigating a Unit Operation source code implemented by C#, I found it's rather complicated than the ones by C++.