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 7523865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:55:32+00:00 2026-05-30T02:55:32+00:00

I am trying to import the GetWindowText in a VB.NET application. So based on

  • 0

I am trying to import the GetWindowText in a VB.NET application.

So based on other sites you just have to import the interopt service and add a DLLImport statement similar to C#. But somehow it is not recognizing the statement and getting a BC30001 (Statement is not valid in a namespace) compile error.

Here is the code I used.

Imports System.Runtime.InteropServices

<DllImport("user32", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function GetWindowText(ByVal hWnd As IntPtr, <Out(), MarshalAs(UnmanagedType.LPTStr)> ByVal lpString As StringBuilder, ByVal nMaxCount As Integer) As Integer
End Function

What assembly do I need to import to make this work? Any ideas?

  • 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-05-30T02:55:33+00:00Added an answer on May 30, 2026 at 2:55 am

    The problem has nothing to do with importing assemblies. You simply cannot define free functions in a namespace in VB.NET.

    You have to place them in either a Module (basically a static class) or a Class.

    It’s recommended you place native Win32 functions in a class named NativeMethods anyway, so rewrite your code to look like this:

    Imports System.Runtime.InteropServices
    
    Friend Class NativeMethods
    
        <DllImport("user32", CharSet:=CharSet.Auto, SetLastError:=True)> _
        Public Shared Function GetWindowText(ByVal hWnd As IntPtr,
            <Out(), MarshalAs(UnmanagedType.LPTStr)> ByVal lpString As StringBuilder,
            ByVal nMaxCount As Integer) As Integer
        End Function
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to import an access database to mysql. I have created a
I'm trying to import a IntelliJ java web application project (Maven Project) from a
I am trying to import data from Access to Excel based on two parameters.
I am trying to import one python script from another. I have a few
I'm trying to import a model from a Django application and getting an error:
I'm trying to import some data from Excel to SQL Server, I have a
I am trying to import each story into an object. Each object will have
I am trying to import RSA private keys into the keychain using my application.
I am trying to import a wordpress database to other server, but that server
I am trying to import details from an access database into my sql application

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.