Help with API call?

I have an old API from a bas file, and I'm trying to convert it. I think I'm on the right track however, I keep running into some problems with it. I can post the old one, and the new one, with the edits that I've made. Is there anyone who would be able to assist me? I don't want someone to re-write the bas or module for me -- I'd like some pointers on where i'm going wrong, and where i've gone wrong and waht to change. Or, is this too much to ask for? I don't want to seem like I'm doing it for homework and want someone to help me -- I think I'm well passed the age of homework :-X lol

Feel free to post what you have. I woulkd suggest, though that if the code is lengthy and there are quite a few problems to break it down into several questions instead of one big massive one. This not only keeps the answers focused but also assists other members who might be researching solutions to the same problems.

The code is an old module, I think I have it worked out, so I might post original code first, my modded code, and questions on what I'm looking to achieve if possible? I remember you helping me a long time ago about putting the cart before the horse -- dude, i've come a long way and I appreciate the help :-) I'll post in a hot minute.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As Any, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
Private Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Long, riid As UUID, ByVal wParam As Long, ppvObject As Any) As Long
Private Const SMTO_ABORTIFHUNG = &H2
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Public Type YIMType
Text As String
HTML As String
End Type
Public Function GetIMText() As YIMType
Dim IMClass As Long
Dim MidWin As Long
Dim InternetExplorerServer As Long
'Loop through all the windows finding their handles from predefined classnames.
IMClass = FindWindow("imclass", vbNullString)
MidWin = FindWindowEx(IMClass, 0&, "ATL:004EFB68", vbNullString)
'Loop through all the windows finding their handles from predefined classnames.
If MidWin = 0 Then
MidWin = FindWindowEx(IMClass, 0&, "ATL:004F0BA8", vbNullString)
If MidWin = 0 Then
MidWin = FindWindowEx(IMClass, 0&, "ATL:004EEB68", vbNullString)
If MidWin = 0 Then MidWin = FindWindowEx(IMClass, 0&, "ATL:004EBB50", vbNullString)
End If
'If you have some errors with the pms not being open, use my API Spy available at www.EliteProdigy.com
'to get a new value for the ATL:004F0BA8, they seem to change that with every revision of their
'messenger program, no sweat tho, its easy find.
End If
InternetExplorerServer = FindWindowEx(atlefb, 0&, "internet explorer_server", vbNullString)
Stop
'The last window we need to find, is the window which the text is in.
'We grab its handle, and pass it into out GetText function.
GetIMText = GetIEText(InternetExplorerServer)
End Function
Private Function GetIEText(ByVal hWnd As Long) As YIMType
Dim doc As IHTMLDocument2
Dim col As IHTMLElementCollection2
Dim EL As IHTMLElement
Dim l As Long
Dim v1 As Variant
Dim v2 As Variant
Set doc = IEDOMFromhWnd(hWnd)
'Pass the data back through the function
On Error GoTo Ender:
GetIEText.Text = doc.body.innerText
GetIEText.HTML = doc.body.innerHTML
Exit Function
Ender:
GetIEText.Text = "No Chat Or Pm Open ?"
Err.Clear
End Function
Private Function IEDOMFromhWnd(ByVal hWnd As Long) As IHTMLDocument
Dim IID_IHTMLDocument As UUID
Dim hWndChild As Long
Dim spDoc As IUnknown
Dim lRes As Long
Dim lMsg As Long
Dim hr As Long
If hWnd <> 0 Then
'If the Handle is not 0, that means if the window is open .........
'We tell windows we are going in for the kill, and grabbing the data
lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT")
Call SendMessageTimeout(hWnd, lMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes)
If lRes Then
With IID_IHTMLDocument
.Data1 = &H626FC520
.Data2 = &HA41E
.Data3 = &H11CF
.Data4(0) = &HA7
.Data4(1) = &H31
.Data4(2) = &H0
.Data4(3) = &HA0
.Data4(4) = &HC9
.Data4(5) = &H8
.Data4(6) = &H26
.Data4(7) = &H37
End With
hr = ObjectFromLresult(lRes, IID_IHTMLDocument, 0, IEDOMFromhWnd)
'We pass the data back from the function.
End If
End If
End Function

So the above is the code that I'm working with. I've gotten around to most of it and the use of type is no longer supported in VB 2010. The next segment is a listing of what I have done but it is still FAR off... Any suggestions?

"...This is what you need to work with most of the structures defined in the Windows API and C/C++..."

To use "StructLayout", add the following imports statement: "Imports System.Runtime.InteropServices".

Before specifying the data types for the parameters it is necessary to look at the definition of the Win API that you want to use. For example, look at GetClassName (see "Windows Data Types" at the end of this post for more info.)

Additionally in some instances you may need to use "System.Runtime.InteropServices.DllImport" (add "Imports System.Runtime.InteropServices").

Additionally, when looking up a Win API definition, if you see a parameter with "Out" (or "In_Out"...or some version that contains the word "Out"), use "ByRef" instead of "ByVal" and ensure that the variable that you are passing it back to has been initialized. An example would be GetWindowRect.

<DllImport("user32.dll", EntryPoint:="GetWindowRect")>
Public Function GetWindowRect(ByVal hwnd As Integer, ByRef lpRect As Rectangle) As Boolean
End Function

Dude, I wasn't expecting all this. I greatly appreciate what you've done here. I'm going to mess with this and incorporate it... In time to come I might PM you regarding something related to the project that I am working on -=]

Hi. so this is actually a continuation from another question of mine[Here](https://www.daniweb.com/programming/software-development/threads/506795/dynamically-add-values-into-datagridview-cell-from-listbox-vb2010) but i was advised to start a new thread as the original question …

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...