【发布时间】:2015-03-27 16:13:11
【问题描述】:
我是 VB 的新手,正在处理 VB6 到 VB.net 的迁移。有一个 API 调用会在临时文件名中附加一个前缀。
我已将 dll 添加为
<DllImport("kernel32")> _
Private Shared Function GetTempFileName(ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
End Function
当我打电话给这个时:
test = GetTempFileName(My.Application.Info.DirectoryPath, Prefix, 0, m_sTempfile)
抛出异常:
An unhandled exception of type 'System.AccessViolationException' occurred in Forum.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
我尝试使用 Path.GetTempFileName() 但我可能需要执行几个操作来获取以特定单词为前缀并位于特定位置的文件名。 我交叉检查了这些值,它们不是坏数据。 我尝试了多种解决方案,但都没有奏效。 有人可以帮忙吗?提前致谢!
【问题讨论】:
-
在 NET 中使用
System.IO.Path.GetTempFileName()并摆脱 PInvoke -
由于我的要求是:需要创建一个具有特定前缀的临时文件并在特定位置创建,我必须操作 GetTempFileName(),还是我们有相同的方法?