What is wrong in this source generated COM code? #122717
-
|
I'm trying to get a grasp of source generated COM and I'm just writing this as an small test. After 2 hours looking for information and trying different things (everything found in the web is in the "old" COM style, surprinsingly) I don't understand why the error in the array of filters in What's wrong? Is sometype of incompatibility? I have to give in and just put an [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct COMDLG_FILTERSPEC
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pszName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pszSpec;
}
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
[Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")]
internal partial interface IShellItem
{
void BindToHandler(IntPtr pbc, ref Guid rbhid, ref Guid riid, out IntPtr ppv);
void GetParent(out IShellItem ppsi);
void GetDisplayName(uint sigdnName, out string ppszName);
void GetAttributes(uint sfgaoMask, out uint psfgaoAttribs);
void Compare(IShellItem psi, uint hint, out int piOrder);
}
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
[Guid("42f85136-db7e-439c-85f1-e4075d135fc8")]
internal partial interface IFileDialog
{
[PreserveSig] int Show(IntPtr parent);
void SetFileTypes(uint cElements, COMDLG_FILTERSPEC[] rgFilterSpec);//It complains about the array
void SetFileTypeIndex(uint iFileType);
uint GetFileTypeIndex();
void Advise(IntPtr pfde, out uint pdwCookie);
void Unadvise(uint dwCookie);
void SetOptions(uint fos);
uint GetOptions();
void SetDefaultExtension(string pszDefaultExtension);
void GetResult(out IShellItem ppsi);
void SetFileName(string pszName);
void GetFileName(out string pszName);
void SetTitle(string pszTitle);
void SetOkButtonLabel(string pszText);
void SetFileNameLabel(string pszText);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
The problem is the |
Beta Was this translation helpful? Give feedback.
The problem is the
stringmember in the struct. It requires marshalling which is not supported by the source generator (and P/Invoke source generator). You must define them aschar*orIntPtrand marshal manually.