ERRO DLL

PEDROALSOI 01/02/2014 17:01:02
#434056
Ola amigos comecei a estudar dll e fiz um que envia e-mail só para aprender mais, então aqui o código do dll:

  Imports System.Net
Public Class envio
Public Function envio(ByVal email As String, ByVal destino As String, ByVal dequemenvio As String, ByVal assunto As String, ByVal SMTP As String, ByVal senha As String, ByVal porta As String, ByVal prioridade As String)
[ô]Define os dados do e-mail
[ô]Dim nomeRemetente As String
[ô]Dim emailRemetente As String

[ô]Dim emailComCopia As String
[ô]Dim emailComCopiaOculta As String

[ô]emailComCopia = [Ô]email@comcopia.com.br[Ô]
[ô]emailComCopiaOculta = [Ô]email@comcopiaoculta.com.br[Ô]


[ô]Host da porta SMTP

SMTP = SMTP

[ô]Dim assuntoMensagem As String
[ô]Dim conteudoMensagem As String

[ô]assuntoMensagem = [Ô]Teste de envio de emails usando System.Net.Mail em VB.NET[Ô]
[ô]conteudoMensagem = [Ô]Teste de envio de emails usando System.Net.Mail em VB.NET[Ô]


[ô]Cria objeto com dados do e-mail.
Dim objEmail As New System.Net.Mail.MailMessage()

[ô]Define o Campo From e ReplyTo do e-mail.
objEmail.From = New System.Net.Mail.MailAddress([Ô]<[Ô] & dequemenvio & [Ô]>[Ô])
[ô]objEmail.ReplyTo = New System.Net.Mail.MailAddress([Ô]Nome <email@seudominio.com.br>[Ô])

[ô]Define os destinatários do e-mail.
objEmail.To.Add([Ô]<[Ô] & destino & [Ô]>[Ô])

Dim priority As String = [Ô]System.Net.Mail.MailPriority.[Ô] And [Ô]prioridade[Ô]

[ô]Define a prioridade do e-mail.
objEmail.Priority = priority

[ô]Define o formato do e-mail HTML (caso não queira HTML alocar valor false)
objEmail.IsBodyHtml = True

[ô]Define o título do e-mail.
objEmail.Subject = assunto

[ô]Define o corpo do e-mail.
objEmail.Body = [Ô]<b>[Ô] & email & [Ô]</b>[Ô]

[ô]Para evitar problemas com caracteres [Ô]estranhos[Ô], configuramos o Charset para [Ô]ISO-8859-1[Ô]
objEmail.SubjectEncoding = System.Text.Encoding.GetEncoding([Ô]ISO-8859-1[Ô])
objEmail.BodyEncoding = System.Text.Encoding.GetEncoding([Ô]ISO-8859-1[Ô])



[ô]Cria objeto com os dados do SMTP
Dim objSmtp As New System.Net.Mail.SmtpClient(SMTP, porta)

[ô]Alocamos o endereço do host para enviar os e-mails
objSmtp.Credentials = New System.Net.NetworkCredential(dequemenvio, senha)
objSmtp.Host = SMTP
objSmtp.Port = porta

[ô]Caso utilize conta de email do exchange da locaweb deve habilitar o SSL
[ô]objEmail.EnableSsl = true;

[ô]Enviamos o e-mail através do método .send()

objSmtp.Send(objEmail)
[ô]excluímos o objeto de e-mail da memória
objEmail.Dispose()
[ô]anexo.Dispose();
End Function
End Class


E o código da form

  Imports enviando_email
Imports System.Net
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim add As enviando_email.envio

add.envio(CDbl([Ô]oi[Ô]), CDbl([Ô]email[Ô]), CDbl([Ô]email[Ô]), CDbl([Ô]oi[Ô]), CDbl([Ô]smtp.gmail.com[Ô]), CDbl([Ô]senha[Ô]), CDbl([Ô]995[Ô]), CDbl([Ô]High[Ô])).ToString()

End Sub


Porem da erro quando executo.

Poderiam me ajudar?
NILSONTRES 01/02/2014 20:38:35
#434058
Resposta escolhida
Você esqueceu do principal, a mensagem de erro.
PEDROALSOI 02/02/2014 09:48:17
#434067
Citação:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidCastException: Conversion from string [Ô]oi[Ô] to type [ô]Double[ô] is not valid. ---> System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat)
--- End of inner exception stack trace ---
at Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value)
at Enviando_email_form.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\user\documents\visual studio 2010\Projects\enviando email\Enviando email form\Form1.vb:line 8
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18051 built by: FX45RTMGDR
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Enviando email form
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/user/Documents/Visual%20Studio%202010/Projects/enviando%20email/Enviando%20email%20form/bin/Debug/Enviando%20email%20form.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 10.0.0.0
Win32 Version: 11.0.50709.17929 built by: FX45RTMREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18045 built by: FX45RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18046 built by: FX45RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18022 built by: FX45RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
enviando email
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/user/Documents/Visual%20Studio%202010/Projects/enviando%20email/Enviando%20email%20form/bin/Debug/enviando%20email.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging=[Ô]true[Ô] />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.


