Your string buffers sizes are off-by-one -- should be sized to RAS_MaxEntryName + 1, RAS_MaxDeviceType + 1 and RAS_MaxDeviceName + 1 to match array sizes in SDK struct.
Here is a somewhat more convenient fixed-string equivalent of the UDT in VB6
This way LenB(RASCONN95_W) = 816 in VB6 which is correct because it is 814 from above C/C++ code *padded* to DWORD boundary. Btw, C/C++ is using padded size for array of RASCONN95_W too.Code:Private Type RASCONN95_W dwSize As Long hRasConn As Long szEntryName As String * 257 ' (RAS_MaxEntryName+1) szDeviceType As String * 17 ' (RAS_MaxDeviceType+1) szDeviceName As String * 129 ' (RAS_MaxDeviceName+1) End Type
The only thing to heed is that you have to use ByVal VarPtr at callsite to prevent Unicode<->ANSI converstion with fixed-length strings, so the original code should work now
Not tested as I don't have any RAS (dial-up/VPN) connections setup.Code:lpRasconn(0).dwSize = LenB(lpRasconn(0)) '=816 lpCb = lpRasconn(0).dwSize * (UBound(lpRasconn) + 1) '=816*256=208896 lErr = RasEnumConnectionsWide(ByVal VarPtr(lpRasconn(0)), lpCb, lConnections)
cheers,
</wqw>




Reply With Quote
