View Full Version : [VB6] Problema con DLL
wingman87
28-02-2007, 21:43
Ho creato una dll e sto provando ad usarla in un progetto (è la prima volta che la uso quindi è una specie di test).
Questa dll ha solo metodi, non proprietà
Mi da subito un problema:
- Variabile oggetto o variabile del blocco With non impostata (errore 91)
Su una riga dove uso x la prima volta un metodo della dll
Inoltre l'errore me lo da anche se richiamo un qualsiasi altro metodo
Credo di aver dichiarato correttamente l'oggetto e cioè:
Dim Session As WPop
Set Session = New WPop
L'oggetto si chiama WPop
La dll è inserita tra i Riferimenti del progetto.
Dov'è il problema?
PS: è la prima dll che faccio quindi potrei anche aver saltato qualche passaggio banale nella creazione.
wingman87
28-02-2007, 22:01
Visto che non è lungo vi copio qui anche il codice della dll:
Private WithEvents pop3 As Winsock
Public Type Sender
Name As String
Mail As String
End Type
Private Enum POP3States 'The POP3 states enum
DISCONNECTED
CONNECTED
PROBLEM
USEROK
PASSOK
REQSTAT
STATOK
REQTOP
TOPOK
REQRETR
RETR
RETROK
REQDELE
DELEOK
End Enum
Private State As POP3States
Private RecData As String
Private Message As String
Private Sub Class_Initialize()
State = DISCONNECTED
End Sub
'------------------------------------FUNCTIONS
Public Function Connect(ByVal Server As String, ByVal Port As String, _
ByVal User As String, ByVal Pass As String) As Integer
pop3.Connect Server, Port
Do While State <> CONNECTED And PROBLEM
DoEvents
Loop
If State = PROBLEM Then
Connect = -1
Exit Function
End If
pop3.SendData "user " + User + vbCrLf
Do While State <> USEROK And PROBLEM
DoEvents
Loop
If State = PROBLEM Then
Connect = -1
Exit Function
End If
pop3.SendData "pass " + Pass + vbCrLf
Do While State <> PASSOK And PROBLEM
DoEvents
Loop
If State = PROBLEM Then
Connect = -1
Exit Function
End If
Connect = 0
End Function
Public Function MexCount() As Integer
State = REQSTAT
pop3.SendData "stat" + vbCrLf
Do While State <> STATOK And PROBLEM
DoEvents
Loop
If State = PROBLEM Then
MexCount = -1
Exit Function
End If
MexCount = Val(Mid(RecData, 5, InStr(5, RecData, " ") - 5))
End Function
Public Function GetMex(ByVal n As Integer) As String
State = REQRETR
pop3.SendData "retr " + n + vbCrLf
Do While State <> RETROK And PROBLEM
DoEvents
Loop
If State = PROBLEM Then
GetMex = "Questo messaggio non esiste"
Exit Function
End If
GetMex = Message
End Function
Public Function MexSender(ByVal n As Integer) As Sender
State = REQTOP
pop3.SendData "top " + n + " 1" + vbCrLf
Do While State <> TOPOK And PROBLEM
DoEvents
Loop
If State = PROBLEM Then
Exit Function
End If
Dim strTop() As String
strTop = Split(txtOut.Text, vbCrLf)
Dim i As Integer
For i = 0 To UBound(strTop)
If UCase(Left(strTop(i), 6)) = "FROM: " Then
Exit For
End If
Next i
Dim Temp As String
Temp = strTop(i)
Temp = Right(Temp, Len(Temp) - 6)
If Left(Temp, 1) <> "<" Then
If Left(Temp, 1) = Chr(34) Then
Temp = Right(Temp, Len(Temp) - 1)
MexSender.Name = Mid(Temp, 1, InStr(1, Temp, Chr(34)) - 1)
Temp = Right(Temp, Len(Temp) - InStr(1, Temp, Chr(34)) - 1)
Else
MexSender.Name = Mid(Temp, 1, InStr(1, Temp, "<") - 2)
Temp = Mid(Temp, InStr(1, Temp, "<"))
End If
Else
MexSender.Name = ""
End If
Temp = Mid(Temp, 2)
Temp = Left(Temp, Len(Temp) - 1)
MexSender.Mail = Temp
End Function
Public Function DeleteMex(ByVal n As Integer) As Integer
State = REQDELE
pop3.SendData "dele " + n + vbCrLf
Do While State <> DELEOK And PROBLEM
DoEvents
Loop
If State = PROBLEM Then
DeleteMex = -1
Exit Function
End If
DeleteMex = 0
End Function
'------------------------------------SUB
Public Sub Disconnect()
State = DISCONNECTED
pop3.Close
End Sub
'------------------------------------POP3
Private Sub pop3_DataArrival(ByVal bytesTotal As Long)
pop3.GetData RecData
Select Case (State)
Case DISCONNECTED
If Left(RecData, 1) = "+" Then
State = CONNECTED
Else
State = PROBLEM
End If
Case CONNECTED
If Left(RecData, 1) = "+" Then
State = USEROK
Else
State = PROBLEM
End If
Case USEROK
If Left(RecData, 1) = "+" Then
State = PASSOK
Else
State = PROBLEM
End If
Case REQSTAT
If Left(RecData, 1) = "+" Then
State = STATOK
Else
State = PROBLEM
End If
Case REQTOP
If UCase(Left(RecData, 8)) = "RECEIVED" Then
State = TOPOK
ElseIf Left(RecData, 1) = "-" Then
State = PROBLEM
End If
Case REQRETR
If Left(RecData, 1) = "+" Then
Message = ""
State = RETR
Else
State = PROBLEM
End If
Case RETR
Message = Message + RecData
If Right(RecData, 5) = vbCrLf + "." + vbCrLf Then
State = RETROK
End If
Case REQDELE
If Left(RecData, 1) = "+" Then
State = DELEOK
Else
State = PROBLEM
End If
End Select
End Sub
Il codice è funzionante, lo so perchè l'ho testato in un altro programma, quello che non mi riesce è incapsularlo in una dll..
wingman87
01-03-2007, 12:10
Ho risolto il problema, bisognava mettere l'oggetto winsock tra i riferimenti e non tra i componenti come ho fatto io e fare una
set pop3=new winsock
alla initialize e una
set pop3=nothing
alla terminate
Ora ho un altro problema, ho compilato il programma e creato l'eseguibile, poi ho passato ad un mio amico il programma con la dll che ho creato. Questo mio amico non ha vb6 installato. Quando fa partire il programma sembra andare tutto bene ma quando dovrebbe usare l'oggetto che ho creato da errore dicendo:
Run time error 429
ActiveX component can't create object
Eppure sul mio pc funziona bene, cosa c'è che non va sul suo? Gli ho anche registrato l'ocx "mswinsck.ocx"
wingman87
02-03-2007, 21:41
up
Non è che questo ocx va registrato in modo differente?
wingman87
04-03-2007, 18:17
Cercando con google ho trovato questo:
http://www.vbip.com/forum/topic.asp?id=2984
penso di essere vicino alla soluzione qualcuno può dargli un'occhiata? Ho provato a fare come dice il link in fondo ma mi da sempre lo stesso errore, ho alcuni dubbi:
1- quale codice di licenza devo prendere? Il mio? Se sì allora devo includere nel pacchetto anche il mio winsock? Oppure devo runtime prendere il codice di licenza dell'ocx che c'è sulla macchina e usare quello?
2- Siamo sicuri che bisogna fare tutto sto casino solo x usare la winsock come riferimento? Come componente infatti non c'è nessun problema...
cosa c'è che non va sul suo? Gli ho anche registrato l'ocx "mswinsck.ocx"
Controlla le dipendenze dell'eseguibile e della dll con dependency walker... Solitamente c'è anche bisogno di installare il runtime VB6...
http://www.microsoft.com/downloads/details.aspx?FamilyID=7b9ba261-7a9c-43e7-9117-f673077ffb3c&DisplayLang=it
Tabagismo
06-03-2007, 19:55
Controlla le dipendenze dell'eseguibile e della dll con dependency walker... Solitamente c'è anche bisogno di installare il runtime VB6...
http://www.microsoft.com/downloads/details.aspx?FamilyID=7b9ba261-7a9c-43e7-9117-f673077ffb3c&DisplayLang=it
Il runtime è installato, il pc è mio, da cosa può dipendere?
E' un problema del winsock o il problema sta nel mio pc :muro:
Grazie
BountyKiller
06-03-2007, 20:31
doppio nick?:stordita:
Tabagismo
06-03-2007, 20:40
doppio nick?:stordita:
No, sono io l'amico di wingman al quale ha passato il programma :D
BountyKiller
06-03-2007, 22:04
lol
wingman87
07-03-2007, 12:52
Controlla le dipendenze dell'eseguibile e della dll con dependency walker... Solitamente c'è anche bisogno di installare il runtime VB6...
http://www.microsoft.com/downloads/details.aspx?FamilyID=7b9ba261-7a9c-43e7-9117-f673077ffb3c&DisplayLang=it
Ho provato niente da fare.. Hai provato a guardare il link che ho messo io? Cmq per il momento vorrà dire che non scriverò dll con la winsock.. Mi piacerebbe xò sapere quale oscuro mistero avvolge questo misterioso componente..
PS: cos'è sta roba? --> :nera:
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.