microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No consistent definitions in some Com interface methods

harborsiem opened this issue · comments

Actual behavior

I am working on a wrapper for the Ribbon Framework, which is using some Com Interfaces of the UIRibbon.dll. allowMarshaling = true is set and this is the only way for me to build the wrapper. But with CsWin32 version 0.3.85-beta and also versions before, I get no consistent definitions for some interface methods for the parameter modifier (in, ref, out or pointer to some structs). See 3. part in this issue where you can see the methods.
In CsWin32 version 0.3.85-beta parameter type PROPVARIANT and also PROPVARIANT_unmanaged is used. This is not done in version 0.3.49beta and before. PROPVARIANT and PROPVARIANT_unmanaged seems to be identical.

Expected behavior

See 3. part where you can see my suggestions. See also issue #881. Optional parameters should be defined by a pointer parameter. In most other cases the parameters should have an in, ref or out modifier, not a pointer.
PROPVARIANT should only used in the definitions.

Repro steps

  1. NativeMethods.txt content:
IUIFramework
IUICommandHandler
IUICollection //OK
IUICollectionChangedEvent //OK
IUIApplication //OK
IUIRibbon //OK
IUISimplePropertySet
IUIImageFromBitmap //OK
IUIImage
IUIEventLogger
IUIEventingManager //OK
IUIContextualUI //OK
IStream
IPropertyStore
IEnumUnknown //OK

  1. NativeMethods.json content (if present):
  "comInterop": {
    "useIntPtrForComOutPointers": false,
    "preserveSigMethods": [ "IUIApplication", "IUICollection", "IUICollectionChangedEvent", "IUICommandHandler", "IUIContextualUI", "IUIEventingManager", "IUIEventLogger" ,
	"IUIFramework", "IUIImage", "IUIImageFromBitmap", "IUIRibbon", "IUISimplePropertySet", "IPropertyStore", "IStream" ]
  },
  "useSafeHandles": false,
  "allowMarshaling": true,
  "friendlyOverloads": {"enabled": false}
  1. Any of your own code that should be shared?
interface IUIFramework
{
unsafe winmdroot.Foundation.HRESULT GetView(uint viewId, global::System.Guid* riid, void** ppv);
//expected signature
unsafe winmdroot.Foundation.HRESULT GetView(uint viewId, in global::System.Guid riid, out void* ppv);

unsafe winmdroot.Foundation.HRESULT GetUICommandProperty(uint commandId, winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* key, out winmdroot.System.Com.StructuredStorage.PROPVARIANT value);
//expected signature
unsafe winmdroot.Foundation.HRESULT GetUICommandProperty(uint commandId, in winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY key, out winmdroot.System.Com.StructuredStorage.PROPVARIANT value);

unsafe winmdroot.Foundation.HRESULT SetUICommandProperty(uint commandId, winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* key, in winmdroot.System.Com.StructuredStorage.PROPVARIANT value);
//expected signature
unsafe winmdroot.Foundation.HRESULT SetUICommandProperty(uint commandId, in winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY key, in winmdroot.System.Com.StructuredStorage.PROPVARIANT value);

all other definitions in this interface seems to be correct
}
interface IUICommandHandler
{
//why is PROPVARIANT_unmanaged in the following definition used ?
unsafe winmdroot.Foundation.HRESULT Execute(uint commandId, winmdroot.UI.Ribbon.UI_EXECUTIONVERB verb, [Optional] winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* key, [Optional] winmdroot.System.Com.StructuredStorage.PROPVARIANT_unmanaged* currentValue, winmdroot.UI.Ribbon.IUISimplePropertySet commandExecutionProperties);
//expected signature
unsafe winmdroot.Foundation.HRESULT Execute(uint commandId, winmdroot.UI.Ribbon.UI_EXECUTIONVERB verb, [Optional] winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* key, [Optional] winmdroot.System.Com.StructuredStorage.PROPVARIANT* currentValue, winmdroot.UI.Ribbon.IUISimplePropertySet commandExecutionProperties);


//why is PROPVARIANT_unmanaged in the following definition used ?
unsafe winmdroot.Foundation.HRESULT UpdateProperty(uint commandId, winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* key, [Optional] winmdroot.System.Com.StructuredStorage.PROPVARIANT_unmanaged* currentValue, out winmdroot.System.Com.StructuredStorage.PROPVARIANT newValue);
//expected signature
unsafe winmdroot.Foundation.HRESULT UpdateProperty(uint commandId, in winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY key, [Optional] winmdroot.System.Com.StructuredStorage.PROPVARIANT* currentValue, out winmdroot.System.Com.StructuredStorage.PROPVARIANT newValue);

}
interface IUISimplePropertySet
{
unsafe winmdroot.Foundation.HRESULT GetValue(winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* key, out winmdroot.System.Com.StructuredStorage.PROPVARIANT value);
//expected signature
unsafe winmdroot.Foundation.HRESULT GetValue(in winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY key, out winmdroot.System.Com.StructuredStorage.PROPVARIANT value);

}
interface IUIImage
{
unsafe winmdroot.Foundation.HRESULT GetBitmap(winmdroot.Graphics.Gdi.HBITMAP* bitmap);
//expected signature
unsafe winmdroot.Foundation.HRESULT GetBitmap(out winmdroot.Graphics.Gdi.HBITMAP bitmap);

}
interface IUIEventLogger
{
unsafe void OnUIEvent(winmdroot.UI.Ribbon.UI_EVENTPARAMS* pEventParams);
//expected signature
unsafe void OnUIEvent(in winmdroot.UI.Ribbon.UI_EVENTPARAMS pEventParams);

}
interface IStream
{
unsafe winmdroot.Foundation.HRESULT Stat(winmdroot.System.Com.STATSTG* pstatstg, [MarshalAs(UnmanagedType.U4)] winmdroot.System.Com.STATFLAG grfStatFlag);
//expected signature
unsafe winmdroot.Foundation.HRESULT Stat(out winmdroot.System.Com.STATSTG pstatstg, [MarshalAs(UnmanagedType.U4)] winmdroot.System.Com.STATFLAG grfStatFlag);

//all other definitions in this interface seems to be correct

}
interface IPropertyStore
{
unsafe winmdroot.Foundation.HRESULT GetAt(uint iProp, winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* pkey);
//expected signature
unsafe winmdroot.Foundation.HRESULT GetAt(uint iProp, out winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY pkey);

unsafe winmdroot.Foundation.HRESULT GetValue(winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* key, out winmdroot.System.Com.StructuredStorage.PROPVARIANT pv);
//expected signature
unsafe winmdroot.Foundation.HRESULT GetValue(in winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY key, out winmdroot.System.Com.StructuredStorage.PROPVARIANT pv);

unsafe winmdroot.Foundation.HRESULT SetValue(winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY* key, in winmdroot.System.Com.StructuredStorage.PROPVARIANT propvar);
//expected signature
unsafe winmdroot.Foundation.HRESULT SetValue(in winmdroot.UI.Shell.PropertiesSystem.PROPERTYKEY key, in winmdroot.System.Com.StructuredStorage.PROPVARIANT propvar);

//all other definitions in this interface seems to be correct

}

Context

  • CsWin32 version: [0.3.85-beta]
  • Win32Metadata version (if explicitly set by project):
  • Target Framework: [e.g. netstandard2.0]
  • LangVersion (if explicitly set by project): [e.g. 9]