Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将C#封送处理接口代码转换为VB.NET的问题_C#_Vb.net - Fatal编程技术网

将C#封送处理接口代码转换为VB.NET的问题

将C#封送处理接口代码转换为VB.NET的问题,c#,vb.net,C#,Vb.net,我正在尝试将一个项目从C#转换为VB.NET,以便将Outlook消息拖放到我们的程序中 可以在CodeProject上找到原始源代码 我已经完成了95%的工作,但是在实现IStorage接口时遇到了问题,下面概述了其中的一部分 公共接口历史记录 { [返回:MarshalAs(UnmanagedType.Interface)] IStream CreateStream([In,marshallas(UnmanagedType.BStr)]字符串pwcsName, [In,marshallas(

我正在尝试将一个项目从C#转换为VB.NET,以便将Outlook消息拖放到我们的程序中

可以在CodeProject上找到原始源代码

我已经完成了95%的工作,但是在实现IStorage接口时遇到了问题,下面概述了其中的一部分

公共接口历史记录
{
[返回:MarshalAs(UnmanagedType.Interface)]
IStream CreateStream([In,marshallas(UnmanagedType.BStr)]字符串pwcsName,
[In,marshallas(UnmanagedType.U4)]int-grfMode,
[In,marshallas(UnmanagedType.U4)]int reserved1,
[In,marshallas(UnmanagedType.U4)]int reserved2);
}
我在VB.NET中将其转换为以下内容:


函数CreateStream(ByVal pwcsName作为字符串,
ByVal grfMode作为整数,
ByVal保留1为整数,
ByVal保留2作为整数)作为IStream
但是,它会导致以下错误:

属性“MarshalAsAttribute”无法应用于“CreateStream”,因为该属性在此声明类型上无效

我在这里有点不知所措,如果你能给我一些建议来帮助我解决这个问题,我将不胜感激


非常感谢。

您可以通过以下方式将属性应用于返回值:

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
函数CreateStream(ByVal pwcsName作为字符串,
ByVal grfMode作为整数,
ByVal保留1为整数,
ByVal保留2作为整数)作为IStream

正如IStream
应该做的那样(没有经过测试,我已经很久没有使用VB.NET了)。C#需要一个笨拙的
返回:
重写这样的属性,在VB.NET中,属性与声明保持得更自然。也许这会有帮助()顺便说一句,很好的双关语。:)