PEDROALSOI 02/02/2014 10:06:07
#434072
Eu tentei modificar o dll mas ainda deu erro.
Ficou o dll assim:
  Imports System.Net
Public Class envio
Public Function envio(ByVal email As Double, ByVal destino As Double, ByVal dequemenvio As Double, ByVal assunto As Double, ByVal SMTP As Double, ByVal senha As Double, ByVal porta As Double, ByVal prioridade As Double)
Dim enviado As Double
[ô]Define os dados do e-mail
[ô]Dim nomeRemetente As String
[ô]Dim emailRemetente As String

[ô]Dim emailComCopia As String
[ô]Dim emailComCopiaOculta As String

[ô]emailComCopia = [Ô]email@comcopia.com.br[Ô]
[ô]emailComCopiaOculta = [Ô]email@comcopiaoculta.com.br[Ô]


[ô]Host da porta SMTP

SMTP = SMTP

[ô]Dim assuntoMensagem As String
[ô]Dim conteudoMensagem As String

[ô]assuntoMensagem = [Ô]Teste de envio de emails usando System.Net.Mail em VB.NET[Ô]
[ô]conteudoMensagem = [Ô]Teste de envio de emails usando System.Net.Mail em VB.NET[Ô]


[ô]Cria objeto com dados do e-mail.
Dim objEmail As New System.Net.Mail.MailMessage()

[ô]Define o Campo From e ReplyTo do e-mail.
objEmail.From = New System.Net.Mail.MailAddress([Ô]<[Ô] & dequemenvio & [Ô]>[Ô])
[ô]objEmail.ReplyTo = New System.Net.Mail.MailAddress([Ô]Nome <email@seudominio.com.br>[Ô])

[ô]Define os destinatários do e-mail.
objEmail.To.Add([Ô]<[Ô] & destino & [Ô]>[Ô])

Dim priority As String = [Ô]System.Net.Mail.MailPriority.[Ô] And [Ô]prioridade[Ô]

[ô]Define a prioridade do e-mail.
objEmail.Priority = priority

[ô]Define o formato do e-mail HTML (caso não queira HTML alocar valor false)
objEmail.IsBodyHtml = True

[ô]Define o título do e-mail.
objEmail.Subject = assunto

[ô]Define o corpo do e-mail.
objEmail.Body = [Ô]<b>[Ô] & email & [Ô]</b>[Ô]

[ô]Para evitar problemas com caracteres [Ô]estranhos[Ô], configuramos o Charset para [Ô]ISO-8859-1[Ô]
objEmail.SubjectEncoding = System.Text.Encoding.GetEncoding([Ô]ISO-8859-1[Ô])
objEmail.BodyEncoding = System.Text.Encoding.GetEncoding([Ô]ISO-8859-1[Ô])



[ô]Cria objeto com os dados do SMTP
Dim objSmtp As New System.Net.Mail.SmtpClient(SMTP, porta)

[ô]Alocamos o endereço do host para enviar os e-mails
objSmtp.Credentials = New System.Net.NetworkCredential(dequemenvio, senha)
objSmtp.Host = SMTP
objSmtp.Port = porta

[ô]Caso utilize conta de email do exchange da locaweb deve habilitar o SSL
[ô]objEmail.EnableSsl = true;

[ô]Enviamos o e-mail através do método .send()

objSmtp.Send(objEmail)
[ô]excluímos o objeto de e-mail da memória
objEmail.Dispose()
[ô]anexo.Dispose();
Return enviado
End Function
End Class
NILSONTRES 02/02/2014 13:02:10
#434080
Olha a mensagem:

Citação:

System.InvalidCastException: Conversion from string [Ô]oi[Ô] to type [ô]Double[ô] is not valid. ---> System.FormatException: Input string was not in a


Você esta converto string para double. é de fato mesmo, olha só vc esta convertendo tudo.
Citação:

add.envio(CDbl([Ô]oi[Ô]), CDbl([Ô]email[Ô]), CDbl([Ô]email[Ô]), CDbl([Ô]oi[Ô]), CDbl([Ô]smtp.gmail.com[Ô]), CDbl([Ô]senha[Ô]), CDbl([Ô]995[Ô]), CDbl([Ô]High[Ô])).ToString()



CDbl, converte para Double.
O que acontece, nós programadores perdemos muito tempo pela falta de aprender a ler as mensagens de erro e por falta de atenção, eu mesmo cometi isso aqui nesse tópico, se eu tivesse prestado atenção não teria nem te perguntado qual a mensagem de erro, pois a linha citada acima demonstra claramente o erro.
Mas faz parte.

