|
|
 | | From: | edamron at spamcop.net | | Subject: | Calling Windows API | | Date: | 4 Jan 2005 13:20:16 -0800 |
|
|
 | I need to port some code we use in VBA to ensure that the person using the database isn't doing so over a RAS connection. In VBA I use a Windows API call. I have converted it to powerbuilder 8.0 but it doesn't work. I have posted the working VBA code as well as the non-working powerbuilder code. Can someone who is better at powerbuilder than I (Almost anyone) tell me what I did wrong?
Thanks.
================== VBA Code =========================== 'Declarations: Public Declare Function RasEnumConnections Lib "RasApi32.dll" Alias "RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, lpcConnections As Long) As Long Public Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long ' Public Const RAS95_MaxEntryName = 256 Public Const RAS95_MaxDeviceType = 16 Public Const RAS95_MaxDeviceName = 32 ' Public Type RASCONN95 dwSize As Long hRasCon As Long szEntryName(RAS95_MaxEntryName) As Byte szDeviceType(RAS95_MaxDeviceType) As Byte szDeviceName(RAS95_MaxDeviceName) As Byte End Type ' Public Type RASCONNSTATUS95 dwSize As Long RasConnState As Long dwError As Long szDeviceType(RAS95_MaxDeviceType) As Byte szDeviceName(RAS95_MaxDeviceName) As Byte End Type
'Code: 'A call to the function IsConnected returns true if the computer has 'established a connection to the internet.
Public Function IsConnected() As Boolean Dim TRasCon(255) As RASCONN95 Dim lg As Long Dim lpcon As Long Dim RetVal As Long Dim Tstatus As RASCONNSTATUS95 ' TRasCon(0).dwSize = 412 lg = 256 * TRasCon(0).dwSize ' RetVal = RasEnumConnections(TRasCon(0), lg, lpcon) If RetVal <> 0 Then MsgBox "ERROR" Exit Function End If ' Tstatus.dwSize = 160 RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus) If Tstatus.RasConnState = &H2000 Then IsConnected = True Else IsConnected = False End If
End Function
========================== PowerBuilder Code =================== forward global type ras_chk from nonvisualobject end type type rasconn95 from structure within ras_chk end type type rasconnstatus95 from structure within ras_chk end type end forward
type rasconn95 from structure long dwsize long hrascon character szentryname[256] character szdevicetype[16] character szdevicename[32] end type
type RASCONNSTATUS95 from structure long dwSize long RasConnState long dwError character szDeviceType[16] character szDeviceName[32] end type
global type ras_chk from nonvisualobject end type global ras_chk ras_chk
type prototypes FUNCTION long RasEnumConnections(Any lpRasCon, long lpcb, long lpcConnections) LIBRARY "RasApi32.dll" ALIAS FOR RasEnumConnectionsA FUNCTION long RasGetConnectStatus(Long hRasCon, Any lpStatus) LIBRARY "RasApi32.dll" ALIAS FOR RasGetConnectStatusA
end prototypes
type variables
end variables
forward prototypes public function boolean of_isconnected () end prototypes
public function boolean of_isconnected ();RASCONN95 TRasCon[256] RASCONNSTATUS95 Tstatus long lg, lpcon, RetVal
TRasCon[1].dwSize = 412
lg = 256 * TRasCon[1].dwSize
lpcon = 0
RetVal = RasEnumConnections(TRasCon[1], lg, lpcon)
if RetVal <> 0 then Messagebox("Error", "Error testing RAS connection") Return True end if
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon[1].hRasCon, Tstatus)
if TStatus.RasConnState = 8192 then Return True end if
Return False
end function on ras_chk.create call super::create TriggerEvent( this, "constructor" ) end on
on ras_chk.destroy TriggerEvent( this, "destructor" ) call super::destroy end on
|
|
 | | From: | Konstantin Goldobin | | Subject: | Calling Windows API | | Date: | Wed, 05 Jan 2005 11:54:00 +0300 |
|
|
 | Hello, Edamron.
Jan 04 2005, Edamron wrote:
E> I need to port some code we use in VBA to ensure that the person using E> the database isn't doing so over a RAS connection. In VBA I use a E> Windows API call. I have converted it to powerbuilder 8.0 but it E> doesn't work. I have posted the working VBA code as well as the E> non-working powerbuilder code. Can someone who is better at E> powerbuilder than I (Almost anyone) tell me what I did wrong?
What do you mean by "it doesn't work"?
Konstantin. http://www.vsi.ru/~kgold
|
|
 | | From: | edamron at spamcop.net | | Subject: | Re: Calling Windows API | | Date: | 5 Jan 2005 13:38:57 -0800 |
