Autor Tema: [HELP] Invoke API's  (Leído 1334 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Cudder

  • Bytes
  • *
  • Mensajes: 26
  • Reputación: +0/-1
    • Ver Perfil
[HELP] Invoke API's
« en: Noviembre 24, 2012, 01:33:58 am »
Hola amigos! Can anyone please Invoke(CallAPI) those API's please?

Código: [Seleccionar]
Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal nService As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal nAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal nFlags As Long) As Long
Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Declare Function InternetOpenUrlA Lib "wininet" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Const INTERNET_SERVICE_FTP = 1: Global sURL As String

Function FTPUpload(sFile As String, sHost As String, sUser As String, sPass As String)
    Dim hINetSession, hSession, sTemp() As String: sTemp = Split(sFile, "\")
     
    hINetSession = InternetOpen("project", 0, vbNullString, vbNullString, 0)
    hSession = InternetConnect(hINetSession, sHost, "21", sUser, sPass, INTERNET_SERVICE_FTP, 0, 0)
    If FtpPutFile(hSession, sFile, sTemp(UBound(sTemp)), 1, 0) = False Then
        Call InternetCloseHandle(hSession): Call InternetCloseHandle(hINetSession)
    End If
End Function

Código: [Seleccionar]
Option Explicit

Private Const MICROSOFT_CDO_CONFIGURATION$ = "http://schemas.microsoft.com/cdo/configuration/"

Private Declare Function GetFileAttributesW Lib "KERNEL32" (ByVal lpFileName As Long) As Long
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long

Private lngPort&, strUser$, strPass$, strFrom$, strServer$, strSubject$, strMessage$, strDestinatary$, strAttachedFile$
Private objCDO As Object, bolUseAuntentificacion As Boolean, bolSSL As Boolean

Friend Property Let Server(ByRef Value$): strServer = Value: End Property
Friend Property Let Destinatary(ByRef Value$): strDestinatary = Value: End Property
Friend Property Let From(ByRef Value$): strFrom = Value: End Property
Friend Property Let Subject(ByRef Value$): strSubject = Value: End Property
Friend Property Let Message(ByRef Value$): strMessage = Value: End Property
Friend Property Let AttachedFile(ByRef Value$): strAttachedFile = Value: End Property
Friend Property Let Port(ByVal Value&): lngPort = Value: End Property
Friend Property Let User(ByRef Value$): strUser = Value: End Property
Friend Property Let Password(ByRef Value$): strPass = Value: End Property
Friend Property Let UseAuntentificacion(ByVal Value As Boolean): bolUseAuntentificacion = Value: End Property
Friend Property Let SSL(ByVal Value As Boolean): bolSSL = Value: End Property

Friend Function SendMail() As Boolean
    On Error GoTo FatalError
   
    If InternetGetConnectedState(&H0&, &H0&) Then
        If (LenB(strPass) = 0) Or (LenB(strUser) = 0) Or (LenB(strFrom) = 0) Or (LenB(strServer) = 0) Or (LenB(strDestinatary) = 0) Or ((lngPort < 0) Or (lngPort > &HFDE8&)) Then Exit Function
        With objCDO
            With .Configuration
                .Fields(MICROSOFT_CDO_CONFIGURATION & "smtpserver") = strServer
                .Fields(MICROSOFT_CDO_CONFIGURATION & "sendusing") = &H2&
                With .Fields
                    .Item(MICROSOFT_CDO_CONFIGURATION & "smtpserverport") = lngPort
                    .Item(MICROSOFT_CDO_CONFIGURATION & "smtpauthenticate") = Abs(bolUseAuntentificacion)
                    .Item(MICROSOFT_CDO_CONFIGURATION & "smtpconnectiontimeout") = &HA&
                    If bolUseAuntentificacion Then
                        .Item(MICROSOFT_CDO_CONFIGURATION & "sendusername") = strUser
                        .Item(MICROSOFT_CDO_CONFIGURATION & "sendpassword") = strPass
                        .Item(MICROSOFT_CDO_CONFIGURATION & "smtpusessl") = bolSSL
                    End If
                    .Update
                End With
            End With
            .To = strDestinatary: .From = strFrom: .Subject = strSubject: .TextBody = strMessage
            If LenB(strAttachedFile) Then
                If GetFileAttributesW(StrPtr(strAttachedFile)) > -1 Then .AddAttachment (strAttachedFile)
            End If
            .Send
        End With
        SendMail = True
    End If
FatalError:
End Function

Private Sub Class_Initialize()
    Set objCDO = CreateObject("CDO.Message")
End Sub

Private Sub Class_Terminate()
    Set objCDO = Nothing
End Sub

Thanks A lot!