Announcement

Collapse
No announcement yet.

Creating a DUN File

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    And he keeps learning.... No answer in sight yet, but close.
    It's a problem in the include file so far as I can tell???


    From Microsoft:
    http://msdn.microsoft.com/library/ps...sclnt_3bub.htm

    Code:
    RasEnumDevices(NULL, &lpcb, &lpcDevices);
    lpRasDevInfo = (LPRASDEVINFO) GlobalAlloc(GPTR, lpcb);
    lpRasDevInfo->dwSize = sizeof(RASDEVINFO);
     
    nRet = RasEnumDevices(lpRasDevInfo, &lpcb, &lpcDevices);
    if (nRet != 0)
    {
        printf("RasEnumDevices failed: Error %d", nRet);
    }
    else
    {
        printf("The following RAS capable devices were found on this machine:\n\n");
        for (i=0; i < lpcDevices; i++)
        {
            printf("%s\n",lpRasDevInfo->szDeviceName);
            lpRasDevInfo++;
        }
    }
    
    
    We're close!
    '
    '
    I'm getting the last error, buffer too small:
    
    lResult = RasEnumDevices(ByVal %NULL, cb, count)
    Select Case lResult
           Case %ERROR_INVALID_USER_BUFFER
                MsgBox "Invalid User Buffer",%MB_ICONSTOP,"DEBUG"
                Exit Function
           Case %ERROR_INVALID_PARAMETER
                MsgBox "Invalid Parameter",%MB_ICONSTOP,"DEBUG"
                Exit Function
           Case %ERROR_NOT_ENOUGH_MEMORY
                MsgBox "Not enough memory",%MB_ICONSTOP,"DEBUG"
                Exit Function
           Case %ERROR_BUFFER_TOO_SMALL
                MsgBox "Buffer too small",%MB_ICONSTOP,"DEBUG"
                Exit Function
    End Select
    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #22
      I'm convinced it's a pointer to a structure that is failing us.

      Now, Microsoft states the following:

      Parameters
      lpRasDevInfo
      [in] Pointer to a buffer that receives an array of RASDEVINFO structures, one for each RAS-capable device. Before calling the function, set the dwSize member of the first RASDEVINFO structure in the buffer to sizeof(RASDEVINFO) to identify the version of the structure.
      lpcb
      [in, out] Pointer to a variable that, on input,contains the size, in bytes, of the lpRasDevInfo buffer.
      On output, the function sets this variable to the number of bytes required to enumerate the devices.

      To determine the required buffer size, call RasEnumDevices with the lpRasDevInfo parameter set to NULL and the variable pointed to by lpcb set to zero. The function returns the required buffer size in the variable pointed to by lpcb. (See sample code under Remarks section.)

      lpcDevices
      [out] Pointer to a variable that receives the number of RASDEVINFO structures written to the lpRasDevInfo buffer.

      But I have seen in teh past where PB fails because of the use of LEN vs the use of SIZEOF.

      Notice the code, and it will not take a SIZEOF either!

      Dim rdi(1 To count) As RASDEVINFO
      rdi(1).dwSize = Len(RASDEVINFO)


      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #23
        Hiya I see we're both posting at the same time!
        I am very close here, I feel it, I have the same issue, no buffer returned but I put the debug code in to show WHY no buffer is returned.

        Always "INVALID USER BUFFER", Hence it won't return it, so we go back and find that a pointer is pointing to the wrong STRUCTURE or TYPE or SOMETHING!!


        RasEnumDevices is failing the 2nd time around.
        Got this one down pretty good now.
        You call it once to return pointer information.

        But I am correctly setting the buffer size at 150 by calling it the first time, Then we do this:

        and it fails with invalid USER buffer now, but I believe this is close, VERY VERY close:


        Code:
          'Null is sent
          lResult = RasEnumDevices(ByVal %NULL, cb, count)
          If IsFalse count Then
            MsgBox "No modems were found!", %MB_ICONSTOP,"Computer Creations Software"
            Exit Function
          End If
        
          cb = Len(RASDEVINFO) * count
          Dim rdi(1 To count) As RASDEVINFO
          rdi(1).dwSize = Len(RASDEVINFO)
        
          'This is weird, use a byval and pointer for null, and now not use a pointer but send the string??
          'Something fishy here.....
          lResult = RasEnumDevices(rdi(1), cb, count)
        
          'So far function returns Invalid User Buffer, this code appears correct according to MS
        
          Select Case lResult
                   Case %ERROR_INVALID_USER_BUFFER
                        MsgBox "Invalid User Buffer",%MB_ICONSTOP,"DEBUG"
                        Exit Function
                   Case %ERROR_INVALID_PARAMETER
                        MsgBox "Invalid Parameter",%MB_ICONSTOP,"DEBUG"
                        Exit Function
                   Case %ERROR_NOT_ENOUGH_MEMORY
                        MsgBox "Not enough memory",%MB_ICONSTOP,"DEBUG"
                        Exit Function
                   Case %ERROR_BUFFER_TOO_SMALL
                        MsgBox "Buffer too small",%MB_ICONSTOP,"DEBUG"
                        Exit Function
                   Case Else
                        MsgBox "Device Type and name are: " & $CRLF & rdi(1).szDeviceType & $CRLF & rdi(1).szDeviceName
            End Select

        ------------------
        Scott
        mailto:[email protected][email protected]</A>

        [This message has been edited by Scott Turchin (edited January 15, 2001).]
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment


        • #24
          Scott,

          We obviously need a pointer here instead of the string's first element.
          So, maybe there is a pointer specialist out there who can help us out?

          ------------------
          mailto:[email protected][email protected]</A>
          www.basicguru.com/zijlema/

          Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
          http://zijlema.basicguru.eu
          *** Opinions expressed here are not necessarily untrue ***

          Comment


          • #25
            Ok.
            Code:
              lResult = RasEnumDevices(ByVal %NULL, cb, count)
            At this point, cb contains the number of bytes you need
            for the buffer. count contains the number of entries
            written to the buffer: at this point, presumably, zero. So:
            Code:
              cb = Len(RASDEVINFO) * count
              Dim rdi(1 To count) As RASDEVINFO
            I am thinking that this is quite backwards. Try this instead:
            Code:
              count = cb / Len(RASDEVINFO)
              Dim rdi(1 To count) As RASDEVINFO

            ------------------
            Tom Hanlin
            PowerBASIC Staff

            Comment


            • #26
              Preciate the help, still returns and Invalid User Buffer however:

              Code:
              count = cb / Len(RASDEVINFO)
              Dim rdi(1 To count) As RASDEVINFO
              
              '  cb = Len(RASDEVINFO) * count
              '  Dim rdi(1 To count) As RASDEVINFO
                rdi(1).dwSize = Len(RASDEVINFO)
              
                lResult = RasEnumDevices(rdi(1), cb, count)
              
                'So far function returns Invalid User Buffer, this code appears correct according to MS
              
                Select Case lResult
                         Case %ERROR_INVALID_USER_BUFFER
                              MsgBox "Invalid User Buffer",%MB_ICONSTOP,"DEBUG"
                              Exit Function
                         Case %ERROR_INVALID_PARAMETER
                              MsgBox "Invalid Parameter",%MB_ICONSTOP,"DEBUG"
                              Exit Function
                         Case %ERROR_NOT_ENOUGH_MEMORY
                              MsgBox "Not enough memory",%MB_ICONSTOP,"DEBUG"
                              Exit Function
                         Case %ERROR_BUFFER_TOO_SMALL
                              MsgBox "Buffer too small",%MB_ICONSTOP,"DEBUG"
                              Exit Function
                         Case Else
                              MsgBox "Device Type and name are: " & $CRLF & rdi(1).szDeviceType & $CRLF & rdi(1).szDeviceName
                  End Select

              My feeling is that the function:
              lResult = RasEnumDevices(rdi(1), cb, count)


              Should be sending a pointer to rdi(1) not the string itself, even the MSDN site states a pointer to the buffer.
              The error returning is invalid user buffer, probably becaues the pointer is wrong?

              Thanks ,

              Scott


              ------------------
              Scott
              mailto:[email protected][email protected]</A>
              Scott Turchin
              MCSE, MCP+I
              http://www.tngbbs.com
              ----------------------
              True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

              Comment


              • #27
                Tom,

                I agree with Scott: we need a pointer here, not the array's first element in stringform.
                Here follows an example of the critical code, copied from Microsoft (in C++, I presume):
                Code:
                RasEnumDevices(NULL, &lpcb, &lpcDevices);
                lpRasDevInfo = (LPRASDEVINFO) GlobalAlloc(GPTR, lpcb);
                lpRasDevInfo->dwSize = sizeof(RASDEVINFO);
                 
                nRet = RasEnumDevices(lpRasDevInfo, &lpcb, &lpcDevices);
                if nret.... etc.
                As you see, the code is producing a pointer, called GPTR. Is someone willing to translate
                this piece of C-code into (Power) Basic?

                ------------------
                mailto:[email protected][email protected]</A>
                www.basicguru.com/zijlema/

                Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                http://zijlema.basicguru.eu
                *** Opinions expressed here are not necessarily untrue ***

                Comment


                • #28
                  I was baffled by what you meant by "in string form" until I saw the
                  RAS32.INC declaration for RasEnumEntries... not quite what I expected.

                  For the moment, I'd suggest replacing this:
                  Code:
                    lResult = RasEnumDevices(rdi(1), cb, count)
                  with this:
                  Code:
                    lResult = RasEnumDevices(BYVAL VARPTR(rdi(1)), cb, count)
                  I'll see if I can dig into RAS32.INC in a bit more detail. This might
                  be easier if the translation was tweaked a wee bit.

                  ------------------
                  Tom Hanlin
                  PowerBASIC Staff

                  Comment


                  • #29
                    Okay, I think I've got it.

                    LEN(RASDEVINFO) is the problem. This returns 150, while the buffer size you need is 152 (per device count, at least on my system). Anyway, you don't need this, as cb and count give you all the size info you need.
                    The following works nicely on my machines running NT4 and Win98 (haven't tested on 95 or 2000 yet, but I expect it would work on them as well).

                    Code:
                    FUNCTION CreateRasEntry ALIAS "CreateRasEntry" (BYVAL entry AS STRING, _
                                            BYVAL areacode AS STRING, _
                                            BYVAL phone AS STRING) Export AS LONG
                    
                      LOCAL cb    AS LONG
                      LOCAL count AS LONG
                      LOCAL x     AS LONG
                      LOCAL modem AS STRING
                      LOCAL r     AS RASENTRY
                      Local lResult As Long
                      
                      RasEnumDevices BYVAL %NULL, cb, count
                      'cb returns the buffer size needed
                      
                      IF ISFALSE count THEN
                        EXIT FUNCTION
                      END IF
                    
                      
                      DIM rdi(1 to count) AS RASDEVINFO
                      'set rdi(1).dwSize to the buffer size divided by the number of devices
                      rdi(1).dwSize = cb/count
                      RasEnumDevices rdi(1), cb, count
                      
                      FOR x = 1 TO count 
                      	'NT uses MODEM, 98 uses modem
                        	IF rdi(x).szDeviceType = "MODEM" Or rdi(x).szDeviceType = "modem" THEN 
                          modem = rdi(x).szDeviceName
                          EXIT FOR
                        END IF
                      NEXT
                    
                      r.dwSize             = 1768  'Windows 95 OSR2 and later
                      r.dwfOptions         = %RASEO_IpHeaderCompression OR _
                                             %RASEO_RemoteDefaultGateway OR _
                                             %RASEO_ModemLights OR %RASEO_SwCompression
                      r.dwCountryId        = 0
                      r.dwCountryCode      = 0
                      r.szAreaCode         = areacode
                      r.szLocalPhoneNumber = phone
                      r.dwAlternateOffset  = 0
                      r.ipAddr             = %NULL
                      r.ipAddrDns          = %NULL
                      r.ipAddrDnsAlt       = %NULL
                      r.ipAddrWins         = %NULL
                      r.ipAddrWinsAlt      = %NULL
                      r.dwFrameSize        = %NULL
                      r.dwfNetProtocols    = %RASNP_Ip
                      r.dwFramingProtocol  = %RASFP_Ppp
                      r.szScript           = ""
                      r.szAutodialDll      = ""
                      r.szAutodialFunc     = ""
                      r.szDeviceType       = $RASDT_Modem
                      r.szDeviceName       = modem
                      r.szX25PadType       = ""
                      r.szX25Address       = ""
                      r.szX25Facilities    = ""
                      r.szX25UserData      = ""
                      r.dwChannels         = 0
                      r.dwReserved1        = 0
                      r.dwReserved2        = 0
                                                  
                                                
                      FUNCTION = RasSetEntryProperties(BYVAL %NULL, BYCOPY entry, r, SIZEOF(r), BYVAL %NULL, %NULL)
                    
                    END FUNCTION
                    '------------------
                    I'm running this with the modified ras include file I posted in the Source Code forum.
                    Peter Amick
                    Baybuild Solutions

                    Comment


                    • #30
                      Thank you!
                      Works like a charm, although I'm confused where my code was wrong, it's that pointer we mentioned but your code has it corrected, or that buffer size, either way life is good!!


                      Take care

                      Scott

                      ------------------
                      Scott
                      mailto:[email protected][email protected]</A>
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment


                      • #31
                        Thank you!
                        No problem. Glad to be able to contribute once in a while.


                        I'm confused where my code was wrong,
                        It seems to me that your code "should" work, I don't know why LEN(RASDEVINFO) doesn't give you the right size. Maybe someone else can explain it.


                        either way life is good!!
                        Happiness is working code!

                        Peter


                        ------------------
                        Peter Amick
                        Baybuild Solutions
                        Peter Amick
                        Baybuild Solutions

                        Comment


                        • #32
                          I probably would not have been able to WRITE that kind of code, but taking it apart today and troubleshooting it gave me a 100% good understanding of what it does, inside and out...

                          Of course I read the MSDN definition on that function/api and that helped a LOT!!

                          But thanks!
                          Two projects done today!!




                          ------------------
                          Scott
                          mailto:[email protected][email protected]</A>
                          Scott Turchin
                          MCSE, MCP+I
                          http://www.tngbbs.com
                          ----------------------
                          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                          Comment


                          • #33
                            Thank you, guys!
                            Now we are getting somewhere, indeed! The strange thing is: I had discovered the difference between LEN(RASDEVINFO) and bytelength divided by count, i.e. 150 versus 152, on my W95 machine.
                            It did'nt work out, however (maybe due to another error?!)

                            There is an unsolved problem yet:
                            Is it possible to copy a shortcut of the new connection to the desktop?

                            I'm working on it now. Your help will be much appreciated.

                            Regards,


                            ------------------
                            mailto:[email protected][email protected]</A>
                            www.basicguru.com/zijlema/



                            [This message has been edited by Egbert Zijlema (edited January 17, 2001).]

                            Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                            http://zijlema.basicguru.eu
                            *** Opinions expressed here are not necessarily untrue ***

                            Comment


                            • #34
                              'at's a good question. Adding up the length of the members of
                              RASDEVINFO comes out to 150, just as LEN() says, and it can
                              readily be verified that there's no padding between the members.
                              Near as I can guess, Windows is adding two bytes of padding to
                              the end of the structure, on the off chance that the next item
                              might need to be DWORD-aligned ...?!!

                              ------------------
                              Tom Hanlin
                              PowerBASIC Staff

                              Comment


                              • #35
                                Egbert it's funny you should ask that, it was the [red]FIRST[/red] thought through my head after I saw that the DUN was there!


                                I have an idea how, have shortcut code from a previous project but since that entry is not really a file to my knowledge I'm not quite sure how to go about it yet...


                                Scott

                                ------------------
                                Scott
                                mailto:[email protected][email protected]</A>
                                Scott Turchin
                                MCSE, MCP+I
                                http://www.tngbbs.com
                                ----------------------
                                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                                Comment


                                • #36
                                  Scott,

                                  I do have such a routine, but the problem is that the Dial Up Networking directory (folder) is not a normal, accessible directory.
                                  Nor can it be accessed using the SHGetSpecialFolder API. I've spent the entire day on it, but without success.

                                  By the way: IF that folder were accessible, there was no need for all the work we've done this far.
                                  We then simply could copy a working RAS-entry from our installdisk to the Dial-Up Networking folder on the user's computer, is not it?


                                  ------------------
                                  mailto:[email protected][email protected]</A>
                                  www.basicguru.com/zijlema/

                                  Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                                  http://zijlema.basicguru.eu
                                  *** Opinions expressed here are not necessarily untrue ***

                                  Comment


                                  • #37
                                    Well I created a short cut manually and opened it in a hex editor.
                                    This has GOT to be easy.
                                    It's just a .LNK file pointing to my "Sinclair" entry.
                                    While I don't understand how the .LNK works, I'm sure this could be mimicked easy enough

                                    Instead of pointing to a file it will point to a DUN entry, should work...
                                    I'll tackle that one later, need to go take care of some errands today

                                    Scott


                                    [This message has been edited by Scott Turchin (edited January 17, 2001).]
                                    Scott Turchin
                                    MCSE, MCP+I
                                    http://www.tngbbs.com
                                    ----------------------
                                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                                    Comment

                                    Working...
                                    X