D
Dragon
Hello,
This is the code:
~
Option Strict On
Imports System
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Class Test
Inherits Form
Friend Declare Auto Function GetWindowText Lib "user32.dll" ( _
ByVal hWnd as IntPtr, _
<MarshalAs(UnmanagedType.LPTStr), [In](), Out()> ByVal lpString As
String, _
ByVal nMaxCount as Integer _
) As Integer
Protected Overrides Sub OnLoad(e as EventArgs)
MyBase.OnLoad(e)
Text() = "All right!"
Dim tempStr As New String(chr(0),256)
Dim Result as Integer = GetWindowText(Me.Handle, tempStr,
tempStr.Length)
MessageBox.Show(Result.ToString & " " tempStr)
End Sub
<STAThread()> Shared Sub Main()
Application.Run(New Test)
End Sub
End Class
~
I expected it to msgbox "10 All right!" and it did it. In Windows XP.
But... testing it in Windows 98 gave strange result: "10 ". For some
curious reason string wasn't marshalled back, even though I included
OutAttribute.
However when I removed all attributes, it worked fine it both OS'es.
What's the difference? Is it documented or bug?
TIA
Roman
This is the code:
~
Option Strict On
Imports System
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Class Test
Inherits Form
Friend Declare Auto Function GetWindowText Lib "user32.dll" ( _
ByVal hWnd as IntPtr, _
<MarshalAs(UnmanagedType.LPTStr), [In](), Out()> ByVal lpString As
String, _
ByVal nMaxCount as Integer _
) As Integer
Protected Overrides Sub OnLoad(e as EventArgs)
MyBase.OnLoad(e)
Text() = "All right!"
Dim tempStr As New String(chr(0),256)
Dim Result as Integer = GetWindowText(Me.Handle, tempStr,
tempStr.Length)
MessageBox.Show(Result.ToString & " " tempStr)
End Sub
<STAThread()> Shared Sub Main()
Application.Run(New Test)
End Sub
End Class
~
I expected it to msgbox "10 All right!" and it did it. In Windows XP.
But... testing it in Windows 98 gave strange result: "10 ". For some
curious reason string wasn't marshalled back, even though I included
OutAttribute.
However when I removed all attributes, it worked fine it both OS'es.
What's the difference? Is it documented or bug?
TIA
Roman