我有下面的代码来使用 Shell32 dll 加载图标。它在我的机器上运行良好。但是生产环境中的一个系统出现异常,提示“System.ArgumentException:传递给 Icon 的 Win32 句柄无效或类型错误”。知道为什么我们会收到此错误吗?谢谢!
Public Function GetExecutableIcon() As Icon
Dim large As IntPtr
Dim small As IntPtr
ExtractIconEx(Application.ExecutablePath, 0, large, small, 1)
Return Icon.FromHandle(small)
End Function
<DllImport("Shell32")> _
Public Shared Function ExtractIconEx(ByVal sFile As String, ByVal iIndex As Integer,
ByRef piLargeVersion As IntPtr, ByRef piSmallVersion As IntPtr,
ByVal amountIcons As Integer) As Integer
End Function