Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - DLL in vb6 per .NET
Forum - C# / VB.NET - DLL in vb6 per .NET

Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 7:45
Domenica, 30/11/2008
salve ragazzi.. dovrei fare una dll in vb6 con i winsock per poterli usare su .net.

questo è il codice della DLL

Codice sorgente - presumibilmente VB.NET

  1. Private frm As Form1
  2. Public WithEvents wsk1 As Winsock
  3. Public port As Integer
  4.  
  5. Private Sub Class_Initialize()
  6. Set frm = New Form1
  7.    Load frm
  8. Set wsk1 = frm.Winsock1
  9. End Sub
  10.  
  11. Public Sub ascolta()
  12.   wsk1.LocalPort = port
  13.   wsk1.Listen
  14. End Sub
  15.  
  16. Private Sub wsk1_ConnectionRequest(ByVal requestID As Long)
  17. wsk1.Accept (requestID)
  18. End Sub



e questo il codice per il .NET

Codice sorgente - presumibilmente VB.NET

  1. Public Shared Sub ascoltoporta(ByVal port As Integer)
  2.         Try
  3.             Dim c As New Progetto1.Class1
  4.             c.port = port
  5.             c.ascolta()
  6.         Catch
  7.         End Try
  8.     End Sub



solo che è come se le porte nn si aprissero....nn da nessun errore ma le porte restano chiuse...io non riesco a capire... voi?

PM Quote
Avatar
Gianluca87 (Ex-Member)
Expert


Messaggi: 300
Iscritto: 16/11/2008

Segnala al moderatore
Postato alle 17:00
Domenica, 30/11/2008
Ciao, perchè non usi la classe Socket di .net?
funziona meglio...e non hai bisogno di importare oggetti da vb che non è il massimo...

PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 23:06
Domenica, 30/11/2008
invece di usare il vb6 mi hanno consigliato... se davvero voglio che questo server dc++ possa reggere 10.000 client, di usare le api native del winsock che ha gia windows...

Codice sorgente - presumibilmente VB.NET

  1. Imports System.Text
  2. Imports System.Collections
  3. Imports System.Runtime.InteropServices
  4.  
  5. Public Class CONN
  6.  
  7.     'porta di ascolto
  8.     Public port As Integer
  9.  
  10.     'dichiarazioni per il socket
  11.     Public Const SUCCESS As Integer = 0
  12.     Public Const HIGH_VERSION As Integer = 2
  13.     Public Const LOW_VERSION As Integer = 2
  14.     Public Const WORD_VERSION As Short = 36
  15.  
  16.     'struttura socket
  17.     Public Structure WSAData
  18.         Public wVersion As Short
  19.         Public wHighVersion As Short
  20.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public Description As String
  21.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=129)> Public Status As String
  22.         Public MaxSockets As Integer
  23.         Public MaxUdpDg As Integer
  24.         Public vendorInfoPointer As IntPtr
  25.     End Structure
  26.  
  27.     'struttura address socket
  28.     Public Structure sockaddr
  29.         Dim sa_family As Integer
  30.         Dim sa_data() As Char
  31.     End Structure
  32.  
  33.     'struttura address socket IPV4
  34.     Public Structure sockaddr_in
  35.         Dim sin_family As Integer
  36.         Dim sin_port As Integer
  37.         Dim in_addr As sockaddr
  38.         Dim sin_zero() As Char
  39.     End Structure
  40.  
  41.     'dichiarazione della chiamate alle funzioni che dovro' affettuare
  42.     Declare Function WSAStartup Lib "ws2_32.dll" (ByVal versionRequested As Int16, ByVal infoBuffer As WSAData) As Integer
  43.     Declare Function WSACleanup Lib "ws2_32.dll" () As Int32
  44.     Declare Function accept Lib "ws2_32.dll" (ByVal socketHandle As IntPtr, ByRef socketAddress As sockaddr, ByRef addressLength As Integer) As IntPtr
  45.     Declare Function bind Lib "ws2_32.dll" (ByVal socketHandle As IntPtr, ByRef socketAddress As sockaddr_in, ByVal addressLength As Integer) As Integer
  46.  
  47.  
  48.     Public Sub parti()
  49.         'viene eseguita per prima questa procedura
  50.         Dim resultCode As Integer = 0
  51.         Dim data As WSAData
  52.  
  53.         data = New WSAData
  54.         data.wHighVersion = HIGH_VERSION
  55.         data.wVersion = LOW_VERSION
  56.  
  57.         resultCode = WSAStartup(WORD_VERSION, data)
  58.         If (resultCode = SUCCESS) Then
  59.             WSACleanup()
  60.         End If
  61.  
  62.         'ho inizializzato il motore delle winsocket per modo di dire
  63.         'adesso qui dovrei chiamare la procedura socket che mi restituisce il socket...poi
  64.         'metterlo in ascolto e bla bla bla....
  65.  
  66.     End Sub



pero' non so continuare.... chi è disposto a darmi una mano?

PM Quote
Avatar
Gianluca87 (Ex-Member)
Expert


Messaggi: 300
Iscritto: 16/11/2008

Segnala al moderatore
Postato alle 11:26
Lunedì, 01/12/2008
usare le api di win da c++ è una soluzione....
non è la strada + facile ma sicuramente la + efficiente in termini di performance / utilizzo risorse

PM Quote
Avatar
Gianluca87 (Ex-Member)
Expert


Messaggi: 300
Iscritto: 16/11/2008

Segnala al moderatore
Postato alle 11:28
Lunedì, 01/12/2008
parlando con HeDo effettivamente mi ha suggerito che la maniera migliore per fare una cosa del genere è gestirti le connessioni con una libreria fatta in c++ che usa direttamente le api di winzoz

PM Quote