-
May 22nd, 2022, 10:26 AM
#1
Thread Starter
Addicted Member
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
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
-
May 22nd, 2022, 10:50 AM
#2
Thread Starter
Addicted Member
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
-
May 22nd, 2022, 08:07 PM
#3
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.
-
May 22nd, 2022, 11:39 PM
#4
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|