Home > Software engineering >  The zeromemory for help
The zeromemory for help

Time:10-29

Each prawn, if straight run code shows that: the following code error calling DLL convention, if the compiled run guest executable program, program crashes, kneel down!

 Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlMoveMemory" (dest As Any, ByVal numBytes As Long) 

Private Type cardDatastru

CardReqMsg As Long
The CardNumber (0 To 14) As Byte
Name1 (0 To 30) As Byte
FacilityCode As Integer
BinaryCardNumber (0 To 15) As Byte

End Type

Private Sub Command1_Click ()

Dim strValue As cardDatastru

Call ZeroMemory (strValue, LenB (strValue))

End Sub

CodePudding user response:

 
'Example Name: Dial
'This program let you dial to dial - up connections using been
'the stored user name and password or the ones you specifies
'(It use RasDial for dialing)

'You need a form with a list, 2 textbox and a command button

Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, ByVal pSrc As String, ByVal ByteLen As Long)
Private Declare Sub ZeroMemory Lib "kernel32. DLL" Alias "RtlZeroMemory" (Destination As Any, ByVal Length As Long)

Const RAS95_MaxEntryName=256
Const RAS_MaxPhoneNumber=128
Const RAS_MaxCallbackNumber=RAS_MaxPhoneNumber

Const UNLEN=256
Const PWLEN=256
Const DNLEN=12
Private Type RASDIALPARAMS
DwSize As Long '1052
SzEntryName (RAS95_MaxEntryName) As Byte
SzPhoneNumber (RAS_MaxPhoneNumber) As Byte
SzCallbackNumber (RAS_MaxCallbackNumber) As Byte
SzUserName (UNLEN) As Byte
SzPassword (PWLEN) As Byte
SzDomain (DNLEN) As Byte
End Type

Private Type RASENTRYNAME95
'set dwsize to 264
DwSize As Long
SzEntryName (RAS95_MaxEntryName) As Byte
End Type

Private Declare Function RasDial Lib "rasapi32. DLL" Alias "RasDialA" (ByVal lprasdialextensions As Long, ByVal LPCSTR As String, ByRef lprasdialparamsa As RASDIALPARAMS, ByVal dword As Long, lpvoid As Any, ByRef lphrasconn As Long) As Long
Private Declare Function RasEnumEntries Lib "rasapi32. DLL" Alias "RasEnumEntriesA" (ByVal reserved As String, ByVal lpszPhonebook As String, lprasentryname As Any, LPCB As Long, lpcEntries As Long) As Long
Private Declare Function RasGetEntryDialParams Lib "rasapi32. DLL" Alias "RasGetEntryDialParamsA" (ByVal LPCSTR As String, ByRef lprasdialparamsa As RASDIALPARAMS, ByRef lpbool As Long) As Long

Private Function Dial (ByVal Connection As String, ByVal UserName As String, ByVal Password As String) As Boolean
Dim the rp As RASDIALPARAMS, h As Long, resp As Long
The rp. DwSize=Len (rp) + 6
ChangeBytes Connection, rp. SzEntryName
ChangeBytes "", the rp szPhoneNumber 'Phone number stored for connection
ChangeBytes "*", the rp szCallbackNumber 'Callback number stored for connection
ChangeBytes UserName, rp. SzUserName
ChangeBytes Password, rp. SzPassword
ChangeBytes "*", the rp szDomain 'Domain stored for connection
'Dial
Resp=RasDial (ByVal 0, ByVal 0, rp, 0, ByVal 0, h) 'AddressOf RasDialFunc
Dial=(resp=0)
End the Function

Private Function ChangeToStringUni (Bytes () As Byte) As String
'Changes an byte array to a Visual Basic unicode string
Dim temp As String
Temp=StrConv (Bytes, vbUnicode)
ChangeToStringUni=Left (temp, InStr (temp, CRH (0)) - 1)
End the Function

Private Function ChangeBytes (ByVal STR As String, Bytes () As Byte) As Boolean
'Changes a Visual Basic unicode string to an byte array
'Returns True if it truncates the STR
Dim lenBs As Long 'length of the byte array
Dim lenStr As Long 'length of the string
LenBs=UBound (Bytes) - LBound (Bytes)
LenStr=LenB (StrConv (STR, vbFromUnicode))
If lenBs & gt; LenStr Then
CopyMemory Bytes (0), STR, lenStr
ZeroMemory Bytes (lenStr), lenBs - lenStr
ElseIf lenBs=lenStr Then
CopyMemory Bytes (0), STR, lenStr
The Else
CopyMemory Bytes (0), STR, lenBs' Queda truncado
ChangeBytes=True
End the If
End the Function

Private Sub Command1_Click ()
Dial List1. Text, Text1, Text2
End Sub


Private Sub List1_Click ()
Dim RDP As RASDIALPARAMS, t As Long
RDP. DwSize=Len (RDP) + 6
ChangeBytes List1. Text, RDP. SzEntryName
'Get User name and password for the connection
T=RasGetEntryDialParams (List1. Text, RDP, 0)
If t=0 Then
Text1=ChangeToStringUni (RDP) szUserName)
Text2=ChangeToStringUni (RDP) szPassword)
End the If
End Sub

Private Sub Form_Load ()
'example created by Daniel Kaufmann ([email protected])
'the load the connections
Text2. PasswordChar='*'
Command1. Caption="Dial"
Dim s As Long As l Long, ln the As Long, a $
ReDim r (255) As RASENTRYNAME95

R (0). DwSize=264
S=256 * r (0). The dwSize
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related