Newsgroup: it.comp.lang.visual-basic
Titolo: Da C# aVisual Basic 2005

Ciao ragazzi ho il seguente codice c# e vorrei convertirlo in VB 2005
chi mi può aiutare?
Grazie in anticipo a chi mi risponderà...
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
// Neded for [DllImport]
using System.Runtime.InteropServices;
using System.Text;
namespace WinSCardApp
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
    {
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private int nContext;				//Card reader context handle - DWORD
        private int nCard;					//Connection handle - DWORD
        private int nActiveProtocol;
        private StatusStrip statusStrip1;
        private ToolStripStatusLabel toolStripStatusLabel1;
        private MenuStrip menuStrip1;
        private ToolStripMenuItem fieToolStripMenuItem;
        private ToolStripMenuItem exitiToolStripMenuItem;
        private Button button1;
        private Button button2;
        private Button button3;
        private Panel panel1;        //T0/T1
        private string readername;
        private Button button4;
        private Button button5;
        private Button button6;
		// WinSCard API's to be imported
		[DllImport("WinScard.dll")]
		public static extern int SCardEstablishContext(uint dwScope, int
nNotUsed1,int nNotUsed2, ref int phContext);
		[DllImport("WinScard.dll")]
		public static extern int SCardReleaseContext(int phContext);
		[DllImport("WinScard.dll")]
		public static extern int SCardConnect(int hContext, string
cReaderName,	uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref
int ActiveProtocol);
        [DllImport("WinScard.dll")]
		public static extern int SCardDisconnect(int hCard, int Disposition);
		[DllImport("WinScard.dll")]
		public static extern int SCardListReaderGroups(int hContext, ref
string cGroups, ref int nStringSize);
		[DllImport("WinScard.dll")]
		public static extern int SCardListReaders(int hContext, string
cGroups,	ref string cReaderLists, ref int nReaderCount);
		[DllImport("WinScard.dll")]
		public static extern int SCardFreeMemory(int hContext, string
cResourceToFree);
		[DllImport("WinScard.dll")]
		public static extern int SCardGetAttrib(int hContext, uint dwAttrId,
ref byte[] bytRecvAttr, ref int nRecLen);
        [DllImport("WinScard.dll")]
        public static extern int SCardTransmit(int hCard, ref
SCARD_IO_REQUEST pioSendPci, byte[] pbSendBuffer, int cbSendLength, ref
SCARD_IO_REQUEST pioRecvPci, ref byte pbRecvBuffer, ref int
pcbRecvLength);
		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.statusStrip1 = new System.Windows.Forms.StatusStrip();
            this.toolStripStatusLabel1 = new
System.Windows.Forms.ToolStripStatusLabel();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fieToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
            this.exitiToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.panel1 = new System.Windows.Forms.Panel();
            this.button4 = new System.Windows.Forms.Button();
            this.button5 = new System.Windows.Forms.Button();
            this.button6 = new System.Windows.Forms.Button();
            this.statusStrip1.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            //
            // statusStrip1
            //
            this.statusStrip1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
            this.toolStripStatusLabel1});
            this.statusStrip1.Location = new System.Drawing.Point(0,
419);
 
this.statusStrip1.Name
 = "statusStrip1";
            this.statusStrip1.Size = new System.Drawing.Size(708, 22);
            this.statusStrip1.TabIndex = 4;
            this.statusStrip1.Text = "statusStrip1";
            //
            // toolStripStatusLabel1
            //
 
this.toolStripStatusLabel1.Name
 = "toolStripStatusLabel1";
            this.toolStripStatusLabel1.Size = new
System.Drawing.Size(109, 17);
            this.toolStripStatusLabel1.Text = "toolStripStatusLabel1";
            //
            // menuStrip1
            //
            this.menuStrip1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
            this.fieToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
 
this.menuStrip1.Name
 = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(708, 24);
            this.menuStrip1.TabIndex = 5;
            this.menuStrip1.Text = "menuStrip1";
            //
            // fieToolStripMenuItem
            //
            this.fieToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
            this.exitiToolStripMenuItem});
 
this.fieToolStripMenuItem.Name
 = "fieToolStripMenuItem";
            this.fieToolStripMenuItem.Size = new
System.Drawing.Size(35, 20);
            this.fieToolStripMenuItem.Text = "File";
            this.fieToolStripMenuItem.Click += new
System.EventHandler(this.fieToolStripMenuItem_Click);
            //
            // exitiToolStripMenuItem
            //
 
this.exitiToolStripMenuItem.Name
 =
"exitiToolStripMenuItem";
            this.exitiToolStripMenuItem.Size = new
