简体   繁体   中英

Issue converting C# marshal interface code to VB.NET

I'm attempting to convert a project from C# to VB.NET to enable drag and dropping of Outlook messages into our program.

The original source can be found here on CodeProject.

I'm 95% of the way there but having trouble implementing the IStorage interface , a portion of which is outlined below.

public interface IStorage
{
    [return: MarshalAs(UnmanagedType.Interface)]
    IStream CreateStream([In, MarshalAs(UnmanagedType.BStr)] string pwcsName,
                         [In, MarshalAs(UnmanagedType.U4)] int grfMode,
                         [In, MarshalAs(UnmanagedType.U4)] int reserved1,
                         [In, MarshalAs(UnmanagedType.U4)] int reserved2);                
}

I've converted it to the following in VB.NET:

<MarshalAs(UnmanagedType.Interface)>
Function CreateStream(<[In], MarshalAs(UnmanagedType.BStr)> ByVal pwcsName As String,
                      <[In], MarshalAs(UnmanagedType.U4)> ByVal grfMode As Integer,
                      <[In], MarshalAs(UnmanagedType.U4)> ByVal reserved1 As Integer,
                      <[In], MarshalAs(UnmanagedType.U4)> ByVal reserved2 As Integer) As IStream

However, it results in the following error:

Attribue 'MarshalAsAttribute' cannot be applied to 'CreateStream' because the attribute is not valid on this declaration type.

I'm a little out of my depth here and would really appreciate any pointers you may have in helping me solve this issue.

Many thanks.

You can apply the attribute to the return value in this way:

Function CreateStream(<[In], MarshalAs(UnmanagedType.BStr)> ByVal pwcsName As String,
            <[In], MarshalAs(UnmanagedType.U4)> ByVal grfMode As Integer,
            <[In], MarshalAs(UnmanagedType.U4)> ByVal reserved1 As Integer,
            <[In], MarshalAs(UnmanagedType.U4)> ByVal reserved2 As Integer) As <MarshalAs(UnmanagedType.Interface)> IStream

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM