GetShortPathName 使用问题

哈利路亚1231 2015-09-17 03:37:28
声明
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
使用
dim p as string=""
Dim sbtemp1 As String = p
Dim n As Long = GetShortPathName(p, sbtemp1, 255)
p = Left(sbtemp1, n)


调试执行方法前 p的值:C:\Users\huanghaic\Desktop\1111\GenDoUtil\DEComPressTemp\1700_0_TFTM_3_AH_2015081801.zip
执行方法后sbtemp1的值:C:\Users\HUANGH~1\Desktop\1111\GENDOU~1\DECOMP~1\1700_0~1.ZIP 0_TFTM_3_AH_2015081801.zip
执行方法后n的值:816043786301
然后在执行到 Left(sbtemp1, n)时抛出异常:算术运算导致溢出。
这是为什么?我怀疑是返回值n不正确。
请大神亲们帮忙指点
...全文
276 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tiger_Zhao 2015-09-17
  • 打赏
  • 举报
回复
Imports System.Runtime.InteropServices

Module Module1

<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Function GetShortPathName(<[In]()> ByVal path As Char(), <Out()> ByVal shortPathBuffer As Char(), ByVal bufferLength As Integer) As Integer
End Function

Sub Main()
Dim p As String = "C:\Users\huanghaic\Desktop\1111\GenDoUtil\DEComPressTemp\1700_0_TFTM_3_AH_2015081801.zip"
Dim shortPathBuffer As Char() = New Char(260) {}
Dim n As Integer = GetShortPathName(p, shortPathBuffer, 260)
p = Left(shortPathBuffer, n)

Console.WriteLine(n)
Console.WriteLine(p)
Console.ReadLine()
End Sub

End Module

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