System.Drawing.Size(103, 22);
            this.exitiToolStripMenuItem.Text = "Exit";
            this.exitiToolStripMenuItem.Click += new
System.EventHandler(this.exitiToolStripMenuItem_Click);
            //
            // button1
            //
            this.button1.Font = new System.Drawing.Font("Microsoft Sans
Serif", 15.75F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button1.Location = new System.Drawing.Point(12, 47);
 
this.button1.Name
 = "button1";
            this.button1.Size = new System.Drawing.Size(239, 76);
            this.button1.TabIndex = 6;
            this.button1.Text = "Watch ";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new
System.EventHandler(this.button1_Click_1);
            //
            // button2
            //
            this.button2.Font = new System.Drawing.Font("Microsoft Sans
Serif", 15.75F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button2.Location = new System.Drawing.Point(12, 139);
 
this.button2.Name
 = "button2";
            this.button2.Size = new System.Drawing.Size(239, 76);
            this.button2.TabIndex = 7;
            this.button2.Text = "Gestione Ticket";
            this.button2.UseVisualStyleBackColor = true;
            //
            // button3
            //
            this.button3.Font = new System.Drawing.Font("Microsoft Sans
Serif", 15.75F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button3.Location = new System.Drawing.Point(12, 234);
 
this.button3.Name
 = "button3";
            this.button3.Size = new System.Drawing.Size(239, 76);
            this.button3.TabIndex = 8;
            this.button3.Text = "Gestione PDF";
            this.button3.UseVisualStyleBackColor = true;
            //
            // panel1
            //
            this.panel1.Location = new System.Drawing.Point(290, 47);
 
this.panel1.Name
 = "panel1";
            this.panel1.Size = new System.Drawing.Size(390, 263);
            this.panel1.TabIndex = 9;
            //
            // button4
            //
            this.button4.Location = new System.Drawing.Point(512, 341);
 
this.button4.Name
 = "button4";
            this.button4.Size = new System.Drawing.Size(75, 23);
            this.button4.TabIndex = 10;
            this.button4.Text = "Stop";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Visible = false;
            this.button4.Click += new
System.EventHandler(this.button4_Click);
            //
            // button5
            //
            this.button5.Location = new System.Drawing.Point(605, 341);
 
this.button5.Name
 = "button5";
            this.button5.Size = new System.Drawing.Size(75, 23);
            this.button5.TabIndex = 11;
            this.button5.Text = "Pause";
            this.button5.UseVisualStyleBackColor = true;
            this.button5.Visible = false;
            this.button5.Click += new
System.EventHandler(this.button5_Click);
            //
            // button6
            //
            this.button6.Location = new System.Drawing.Point(420, 341);
 
this.button6.Name
 = "button6";
            this.button6.Size = new System.Drawing.Size(75, 23);
            this.button6.TabIndex = 12;
            this.button6.Text = "Play";
            this.button6.UseVisualStyleBackColor = true;
            this.button6.Visible = false;
            this.button6.Click += new
System.EventHandler(this.button6_Click);
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(708, 441);
            this.Controls.Add(this.button6);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.statusStrip1);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Edmaster Bouquet";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.statusStrip1.ResumeLayout(false);
            this.statusStrip1.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();
		}
		#endregion
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			Application.Run(new Form1());
		}
		private void Form1_Load(object sender, System.EventArgs e)
		{
            //First step in using smart cards is
CSardEstablishContext()
            uint nContext = 2;		//system
            int nNotUsed1 = 0;
            int nNotUsed2 = 0;
            this.nContext = 0;		//handle to context - SCARDCONTEXT
            string error = "";
            int nRetVal1 = SCardEstablishContext(nContext, nNotUsed1,
nNotUsed2, ref this.nContext);
            if (nRetVal1 != 0)
            {
                error = "error";
            }
            //next we split up the null delimited strings into a string
array
            char[] delimiter = new char[1];
            delimiter[0] = Convert.ToChar(0);
            //Next we need to call the  SCardListReaderGroups() to find
reader groups to use
            string cGroupList = "" + Convert.ToChar(0);
            int nStringSize = -1;	//SCARD_AUTOALLOCATE
            int nRetVal2 = SCardListReaderGroups(this.nContext, ref
cGroupList, ref nStringSize);
            if (nRetVal2 != 0)
            {
                error = "error";
            }
            string[] cGroups = cGroupList.Split(delimiter);
            string cReaderList = "" + Convert.ToChar(0);
            int nReaderCount = -1;
            // Get the reader list
            int nRetVal4 = SCardListReaders(this.nContext, cGroups[0],
ref cReaderList, ref nReaderCount);
            if (nRetVal4 != 0)
            {
                error = "error";
            }
            if (error == "") {
                string[] cReaders = cReaderList.Split(delimiter);
                toolStripStatusLabel1.Text = cReaders[0];
                this.readername = cReaders[0];
                connect();
                verifypin();
            } else {
                if (MessageBox.Show("Errore di comunicazione lettore
non presente " , "Error",
                MessageBoxButtons.OK, MessageBoxIcon.Question) ==
DialogResult.OK)
                {
                    Application.Exit();
                }
            }
		}
        public struct SCARD_IO_REQUEST
        {
            public int Protocol;
            public int PciLength;
        }
		private void button1_Click(object sender, System.EventArgs e)
		{
		}
        private void connect(){
            			uint nShareMode      = 1;			//exclusive
			uint nPrefProtocol   = 2;	//default PTS
			this.nCard           = 0;
			this.nActiveProtocol = 0;
			int nRetVal6 = SCardConnect(this.nContext, this.readername,
nShareMode, nPrefProtocol, ref this.nCard, ref this.nActiveProtocol);
            if (nRetVal6 != 0)
                DisplaySCError(nRetVal6, "SCardConnect()");
        }
        private void button2_Click(object sender, EventArgs e)
        {
        }
        private void DisplaySCError(int nErrCode, string cText)
        {
            string cErrString = "";
            string ErrCode = String.Format("0x{0:X}", nErrCode);
            switch (ErrCode)
            {
                case "0x80100001":
                    cErrString = "Internal Error";
                    break;
                case "0x80100002":
                    cErrString = "Cancelled";
                    break;
                case "0x80100003":
                    cErrString = "Invalid Handle";
                    break;
                case "0x80100004":
                    cErrString = "Invalid Parameter";
                    break;
                case "0x80100005":
                    cErrString = "Invalid Target";
                    break;
                case "0x80100006":
                    cErrString = "No Memory";
                    break;
                case "0x80100007":
                    cErrString = "Waited Too Long";
                    break;
                case "0x80100008":
                    cErrString = "Insufficient Buffer";
                    break;
                case "0x80100009":
                    cErrString = "Unknown Reader";
                    break;
                case "0x8010000A":
                    cErrString = "Timeout";
                    break;
                case "0x8010000B":
                    cErrString = "Sharing Violation";
                    break;
                case "0x8010000C":
                    cErrString = "Nessuna carta presente";
                    break;
                case "0x8010000D":
                    cErrString = "Carta non riconosciuta";
                    break;
                case "0x8010000E":
                    cErrString = "Can't Dispose";
                    break;
                case "0x8010000F":
                    cErrString = "Proto Mismatch";
                    break;
                case "0x80100010":
                    cErrString = "Not Ready";
                    break;
                case "0x80100011":
                    cErrString = "Invalid Value";
                    break;
                case "0x80100012":
                    cErrString = "System Cancelled";
                    break;
                case "0x80100013":
                    cErrString = "Comm Error";
                    break;
                case "0x80100014":
                    cErrString = "Unknown Error";
                    break;
                case "0x80100015":
                    cErrString = "Invalid ATR";
                    break;
                case "0x80100016":
                    cErrString = "Not Transacted";
                    break;
                case "0x80100017":
                    cErrString = "Reader Unavailable";
                    break;
                case "0x80100018":
                    cErrString = "Shutdown";
                    break;
                case "0x80100019":
                    cErrString = "PCI Too Small";
                    break;
                case "0x8010001A":
                    cErrString = "Reader Unsupported";
                    break;
                case "0x8010001B":
                    cErrString = "Duplicate Reader";
                    break;
                case "0x8010001C":
                    cErrString = "Card Unsupported";
                    break;
                case "0x8010001D":
                    cErrString = "No Service";
                    break;
                case "0x8010001E":
                    cErrString = "Service Stopped";
                    break;
                case "0x80100065":
                    cErrString = "Unsupported Card";
                    break;
                case "0x80100066":
                    cErrString = "Unresponsive Card";
                    break;
                case "0x80100067":
                    cErrString = "Unpowered Card";
                    break;
                case "0x80100068":
                    cErrString = "Reset Card";
                    break;
                case "0x80100069":
                    cErrString = "Carta non presente";
                    break;
                default:
                    cErrString = "Unknown PC/SC Error Code - No Further
Information Is Available";
                    break;
            }
           /* MessageBox.Show(String.Format("Error Code: 0x{0:X}\n\n" +
cErrString + "\n\n" + cText+this.readername, nErrCode),
                "Smart Card PC/SC Error");*/
            if (MessageBox.Show("Errore di comunicazione "+ cErrString,
"Error",
            MessageBoxButtons.OK, MessageBoxIcon.Question) ==
DialogResult.OK)
            {
                Application.Exit();
            }
        }
        private void listBox1_SelectedIndexChanged(object sender,
EventArgs e)
        {
        }
        private void verifypin() {
            string RetVal = "";
            RetVal = CallSCardTransmit("00 20 00 02 08 31 32 33 34 35
36 37 39", "Admin Password");
        }
        private void button3_Click(object sender, EventArgs e)
        {
        }
        private byte[] HexStringToByteArray(string hexStringIn)
        {
            char[] Delimiter = new char[1] { ' ' };
            string[] HexNumbers = hexStringIn.Split(Delimiter);
            byte[] NewByteArray = new byte[HexNumbers.Length];
            for (int i = 0; i < HexNumbers.Length; i++)
            {
                NewByteArray[i] = byte.Parse(HexNumbers[i],
System.Globalization.NumberStyles.AllowHexSpecifier);
            }
            return NewByteArray;
        }
        public string CallSCardTransmit(string sendString, string
friendlyExplanation)
        {
            int RetVal = 0;
            byte[] SendBytes = HexStringToByteArray(sendString);
            int SendLength = SendBytes.Length;
            SCARD_IO_REQUEST SendPci;	//structure is defined below
            SendPci.Protocol = this.nActiveProtocol;
            SendPci.PciLength = 8;
            //IntPtr RecvBytesPtr = new IntPtr(0);
            int RecvLength = 257;
            byte[] RecvBytes = new byte[RecvLength];
            SCARD_IO_REQUEST RecvPci;
            RecvPci.Protocol = this.nActiveProtocol;
            RecvPci.PciLength = 8;
            RetVal = SCardTransmit(this.nCard, ref SendPci, SendBytes,
SendLength,ref RecvPci, ref RecvBytes[0], ref RecvLength);
            if (RetVal == 0)
            {
                System.Text.StringBuilder ResultString = new
System.Text.StringBuilder("");
                for (int i = 0; i < RecvLength; i++)
                {
                    ResultString.Append(RecvBytes[i].ToString("X2") + "
");
                }
                if (friendlyExplanation.Trim().Length > 0)
                    MessageBox.Show("Carta Verificata, Applicazione
attiva", "Successful Call!");
                return ResultString.ToString();
            }
            else
            {
                DisplaySCError(RetVal, friendlyExplanation);
                return "ERROR";
            }
        }
        private void fieToolStripMenuItem_Click(object sender,
EventArgs e)
        {
        }
        private void exitiToolStripMenuItem_Click(object sender,
EventArgs e)
        {
            Application.Exit();
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            int height = panel1.Height;
             int width = panel1.Width;
            panel1.Width = width;
            panel1.Height = height;
            button4.Visible = true;
            button5.Visible = true;
            button6.Visible = true;
        }
        private void button4_Click(object sender, EventArgs e)
        {
        }
        private void button5_Click(object sender, EventArgs e)
        {
        }
        private void button6_Click(object sender, EventArgs e)
        {
        }
	}
}
ciao excess
P.S. per l'istruzione DLLIMPORTS il porblema è gia risolto...
grazie ancora

 P.S. per l'istruzione DLLIMPORTS il porblema è gia risolto...
Oh, allora hai quasi finito ;)
Domanda: ma perchè devi convertire tutta 'sta roba?
Non ti conviene tenertela in c#?
Ciao 