PEDROALSOI 02/02/2014 13:06:06
#434082
Ok vou tentar não colocar o CDbl
NILSONTRES 02/02/2014 13:10:27
#434083
Citação:

Public Function envio(ByVal email As Double, ByVal destino As Double, ByVal dequemenvio As Double, ByVal assunto As Double, ByVal SMTP As Double,


Voce tem que colocar string para string.
double é dupla precisão, 0.00 ou 0 ou 0,00
PEDROALSOI 02/02/2014 13:10:43
#434084
Agora deu o erro:

Citação:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at Enviando_email_form.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\user\documents\visual studio 2010\Projects\enviando email\Enviando email form\Form1.vb:line 8
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18051 built by: FX45RTMGDR
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Enviando email form
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/user/Documents/Visual%20Studio%202010/Projects/enviando%20email/Enviando%20email%20form/bin/Debug/Enviando%20email%20form.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 10.0.0.0
Win32 Version: 11.0.50709.17929 built by: FX45RTMREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18045 built by: FX45RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18046 built by: FX45RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18022 built by: FX45RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
enviando email
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/user/Documents/Visual%20Studio%202010/Projects/enviando%20email/Enviando%20email%20form/bin/Debug/enviando%20email.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging=[Ô]true[Ô] />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.





E troquei o inicio do dll:

  Public Function envio(ByVal email As String, ByVal destino As String, ByVal dequemenvio As String, ByVal assunto As String, ByVal SMTP As String, ByVal senha As String, ByVal porta As String, ByVal prioridade As String) 


E a form:

Dim add As enviando_email.envio

add.envio(([Ô]oi[Ô]), ([Ô]email[Ô]), ([Ô]email[Ô]), ([Ô]oi[Ô]), ([Ô]smtp.gmail.com[Ô]), ([Ô]senha[Ô]), ([Ô]995[Ô]), ([Ô]High[Ô])).ToString()


NILSONTRES 02/02/2014 13:18:29
#434085
Opa, gostei das novas cores da fonte do vbmania.


Citação:

Dim oMail As New MailMessage() [ô] Cria o Objeto de Email
Dim oSMTP As New SmtpClient(CBO_SMTP.Text)
oSMTP.Port = CBO_PORTA.Text.Trim
oMail.From = New MailAddress(CBO_EMAIL.Text)
oMail.To.Add(TXT_PARA_EMAIL.Text.Trim.ToLower)

If TXT_PARA_CC_EMAIL.Text.Trim <> [Ô][Ô] Then
oMail.Bcc.Add(TXT_PARA_CC_EMAIL.Text.Trim.ToLower)
End If
[ô]oMail.CC.Add([Ô]eu@eu.com.br[Ô])


oMail.Headers.Add([Ô]Disposition-Notification-To[Ô], CBO_EMAIL.Text)
oMail.Priority = MailPriority.High
oMail.Subject = TXT_ASSUNTO.Text.Trim.ToUpper
oMail.Attachments.Add(New Attachment([Ô]c:\Orçamento.pdf[Ô]))
oMail.IsBodyHtml = True
If CHQ_IMG.Checked = False Then
oMail.Body = Replace(TXT_MENSAGEM.Text.Trim.ToUpper, vbLf, [Ô]<BR>[Ô])
oSMTP.Timeout = 1000000
oSMTP.Credentials = New System.Net.NetworkCredential(CBO_EMAIL.Text, _SENHA_SMTP)
Else
oMail.Body = New StreamReader(LBL_IMG.Text.Trim).ReadToEnd()
oSMTP.Timeout = 1000000
oSMTP.Credentials = New System.Net.NetworkCredential(CBO_EMAIL.Text, _SENHA_SMTP)
Dim body As String = [Ô]<font size=4 face=Trebuchet>[Ô] & Replace(TXT_MENSAGEM.Text.Trim, vbLf, [Ô]<BR>[Ô]) & [Ô]</font>[Ô] & [Ô]<br><br><br>[Ô] & [Ô]<img src=[Ô][Ô]cid:Imagem1[Ô][Ô] /><br>[Ô]
Dim view As AlternateView = AlternateView.CreateAlternateViewFromString(body, Nothing, MediaTypeNames.Text.Html)
Dim resource As New LinkedResource(LBL_IMG.Text)
resource.ContentId = [Ô]Imagem1[Ô]
view.LinkedResources.Add(resource)
oMail.AlternateViews.Add(view)
End If

oSMTP.Send(oMail)
oMail.Dispose()



Da uma olhada nesse exemplo que já funciona, e já tem alguns recursos de anexo e imagens, ve se te ajuda.
PEDROALSOI 02/02/2014 13:27:21
#434087
Eu consigo enviar email mas quero por dll
PEDROALSOI 02/02/2014 14:35:42
#434088
O que quero saber e como consigo o valor de uma variável da form no dll
Tópico encerrado , respostas não são mais permitidas