0

我正在尝试使用文件流从我的资源中获取 *.exe 文件。我的代码是这样的:filerdr = New FileStream(My.Resources.ResourceManager.GetStream("filename.exe"), FileMode.Open) 但我得到了这个错误

Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(handle As Microsoft.Win32.SafeHandles.SafeFileHandle, access As System.IO.FileAccess)': Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to 'Microsoft.Win32.SafeHandles.SafeFileHandle'.
'Public Sub New(handle As System.IntPtr, access As System.IO.FileAccess)': Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to 'System.IntPtr'.
'Public Sub New(path As String, mode As System.IO.FileMode)': Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to 'String'.

我也试过:filerdr = New FileStream(My.Resources.filename.exe, FileMode.Open

但仍然没有运气,请不要给我解决方法,请告诉我如何按照我想要的方式执行此操作。

我想添加FileMode.Open然后将其与另一个文件进行比较,通过使用

If filerdr.ReadByte = filerdr2.ReadByte AndAlso 
     filerdr.Length = filerdr2.Length  Then 
'''''''''''' 
End If 
4

1 回答 1

0

我找到了解决方案。首先我必须将我的变量“filerdr”从 FileStream 更改为 UnmanagedMemoryStream,然后我必须从这里编辑 Resources.resx

<data name="MyFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MyFile.exe;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>

对此

<data name="MyFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MyFile.exe;System.IO.MemoryStream, mscorlib, Version=2.0.0.0,            Culture=neutral, PublicKeyToken=b77a5c561934e089</value>

简而言之。System.Byte[] 到 System.IO.MemoryStream。这解决了问题,我的代码开始工作。

于 2013-10-13T22:03:27.583 回答