ciao fabio Grazie infinite per la risposta....
essendo novello del mondo visual basic e ignaro del c#  volevo fare
delle prove per usare delle smart card e verificare che il pin sia
corretto....
volevo farlo in vb perchè in c# non saprei + come proseguire la mia
applicazione...se ci fosse un modo di usare il codice c# in visual
basic mi andrebbe bene lo stesso...
grazie mille di nuovo


ciao ragazzi ho fatto come mi ha detto fabio e ho convertito tutto
mi da errore nel codice seguente...chi mi aiuta???
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
' Neded for [DllImport]
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
    Inherits System.Windows.Forms.Form
    '/ <summary>
    '/ Required designer variable.
    '/ </summary>
    Private nContext As Integer 'Card reader context handle - DWORD
    Private nCard As Integer 'Connection handle - DWORD
    Private nActiveProtocol As Integer
    Private readername As String
    <DllImport("winscard.dll")> _
    Public Shared Function SCardEstablishContext(ByVal dwScope As
UInteger, ByVal nNotUsed1 As Integer, ByVal nNotUsed2 As Integer, ByRef
phContext As Integer) As Integer
    End Function
    <DllImport("winscard.dll")> _
    Public Shared Function SCardReleaseContext(ByVal phContext As
Integer) As Integer
    End Function
    <DllImport("winscard.dll")> _
    Public Shared Function SCardConnect(ByVal hContext As Integer,
ByVal cReaderName As String, ByVal dwShareMode As UInteger, ByVal
dwPrefProtocol As UInteger, ByRef phCard As Integer, ByRef
ActiveProtocol As Integer) As Integer
    End Function
    <DllImport("winscard.dll")> _
    Public Shared Function SCardDisconnect(ByVal hCard As Integer,
ByVal Disposition As Integer) As Integer
    End Function
    <DllImport("winscard.dll")> _
    Public Shared Function SCardListReaderGroups(ByVal hContext As
Integer, ByRef cGroups As String, ByRef nStringSize As Integer) As
Integer
    End Function
    <DllImport("winscard.dll")> _
    Public Shared Function SCardListReaders(ByVal hContext As Integer,
ByVal cGroups As String, ByRef cReaderLists As String, ByRef
nReaderCount As Integer) As Integer
    End Function
    <DllImport("winscard.dll")> _
    Public Shared Function SCardFreeMemory(ByVal hContext As Integer,
ByVal cResourceToFree As String) As Integer
    End Function
    <DllImport("winscard.dll")> _
    Public Shared Function SCardGetAttrib(ByVal hContext As Integer,
ByVal dwAttrId As UInteger, ByRef bytRecvAttr As Byte, ByRef nRecLen As
Integer) As Integer
    End Function
    <DllImport("winscard.dll")> _
    Public Shared Function SCardTransmit(ByVal hCard As Integer, ByRef
pioSendPci As SCardVB.Form1.SCARD_IO_REQUEST, ByVal pbSendBuffer As
Byte, ByVal cbSendLength As Integer, ByRef pioRecvPci As
SCARD_IO_REQUEST, ByRef pbRecvBuffer As Byte, ByRef pcbRecvLength As
Integer) As Integer
    End Function
    Public Structure SCARD_IO_REQUEST
        Public Protocol As Integer
        Public PciLength As Integer
    End Structure 'SCARD_IO_REQUEST
    Private Sub connect()
        Dim nShareMode As System.UInt32 = 1 'ToDo: Unsigned Integers
