Results 1 to 4 of 4

Thread: Import DLL - Convert c#>VB Error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    213

    Import DLL - Convert c#>VB Error

    Hi,

    Trying to convert some c# code to VB, but isn't working.

    Error: 'System.Runtime.InteropServices.DllImportAttribute' cannot be applied to a Declare.


    Thanks in advance

    Name:  dllerror1.jpg
Views: 173
Size:  38.6 KB
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    My Website
    VSCOMM 2022 LAZARUS 2.2.0 Win10 16G RAM Nivida GForce RTX 2060

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    213

    Re: Import DLL - Convert c#>VB Error

    Okay, realized it needs to be shared.

    How this? Does this look right?

    Code:
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function
    
        <DllImport("user32.dll")>
        Shared Function ReleaseCapture() As Boolean
        End Function
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    My Website
    VSCOMM 2022 LAZARUS 2.2.0 Win10 16G RAM Nivida GForce RTX 2060

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,516

    Re: Import DLL - Convert c#>VB Error

    Using Declare is the old VB6 way of declaring an external function so it still exists in VB.NET for compatibility. The DllImportAttribute is the .NET way of declaring an external function. You don't use both together.

    Your VB looks OK in principle but, if you want to know whether it's an accurate translation of some C# code, we'd need to see the C# code too.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,822

    Re: Import DLL - Convert c#>VB Error

    If you're trying to drag a Form or a Control...
    (To drag a Control is slightly different)

    Code:
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        Me.Capture = False
    
        Const WM_NCLBUTTONDOWN As Integer = &HA1
        Const HTCAPTION As Integer = &H2
    
        Dim msg As Message = _
            Message.Create(Me.Handle, WM_NCLBUTTONDOWN, _
                New IntPtr(HTCAPTION), IntPtr.Zero)
    
        Me.DefWndProc(msg)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width