VB.Net app not working on 32 bit machines

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BHo15
    New Member
    • Feb 2014
    • 143

    VB.Net app not working on 32 bit machines

    I have an app that is a long time in the making and has had a lot of excellent input from others on. It runs great on 64 bit machines, but breaks down on any of the 32 machines I've run it on.

    The app is designed to log on to the OpenDNS website, and then pull the history of URL visits from my router. It then dumps this to a CSV file, then saves it to Excel after sorting and removing fluff.

    Because testing this requires an OpenDNS account, it may be hard for you all to test. But I'm hoping someone can look at the code, and see if they see anything that would be different for 64 bit vs 32 bit machines.

    It appears to get through the first call to GetUrlData (data = GetUrlData(URL & "/signin", "GET", "")), but then doesn't come up with any data on the second call (data = GetUrlData(URL & "/signin", "POST", "formtoken= " & token & "&username= " & strUser & "&password= " & strPW & "&sign_in_submi t=foo")). Therefore, I get the message "Please check your username and password.").

    Here is the main sub...

    Code:
        Private Sub btnFetch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFetch.Click
    
            My.Settings.Save()
    
            btnFetch.Text = "Processing"
            Dim strUser As String = txtUser.Text
            Dim strNet As String = txtNetwork.Text
            Dim strBDate As String = txtBDate.Text
            Dim strEDate As String = txtEDate.Text
            Dim strPW As String = RC4(txtPW.Text, strK)
            Dim DateRange As String = strBDate & "to" & strEDate
            Dim page As Integer = 1
            Dim objWriter As New System.IO.StreamWriter(CurPath & "DNLD.csv", False)
            Dim i As Integer = 1
    
            data = GetUrlData(URL & "/signin", "GET", "")
    
            MsgBox(i)
            i = i + 1
    
            Dim Matches As Match = Regex.Match(data, ".*name=""formtoken"" value=""([0-9a-f]*)"".*")
            Dim token As String = Matches.Value.Substring(Matches.Value.IndexOf("formtoken") + 18)
            token = token.Substring(0, token.IndexOf(Chr(34)))
    
            data = GetUrlData(URL & "/signin", "POST", "formtoken=" & token & "&username=" & strUser & "&password=" & strPW & "&sign_in_submit=foo")
    
            MsgBox(i)
            i = i + 1
    
            If Len(data) <> 0 Then
                MsgBox("Please check your username and password.")
                Me.btnFetch.Text = Nothing
                Exit Sub
            End If
    
            Do While True
                data = GetUrlData(URL & "/stats/" & strNet & "/topdomains/" & DateRange & "/page" & page & ".csv", "GET", "")
    
                MsgBox(i)
    
                If page = 1 Then
                    If Len(data) = 0 Then
                        MsgBox("Please check your network." & strNet & vbCrLf)
                        Me.btnFetch.Text = Nothing
                        Exit Sub
                    ElseIf InStr(data, "<!DOCTYPE") Then
                        MsgBox("Error retrieving data. Date range may be outside of available data.")
                        Me.btnFetch.Text = Nothing
                        Exit Sub
                    End If
                Else
                    data = Mid(data, InStr(data, vbLf) + 1)
                End If
                If Len(Trim(data)) = 0 Then
                    Exit Do
                End If
    
                objWriter.WriteLine(data)
                page = page + 1
    
                i = i + 1
    
            Loop
            objWriter.Close()
    
            Call ProcessExcel(CurPath)
    
            'The Excel Module closes the application after finish.
    
        End Sub


    And here is the GetUrlData Function...

    Code:
        Private Function GetUrlData(ByVal strUrl, ByVal strMethod, ByVal strData)
    
    
            objHTTP.Open(strMethod, strUrl)
    
            If strMethod = "POST" Then
                objHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
            End If
    
            objHTTP.Option(6) = False
    
            objHTTP.Send(strData)
    
            If Err.Number <> 0 Then
    
                GetUrlData = "ERROR: " & Err.Description & vbCrLf & Err.Source & " (" & Err.Number & ")"
            Else
    
                GetUrlData = objHTTP.ResponseText
            End If
    
        End Function
  • BHo15
    New Member
    • Feb 2014
    • 143

    #2
    If it helps any, I've used some msgbox's to test the variables in this trouble section. On the 2nd call to GetUrlData (data = GetUrlData(URL & "/signin", "POST", "formtoken= " & token & "&username= " & strUser & "&password= " & strPW & "&sign_in_submi t=foo")), all of the variables are populated (token, strUser, and strPW).

    So if anyone has any thoughts on how I could troubleshoot (step through, use msgbox's, etc) the GetUrlData Function, that would be helpful.

    Thanks,
    Brad

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      The program was compiled as 32-bit? I'm part of the C/C++ world and a 64-bit program will never work on a 32-bit machine. Just curious.

      Comment

      • BHo15
        New Member
        • Feb 2014
        • 143

        #4
        Thanks for the insight. Unfortunately (this is where the true programmers role their eyes), I don't have enough knowledge to know how it was compiled. I am using Visual Studio Express, and I never had to formally compile it to use the exe that was automatically created. If someone has insight on how to compile differently for 32 vs 64 bit in Visual Studio Express, I am all ears.

        That said, the section that is having trouble is just going out to a website, logging in, and pulling data. Why would that act any differently between 32 bit and 64 bit?

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          There are different Visual Studio products for 32 and 64 bit. In my case I can only create a Win32 project which gives me a 32-bit object file. On the 64-bit operating system this 32-bit program won't run because of instruction set incompatibility . However, Microsoft has written a dll called WOW (windows-on-windows)which reads my 32-bit program as data and quick like a bunny translates the instructions to 64-bit. The effect is that 32-bit programs appear to run on the 64-bit machine. Naturally, they run slower due to the machinations of WOW.

          However, this does not work the other way. There is no support for 64-bit code on a 32 bit OS.

          If your Visual Studio express has a Win32 project capability, then create a Visual Basic project, add your code files and build. The resultant code will work on the 32bit OS and because of WOW will also run (slower) on a 64bit OS.

          I am curious now so please let me know what happens.

          Comment

          • BHo15
            New Member
            • Feb 2014
            • 143

            #6
            I read up a bit on how to compile in 32 bit, and I saw to chose x86 as the platform target. I did this, then select Build Solution, and it apparently completed with 2 warnings...

            C:\Program Files (x86)\MSBuild\1 2.0\bin\Microso ft.Common.Curre ntVersion.targe ts(2151,5): warning MSB3284: Cannot get the file path for type library "2df8d04c-5bfa-101b-bde5-00aa0044de52" version 2.5. Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTR EGISTERED))

            C:\Program Files (x86)\MSBuild\1 2.0\bin\Microso ft.Common.Curre ntVersion.targe ts(2151,5): warning MSB3284: Cannot get the file path for type library "00020813-0000-0000-c000-000000000046" version 1.7. Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTR EGISTERED))

            Not sure what these are. Could they be causing the problem? No change in results when I ran it.

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              Maybe this will help: http://vb.mvps.org/hardcore/html/whatistypelibrary.htm

              Comment

              • BHo15
                New Member
                • Feb 2014
                • 143

                #8
                So I tried adding a reference to one of these type libraries (WIN.TLB or WIN32API.TXT). I didn't see any of them as a choice in the Type Libraries listed. I did add a reference to Win32_TPM 1.0 Type Library, with no change in function.

                Do I need to download one of those 2 type libraries specifically?

                Comment

                • weaknessforcats
                  Recognized Expert Expert
                  • Mar 2007
                  • 9214

                  #9
                  The type libraries are part of COM which underlies VB Automation by implementing IDispatch. There libraries need to be registered. I expect there is a RegTypeLib call in there somewhere with an argument for the type library GUID but no way for the compiler to figure out the path to the type library so it can b registered.

                  I suspect you will need a better VB man then me.

                  Comment

                  • BHo15
                    New Member
                    • Feb 2014
                    • 143

                    #10
                    Thanks so much for your insight. I wish I had the skill to carry out the references to the libraries that you are talking about. Maybe eventually. :)

                    So the gauntlet has been thrown... Any "better VB men" (or women) want to chime in?

                    Comment

                    • Luk3r
                      Contributor
                      • Jan 2014
                      • 300

                      #11
                      Heya, Brad! Long time no chat. I decided to go back through your project and I noticed that you are referencing Microsoft Excel and Office 14.0. Are your 32bit machines running Office 2010? Microsoft Excel and Microsoft Office 12.0 Object Library would need to be used for Excel/Office 2007.

                      Also, I tested the application on a 32 bit machine just now and I was getting the same error.. telling me that my username or password was wrong. So I very slowly typed my password using the keypad for numbers and making sure I only typed 1 letter at a time and I got past the invalid username/password but was faced with the application telling me it was trying to access memory that was corrupt. I finally decided to take off the masking of the password and noticed that it was turning my password into this: —¢aËzàæ....Th at's definitely not what I was typing. I realized it was the encryption you were doing. So, I modified the code to use no encryption and it worked...part of the time. The way your events are setup to store data is a bit off. I may not always "leave" a textbox, which means it doesn't have anything new stored, hence, forgetting my username, network, and/or password. I was still getting the corrupt memory issue but I guess we can work on that when the time comes and after you've figured out how you'd like to fix what I've mentioned. On another note, I don't know that you can use RC4 encryption for a password and have no method of deciphering. You'd have to set up some sort of decipher method for that encryption for the password to be properly read and used in the URL when connecting to OpenDNS.com.

                      Comment

                      • BHo15
                        New Member
                        • Feb 2014
                        • 143

                        #12
                        Greetings Luke! Glad you jumped in!

                        With regards to the Office 2010... There may be some users that have 2010, but most will have 2007. But... The errors, as you can see, are happening before it even gets to the Excel portion of the code.

                        The errors that you got are exactly what I am getting. The RC4 encryption actually does have a decryption piece to it, but maybe for some reason it is not working consistently on 32 bit machines?

                        This is what I have for the password field, and saving it to the My.Settings.

                        Code:
                            Private Sub PWChg(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPW.Leave
                                My.Settings.appPW = RC4(Me.txtPW.Text, strK)
                                Me.txtPW.Text = My.Settings.appPW
                            End Sub

                        Do you think that using the "on leave" event is the wrong way to do that?

                        Comment

                        • BHo15
                          New Member
                          • Feb 2014
                          • 143

                          #13
                          I just tried without any encryption, and still got the Username/Password error (worked great with Win 7 - 64 bit).

                          Comment

                          Working...