not supported 'exclusive
        Dim nPrefProtocol As System.UInt32 = 2 'ToDo: Unsigned Integers
not supported 'default PTS
        Me.nCard = 0
        Me.nActiveProtocol = 0
        Dim nRetVal6 As Integer = SCardConnect(Me.nContext,
Me.readername, nShareMode, nPrefProtocol, (Me.nCard),
(Me.nActiveProtocol))
        If nRetVal6 <> 0 Then
            DisplaySCError(nRetVal6, "SCardConnect()")
        End If
    End Sub 'connect
    Private Sub DisplaySCError(ByVal nErrCode As Integer, ByVal cText
As String)
        Dim cErrString As String = ""
        Dim ErrCode As String = [String].Format("0x{0:X}", nErrCode)
        Select Case ErrCode
            Case "0x80100001"
                cErrString = "Internal Error"
            Case "0x80100002"
                cErrString = "Cancelled"
            Case "0x80100003"
                cErrString = "Invalid Handle"
            Case "0x80100004"
                cErrString = "Invalid Parameter"
            Case "0x80100005"
                cErrString = "Invalid Target"
            Case "0x80100006"
                cErrString = "No Memory"
            Case "0x80100007"
                cErrString = "Waited Too Long"
            Case "0x80100008"
                cErrString = "Insufficient Buffer"
            Case "0x80100009"
                cErrString = "Unknown Reader"
            Case "0x8010000A"
                cErrString = "Timeout"
            Case "0x8010000B"
                cErrString = "Sharing Violation"
            Case "0x8010000C"
                cErrString = "Nessuna carta presente"
            Case "0x8010000D"
                cErrString = "Carta non riconosciuta"
            Case "0x8010000E"
                cErrString = "Can't Dispose"
            Case "0x8010000F"
                cErrString = "Proto Mismatch"
            Case "0x80100010"
                cErrString = "Not Ready"
            Case "0x80100011"
                cErrString = "Invalid Value"
            Case "0x80100012"
                cErrString = "System Cancelled"
            Case "0x80100013"
                cErrString = "Comm Error"
            Case "0x80100014"
                cErrString = "Unknown Error"
            Case "0x80100015"
                cErrString = "Invalid ATR"
            Case "0x80100016"
                cErrString = "Not Transacted"
            Case "0x80100017"
                cErrString = "Reader Unavailable"
            Case "0x80100018"
                cErrString = "Shutdown"
            Case "0x80100019"
                cErrString = "PCI Too Small"
            Case "0x8010001A"
                cErrString = "Reader Unsupported"
            Case "0x8010001B"
                cErrString = "Duplicate Reader"
            Case "0x8010001C"
                cErrString = "Card Unsupported"
            Case "0x8010001D"
                cErrString = "No Service"
            Case "0x8010001E"
                cErrString = "Service Stopped"
            Case "0x80100065"
                cErrString = "Unsupported Card"
            Case "0x80100066"
                cErrString = "Unresponsive Card"
            Case "0x80100067"
                cErrString = "Unpowered Card"
            Case "0x80100068"
                cErrString = "Reset Card"
            Case "0x80100069"
                cErrString = "Carta non presente"
            Case Else
                cErrString = "Unknown PC/SC Error Code - No Further
