Ok I suppose this error isn't new at all to some of us, who has coded something having to deal with local hooks in vb.net
Code Unable to find an entry point named 'GetForegroundWindow' in DLL 'user32.dll'.
Code Private Declare Function GetForegroundWindow Lib "user32" () As Int32
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Function GetActiveWindowTitle() As String
Dim MyStr As String
MyStr = New String(Chr(0), 100)
GetWindowText(GetForeGroundWindow, MyStr, 100)
MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
Return MyStr
End Function
Now it throws back this very funny error. I saw an example which compiled successfully without problems. Now I try to compile the same on visual studio 2012 I get this very annoying error. Now I sit and ask, what the fuck is wrong? Like I don't seem to know what's wrong! Pls Help.
As long ? I guess you're using a old signature, please look here : http://msdn.microsoft.com/en-us/library/...s.85).aspx
Aug 29, 2014 04:00 AM
(This post was last modified: Aug 29, 2014 04:02 AM by Menalix.)
Well the API Parameters for all API's is not right, so that could be a start.
Yeah. P/Invoke provides the updated signature for .NET, you're using the old VB signature.
Once that's fixed and you have the APIs declared, it's a 1 liner (if you want it to).
Ok, changed to Integer and int32, still the same stupid error. What's wrong ! I followed a video of it in which a guy used VS 2010 and it compiled without errors.
I am coding with visual studio 2012, could it be compactibility issues?
Aug 29, 2014 04:14 AM
(This post was last modified: Aug 29, 2014 04:56 AM by Washi.)
(Aug 29, 2014 04:06 AM)log dot zip Wrote: Yeah. P/Invoke provides the updated signature for .NET, you're using the old VB signature.
Once that's fixed and you have the APIs declared, it's a 1 liner (if you want it to).
![[Image: oOC9U8O.png]](https://i.imgur.com/oOC9U8O.png)
Yea only if you want to return a number and not a string >_>.
PInvoke declarations:
PHP Code
<?php <DllImport("user32.dll", SetLastError:=True)> _ Private Shared Function GetForegroundWindow() As IntPtr End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer End Function
DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer End Function
And for the usage:
PHP Code
<?php Dim windowHandle = GetForegroundWindow() Dim builder As New StringBuilder(GetWindowTextLength(windowHandle)) Dim length = GetWindowText(windowHandle, builder, builder.Capacity) Dim windowText = builder.ToString()
Aug 29, 2014 04:18 AM
(This post was last modified: Aug 29, 2014 04:21 AM by Menalix.)
(Aug 29, 2014 04:10 AM)javiermad Wrote: Ok, changed to Integer and int32, still the same stupid error. What's wrong ! I followed a video of it in which a guy used VS 2010 and it compiled without errors.
I am coding with visual studio 2012, could it be compactibility issues?
......
Integer and int32 is the same.
If that's on the forground api it should be intptr
Dont use Pinvoke all what they provide for vb.net is very wrong which makes them incompitable when the process is running in 64bit
(Aug 29, 2014 04:18 AM)Menalix Wrote: ......
Integer and int32 is the same.
If that's on the forground api it should be intptr
Dont use Pinvoke all what they provide for vb.net is very wrong which makes them incompitable when the process is running in 64bit
@Menalix, what do I use then? Could u kindly show me? I am kinda lost here. Pls.
(Aug 29, 2014 04:15 AM)TheUnknownProgrammer Wrote: Yea only if you want to return a number and not a string >_>.
PInvoke declarations:
PHP Code
<?php <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer End Function
DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer End Function
And for the usage:
PHP Code
<?php Dim windowHandle = GetForegroundWindow() Dim builder As New StringBuilder(GetWindowTextLength(windowHandle)) Dim length = GetWindowText(windowHandle, builder, builder.Capacity) Dim windowText = builder.ToString()
Oops. Did not debug code before posting. Bad idea.
Heres a shorter example, that returns a string.
If you're going for readability though, TUPPES example is the way to go.
Declarements:
Usage:
I recently started finding interesting functions on pinvoke.com. The site is very nice, you can see the declarations, custom types, sample code and description. Trust me, it's a lot of fun.
Aug 29, 2014 11:01 AM
(This post was last modified: Aug 29, 2014 11:02 AM by Menalix.)
(Aug 29, 2014 07:14 AM)SIM-1456245 Wrote: I recently started finding interesting functions on pinvoke.com. The site is very nice, you can see the declarations, custom types, sample code and description. Trust me, it's a lot of fun. Funnier to just load kernel32.dll up in IDA or Ollydbg and look around, and find structures you need in the c++ header files.
All pinvoke.com's parameters is wrong, I guess they just use a c# to VB.net converter, and that's why it's all wrong.
(Aug 29, 2014 07:14 AM)SIM-1456245 Wrote: I recently started finding interesting functions on pinvoke.com. The site is very nice, you can see the declarations, custom types, sample code and description. Trust me, it's a lot of fun. The parameters on the website is wrong.
It's funnier to just load kernel32, user32 and so on up in IDA or Ollydbg and look around.
(Aug 29, 2014 07:14 AM)SIM-1456245 Wrote: I recently started finding interesting functions on pinvoke.com. The site is very nice, you can see the declarations, custom types, sample code and description. Trust me, it's a lot of fun.
I think it's pinvoke.net & not pinvoke.com... as i too try to learn from here.. ;)
BTC - bc1q3efew3yzfwhdz290dafykaw0a2w56g2j69g2c6
ETH - 0xf1c873217032468990D3313da6509D1b813c4671
USDT - 0xf1c873217032468990D3313da6509D1b813c4671
PP - [email protected]
(Aug 29, 2014 11:01 AM)Menalix Wrote: Funnier to just load kernel32.dll up in IDA or Ollydbg and look around, and find structures you need in the c++ header files.
All pinvoke.com's parameters is wrong, I guess they just use a c# to VB.net converter, and that's why it's all wrong.
The parameters on the website is wrong.
It's funnier to just load kernel32, user32 and so on up in IDA or Ollydbg and look around.
Not sure why you would waste time doing that tbh, APIs have multiple signatures. As long as you dont use non-primitive "types" it will work or create your own structures to hold the values.
Or more dirty :
PHP Code
<?php <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _ Private Shared Function GetWindowText(ByVal hwnd As IntPtr, <Out> ByVal lpString As IntPtr, ByVal cch As Integer) As Integer End Function
Dim dataStr As IntPtr = Marshal.AllocHGlobal(255) If GetWindowText(Handle, dataStr, 255) = 0 Then Throw New System.ComponentModel.Win32Exception() End If MsgBox(Marshal.PtrToStringAuto(dataStr))
(Aug 29, 2014 03:25 AM)javiermad Wrote: Ok I suppose this error isn't new at all to some of us, who has coded something having to deal with local hooks in vb.net
Code Unable to find an entry point named 'GetForegroundWindow' in DLL 'user32.dll'.
Code Private Declare Function GetForegroundWindow Lib "user32" () As Int32
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Function GetActiveWindowTitle() As String
Dim MyStr As String
MyStr = New String(Chr(0), 100)
GetWindowText(GetForeGroundWindow, MyStr, 100)
MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
Return MyStr
End Function
Now it throws back this very funny error. I saw an example which compiled successfully without problems. Now I try to compile the same on visual studio 2012 I get this very annoying error. Now I sit and ask, what the fuck is wrong? Like I don't seem to know what's wrong! Pls Help.
Here you go OP: Should work now.
Code Private Declare Function GetForegroundWindow Lib "user32.dll" () As Int32
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
Private Function GetActiveWindowTitle() As String
Dim MyStr As String
MyStr = New String(Chr(0), 100)
GetWindowText(GetForegroundWindow, MyStr, 100)
MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
Return MyStr
End Function
Ok had a fight with it, glad it works now. Thanks a whole lot guys. You guys are the best. I am very grateful
How ever it doesn't send logs tho, but I am working on it to see what it can do
Just sends data like
Time. And date and the process
Like this. I followed this source code https://hackforums.net/printthread.php?tid=871861
Code 28/09/2014 09:38:35
Notepad
It doesn't send the data typed in.. Others are working cool, just wondering
|