|
|
 | RetVal in the snippit below is always non-zero
if RetVal <> 0 then Messagebox("Error", "Error testing RAS connection") Return True end if
|
|
 | | From: | edamron at spamcop.net | | Subject: | Re: Calling Windows API | | Date: | 7 Jan 2005 08:51:35 -0800 |
|
|
 | In VB we pass a variant or Any type. The datatype is actually a RASCON structure: typedef struct _RASCONN { DWORD dwSize; HRASCONN hrasconn; TCHAR szEntryName[RAS_MaxEntryName + 1];
#if (WINVER >= 0x400) TCHAR szDeviceType[ RAS_MaxDeviceType + 1 ]; TCHAR szDeviceName[ RAS_MaxDeviceName + 1 ]; #endif #if (WINVER >= 0x401) TCHAR szPhonebook [ MAX_PATH ]; DWORD dwSubEntry; #endif #if (WINVER >= 0x500) GUID guidEntry; #endif #if (WINVER >= 0x501) DWORD dwFlags; LUID luid; #endif } RASCONN ;
|
|
 | | From: | Konstantin Goldobin | | Subject: | Calling Windows API | | Date: | Fri, 07 Jan 2005 23:38:18 +0300 |
|
|
 | Edamron,
Jan 07 2005, Edamron wrote:
E> In VB we pass a variant or Any type. The datatype is actually a E> RASCON structure:
I believe it will be tricky to make it windows version dependable, but for a start try to modify your function declaration to:
FUNCTION long RasEnumConnections(ref rasconn95 lpRasCon, long lpcb, long lpcConnections) LIBRARY "RasApi32.dll" ALIAS FOR RasEnumConnectionsA
Konstantin. http://www.vsi.ru/~kgold
|
|
 | | From: | Konstantin Goldobin | | Subject: | Calling Windows API | | Date: | Sat, 08 Jan 2005 12:07:35 +0300 |
|
|
 | Edamron,
Jan 07 2005, Edamron wrote:
E> In VB we pass a variant or Any type. The datatype is actually a E> RASCON structure:
Finally, this snippet works OK for me:
=== Cut === $PBExportHeader$ras_chk.sru forward global type ras_chk from nonvisualobject end type end forward
type rasconn95 from structure long dwsize long hrascon character szentryname[256] character szdevicetype[16] character szdevicename[32] end type
type RASCONNSTATUS95 from structure long dwSize long RasConnState long dwError character szDeviceType[16] character szDeviceName[32] end type
global type ras_chk from nonvisualobject end type global ras_chk ras_chk
type prototypes FUNCTION long RasEnumConnections(ref rasconn95 lpRasCon[256], ref long lpcb, ref long lpcConnections) LIBRARY "RasApi32.dll" ALIAS FOR RasEnumConnectionsA FUNCTION long RasGetConnectStatus(Long hRasCon, ref rasconnstatus95 lpStatus) LIBRARY "RasApi32.dll" ALIAS FOR RasGetConnectStatusA
end prototypes type variables
end variables
forward prototypes public function boolean of_isconnected () end prototypes
public function boolean of_isconnected (); RASCONN95 TRasCon[256] RASCONNSTATUS95 Tstatus long lg, lpcon, RetVal
TRasCon[1].dwSize = 412
lg = 256 * TRasCon[1].dwSize
lpcon = 0
RetVal = RasEnumConnections(TRasCon, lg, lpcon)
if RetVal <> 0 then Messagebox("Error", "Error testing RAS connection") Return True end if
if lpcon = 0 then return false
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon[1].hRasCon, Tstatus)
if RetVal <> 0 then Messagebox("Error", "Error retrieving RAS information") Return True end if
if TStatus.RasConnState = 8192 then Return True end if
Return False
end function on ras_chk.create TriggerEvent( this, "constructor" ) end on
on ras_chk.destroy TriggerEvent( this, "destructor" ) end on
=== Cut ===
Konstantin. http://www.vsi.ru/~kgold
|
|
 | | From: | Konstantin Goldobin | | Subject: | Calling Windows API | | Date: | Fri, 07 Jan 2005 13:30:37 +0300 |
|
|
 | Edamron,
Jan 05 2005, Edamron wrote:
E> RetVal in the snippit below is always non-zero
E> if RetVal <> 0 then E> Messagebox("Error", "Error testing RAS connection") E> Return True E> end if
What is the real datatype of the first argument of RasEnumConnectionsA?
Konstantin. http://www.vsi.ru/~kgold
|
|
|