Information Is Available"
        End Select
        ' MessageBox.Show(String.Format("Error Code: 0x{0:X}\n\n" +
cErrString + "\n\n" + cText+this.readername, nErrCode),
        '"Smart Card PC/SC Error");
        If MessageBox.Show("Errore di comunicazione " + cErrString,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Question) =
DialogResult.OK Then
            Application.Exit()
        End If
    End Sub 'DisplaySCError
    Private Function HexStringToByteArray(ByVal hexStringIn As String)
As Byte()
'
'
'
'ERRORE  n.2 parte dalla rigua seguente
        Dim Delimiter(1) As Char = {" "c}
        Dim HexNumbers As String() = hexStringIn.Split(Delimiter)
        Dim NewByteArray(HexNumbers.Length) As Byte
        Dim i As Integer
        For i = 0 To HexNumbers.Length - 1
            NewByteArray(i) = Byte.Parse(HexNumbers(i),
System.Globalization.NumberStyles.AllowHexSpecifier)
        Next i
        Return NewByteArray
    End Function 'HexStringToByteArray
    Public Function CallSCardTransmit(ByVal sendString As String, ByVal
friendlyExplanation As String) As String
        Dim RetVal As Integer = 0
        Dim SendBytes As Byte() = HexStringToByteArray(sendString)
        Dim SendLength As Integer = SendBytes.Length
        Dim SendPci As SCARD_IO_REQUEST 'structure is defined below
        SendPci.Protocol = Me.nActiveProtocol
        SendPci.PciLength = 8
        'IntPtr RecvBytesPtr = new IntPtr(0);
        Dim RecvLength As Integer = 257
        Dim RecvBytes(RecvLength) As Byte
        Dim RecvPci As SCARD_IO_REQUEST
        RecvPci.Protocol = Me.nActiveProtocol
        RecvPci.PciLength = 8
