Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:21:23+00:00 2026-06-13T23:21:23+00:00

Can somebody explain how it can be that the same API call returns so

  • 0

Can somebody explain how it can be that the same API call returns so much quicker with VB6 than with VB.NET?

Here is my VB6 code:

Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long


Public Function GetWindowTextEx(ByVal uHwnd As Long) As String

Dim lLen&
lLen = GetWindowTextLength(uHwnd) + 1

Dim sTemp$
sTemp = Space(lLen)

lLen = GetWindowText(uHwnd, sTemp, lLen)

Dim sRes$
sRes = Left(sTemp, lLen)

GetWindowTextEx = sRes

End Function

And here is my VB.NET code:

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpWindowText As String, ByVal cch As Integer) As Integer

    Dim sText As String = Space(Int16.MaxValue)
    GetWindowText(hwnd, sText, Int16.MaxValue)

I ran each version 1000 times.

The VB6 version needed 2.04893359351538 ms.
The VB.NET version needed 372.1322491699365 ms.

Both Release and Debug version are about the same.

What is happening here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:21:23+00:00Added an answer on June 13, 2026 at 11:21 pm

    Do not use the *A version, just skip the suffix, and use StringBuilder instead of String:

    Private Declare Auto Function GetWindowText Lib "user32" (ByVal hwnd As Integer, ByVal lpWindowText As StringBuilder, ByVal cch As Integer) As Integer
    Private Declare Function GetWindowTextLength Lib "user32" (ByVal hwnd As Integer) As Integer
    
    Dim len As Integer = GetWindowTextLength (hwnd)
    Dim str As StringBuilder = new StringBuilder (len)
    GetWindowText (hwnd, str, str.Capacity)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody explain why the .Net framework team decided that a delegate without subscribers
Can somebody explain to me what the below code is doing. before and after
Can somebody explain why the following code is not valid? Is it because the
can somebody please explain is it possible to convert this snippet of the code
Can somebody explain (better than the technet/msdn docs) what the auto provider exactly does,
Can somebody explain me what the following bit of code in Matlab is doing?
Can somebody explain to me what this does in javascript? (function (x,y){}(x,y)); or this
Can somebody explain to me why the following works: template<class T> class MyTemplateClass {
Can somebody explain the main differences between (advantages / disadvantages) the two implementations? For
Can somebody explain me one thing. I have two methods in my controller :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.