'
'
'
'ERRORE N. 3  parte dalla riga seguente
        RetVal = SCardTransmit(Me.nCard, SendPci, SendBytes,
SendLength, RecvPci, RecvBytes(0), RecvLength)
        If RetVal = 0 Then
            Dim ResultString As New System.Text.StringBuilder("")
            Dim i As Integer
            For i = 0 To RecvLength - 1
                ResultString.Append((RecvBytes(i).ToString("X2") + "
"))
            Next i
            If friendlyExplanation.Trim().Length > 0 Then
                MessageBox.Show("Carta Verificata, Applicazione
attiva", "Successful Call!")
            End If
            Return ResultString.ToString()
        Else
            DisplaySCError(RetVal, friendlyExplanation)
            Return "ERROR"
        End If
    End Function 'CallSCardTransmit
    Private Sub verifypin()
        Dim RetVal As String = ""
        RetVal = CallSCardTransmit("00 20 00 02 08 31 32 33 34 35 36 37
39", "Admin Password")
    End Sub 'verifypin
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        'First step in using smart cards is CSardEstablishContext()
        Dim nContext As System.UInt32 = 2 'ToDo: Unsigned Integers not
supported 'system
        Dim nNotUsed1 As Integer = 0
        Dim nNotUsed2 As Integer = 0
        Me.nContext = 0 'handle to context - SCARDCONTEXT
        Dim [error] As String = ""
        Dim nRetVal1 As Integer = SCardEstablishContext(nContext,
nNotUsed1, nNotUsed2, (Me.nContext))
        If nRetVal1 <> 0 Then
            [error] = "error"
        End If
        'next we split up the null delimited strings into a string
array
        Dim delimiter(1) As Char
        delimiter(0) = Convert.ToChar(0)
        'Next we need to call the  SCardListReaderGroups() to find
reader groups to use
        Dim cGroupList As String = "" + Convert.ToChar(0)
        Dim nStringSize As Integer = -1 'SCARD_AUTOALLOCATE
        Dim nRetVal2 As Integer = SCardListReaderGroups(Me.nContext,
cGroupList, nStringSize)
        If nRetVal2 <> 0 Then
            [error] = "error"
        End If
        Dim cGroups As String() = cGroupList.Split(delimiter)
        Dim cReaderList As String = "" + Convert.ToChar(0)
        Dim nReaderCount As Integer = -1
        ' Get the reader list
        Dim nRetVal4 As Integer = SCardListReaders(Me.nContext,
cGroups(0), cReaderList, nReaderCount)
        If nRetVal4 <> 0 Then
            [error] = "error"
        End If
        If [error] = "" Then
            Dim cReaders As String() = cReaderList.Split(delimiter)
            ToolStripStatusLabel1.Text = cReaders(0)
            Me.readername = cReaders(0)
            connect()
            verifypin()
        Else
            If MessageBox.Show("Errore di comunicazione lettore non
presente ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Question) =
DialogResult.OK Then
                Application.Exit()
            End If
        End If
    End Sub 'Form1_Load
i due errori sono i seguenti
Errore	2	Inizializzazione esplicita non consentita per matrici
dichiarate con limiti espliciti.	C:\Documents and
Settings\mlivio\Documenti\Visual Studio
2005\Projects\SCardVB\SCardVB\Form1.vb	180	13	SCardVB
Errore	3	Impossibile convertire il valore di tipo "Matrice a 1
dimensioni di Byte." in "Byte".	C:\Documents and
Settings\mlivio\Documenti\Visual Studio
2005\Projects\SCardVB\SCardVB\Form1.vb	207	51	SCardVB
grazie a chi mi risponderà
excess

 mi da errore nel codice seguente...chi mi aiuta???
Beh, allora sei novello anche nel mondo 
vb.net
 :) e dei NG.
Fai una bella cosa, dato che nessuno guarderà tutto il codice che posti, 
posta solo le righe che ti danno errore (magari anche quelle intorno per 
capire il contesto, ad es. che tipo di variabili sono (nell'altro NG sei 
stato già più gentile).
Poi, c'è comunque da fidarni nel convertire tutto tramite traduttore 
automatico e affidarsi al compilatore per capire se tutto funziona ;)
Ciao 


Ciao Fabio
hai ragione sono novello di tutto :-) però sono curioso e testardo e
devo provare fino a quando non riesco...
le due funzioni/procedure che mi danno errore sono
    Private Function HexStringToByteArray(ByVal hexStringIn As String)
As Byte()
        Dim Delimiter(1) As Char = {" "c}
        Dim HexNumbers As String() = hexStringIn.Split(Delimiter)
        Dim NewByteArray(HexNumbers.Length) As Byte
        Dim i As Integer
        For i = 0 To HexNumbers.Length - 1
            NewByteArray(i) = Byte.Parse(HexNumbers(i),
System.Globalization.NumberStyles.AllowHexSpecifier)
        Next i
        Return NewByteArray
    End Function 'HexStringToByteArray
e altro errore qui
    Public Function CallSCardTransmit(ByVal sendString As String, ByVal
friendlyExplanation As String) As String
        Dim RetVal As Integer = 0
        Dim SendBytes As Byte() = HexStringToByteArray(sendString)
        Dim SendLength As Integer = SendBytes.Length
        Dim SendPci As SCARD_IO_REQUEST 'structure is defined below
        SendPci.Protocol = Me.nActiveProtocol
        SendPci.PciLength = 8
        'IntPtr RecvBytesPtr = new IntPtr(0);
        Dim RecvLength As Integer = 257
        Dim RecvBytes(RecvLength) As Byte
        Dim RecvPci As SCARD_IO_REQUEST
        RecvPci.Protocol = Me.nActiveProtocol
        RecvPci.PciLength = 8
        RetVal = SCardTransmit(Me.nCard, SendPci, SendBytes,
SendLength, RecvPci, RecvBytes(0), RecvLength)
        If RetVal = 0 Then
            Dim ResultString As New System.Text.StringBuilder("")
            Dim i As Integer
            For i = 0 To RecvLength - 1
                ResultString.Append((RecvBytes(i).ToString("X2") + "
"))
            Next i
            If friendlyExplanation.Trim().Length > 0 Then
                MessageBox.Show("Carta Verificata, Applicazione
attiva", "Successful Call!")
            End If
            Return ResultString.ToString()
        Else
            DisplaySCError(RetVal, friendlyExplanation)
            Return "ERROR"
        End If
    End Function 'CallSCardTransmit
e gli errori che mi da sono
Errore  2       Inizializzazione esplicita non consentita per matrici
dichiarate con limiti espliciti.        C:\Documents and
Settings\---------\Documenti\Visual Studio
2005\Projects\SCardVB\SCardVB\Form1.vb  180     13      SCardVB
Errore  3       Impossibile convertire il valore di tipo "Matrice a 1
dimensioni di Byte." in "Byte".  C:\Documents and
Settings\--------\Documenti\Visual Studio


 hai ragione sono novello di tutto :-)
Ma in italiano no, spero :)
Ti ho chiesto le righe, non le pagine di codice!
O almeno indica le righe con il problema!
La prima è facile, o almeno, la descrizione mi pare chiarissima:
-->        Dim Delimiter(1) As Char = {" "c}
diventa
Dim Delimiter() As Char = {" "c}
o
Dim Delimiter As Char() = {" "c}
a secondo dei tuoi gusti.
La seconda boh... a occhio è corretta ma è piena di funzioni di cui non hai 
postato la dichiarazione e ancora non so dov'è che va in errore.
Ciao 


:-)
sei troppo paziente e ti ringrazio per questo
questa è la riga
     RetVal = SCardTransmit(Me.nCard, SendPci, SendBytes, SendLength,
RecvPci, RecvBytes(0), RecvLength)
Errore	2	Impossibile convertire il valore di tipo "Matrice a 1
dimensioni di Byte." in "Byte".	C:\Documents and
Settings\mlivio\Documenti\Visual Studio
2005\Projects\SCardVB\SCardVB\Form1.vb	203	51	SCardVB
e mi sottolinea il parametro  SendBytes
la funzione è sempre quella di prima
Public Function CallSCardTransmit(ByVal .....ecc ecc

 Public Function CallSCardTransmit(ByVal .....ecc ecc
Vabbeh, ma allora lo fai apposta!
Sarò paziente ma ti assicuro che è solo una cosa temporanea.
COME CAVOLO FACCIO a capire se i parametri sono passati male se mi cancelli 
la dichiarazione???
Ma va che sei un bell'elemento ecc ecc!
Ciao 


    Public Function CallSCardTransmit(ByVal sendString As String, ByVal
friendlyExplanation As String) As String
        Dim RetVal As Integer = 0
        Dim SendBytes As Byte() = HexStringToByteArray(sendString)
        MsgBox(sendString)
        Dim SendLength As Integer = SendBytes.Length
        Dim SendPci As SCARD_IO_REQUEST 'structure is defined below
        SendPci.Protocol = Me.nActiveProtocol
        SendPci.PciLength = 8
        'IntPtr RecvBytesPtr = new IntPtr(0);
        Dim RecvLength As Integer = 257
        Dim RecvBytes(RecvLength) As Byte
        Dim RecvPci As SCARD_IO_REQUEST
        RecvPci.Protocol = Me.nActiveProtocol
        RecvPci.PciLength = 8
        RetVal = SCardTransmit(Me.nCard, SendPci, SendBytes,
SendLength, RecvPci, RecvBytes(0), RecvLength)
        If RetVal = 0 Then
            Dim ResultString As New System.Text.StringBuilder("")
            Dim i As Integer
            For i = 0 To RecvLength - 1
                ResultString.Append((RecvBytes(i).ToString("X2") + "
"))
            Next i
            If friendlyExplanation.Trim().Length > 0 Then
                MessageBox.Show("Carta Verificata, Applicazione
attiva", "Successful Call!")
            End If
            Return ResultString.ToString()
        Else
            DisplaySCError(RetVal, friendlyExplanation)
            Return "ERROR"
        End If
    End Function 'CallSCardTransmit
e la riga che mi da errore é
        RetVal = SCardTransmit(Me.nCard, SendPci, SendBytes,
SendLength, RecvPci, RecvBytes(0), RecvLength)
al parametro SendBytes

 SendLength, RecvPci, RecvBytes(0), RecvLength)
Stavo per insultarti ma poi ho visto che ho commesso una svista (certo che 
tu mica te ne sei accorto).
L'errore è che la conversione ha toppato.
Il parametro pbSendBuffer di SCardTransmit è stato tradotto in pbSendBuffer 
as Byte mentre se guardi l'originale è pbSendBuffer() As Byte.
Ciao 


Grazie infinite fabio...inizio a vedere qualche risultato.....