event handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ankit Aneja

    event handling


    i am using com dll in my project which fires up event

    code in vb is like this
    Option Explicit
    Dim WithEvents p As CLAMXLib.ClamEn gine
    Dim mresult As ClamResult

    Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult)
    Set mresult = result
    End Sub



    in c#

    CLAMXLib.ClamEn gine p;
    ClamResult mResult;

    //now how will i catch events


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: event handling

    Ankit,

    You do this:

    p.OnScanComplet e += new OnScanCompleteE ventHandler(p_O nScanComplete);

    This is a guess based on the event handler type of the event, as well as
    your method, but it should give you the idea.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Ankit Aneja" <efextra@newsgr oups.nospam> wrote in message
    news:eLp%239sKA GHA.3136@TK2MSF TNGP15.phx.gbl. ..[color=blue]
    >
    > i am using com dll in my project which fires up event
    >
    > code in vb is like this
    > Option Explicit
    > Dim WithEvents p As CLAMXLib.ClamEn gine
    > Dim mresult As ClamResult
    >
    > Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult)
    > Set mresult = result
    > End Sub
    >
    >
    >
    > in c#
    >
    > CLAMXLib.ClamEn gine p;
    > ClamResult mResult;
    >
    > //now how will i catch events
    >
    >[/color]


    Comment

    • Stoitcho Goutsev \(100\) [C# MVP]

      #3
      Re: event handling

      Ankit,

      I'm not VB expert, but as far as I know if you declare a variable with
      *WithEvents* keyword you can handle the event using *Handles* in the event
      handler methods declaration.

      Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult) Handles
      p.ScanComplete
      ....


      Be careful though because the event handling happens in some early stage so
      the event may fire before you are prepared for that.


      --
      HTH
      Stoitcho Goutsev (100) [C# MVP][color=blue]
      > Set mresult = result
      > End Sub[/color]
      "Ankit Aneja" <efextra@newsgr oups.nospam> wrote in message
      news:eLp%239sKA GHA.3136@TK2MSF TNGP15.phx.gbl. ..[color=blue]
      >
      > i am using com dll in my project which fires up event
      >
      > code in vb is like this
      > Option Explicit
      > Dim WithEvents p As CLAMXLib.ClamEn gine
      > Dim mresult As ClamResult
      >
      > Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult)
      > Set mresult = result
      > End Sub
      >
      >
      >
      > in c#
      >
      > CLAMXLib.ClamEn gine p;
      > ClamResult mResult;
      >
      > //now how will i catch events
      >
      >[/color]


      Comment

      • Ankit Aneja

        #4
        Re: event handling

        i am doing all this thin in a class i am not understanding where i will
        write this
        p.OnScanComplet e += new OnScanCompleteE ventHandler(p_O nScanComplete);

        if i write p. inside any funtion it displays "OnScanComplete "
        outside any function it displays nothing
        "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
        message news:#XvsIQLAGH A.2132@TK2MSFTN GP14.phx.gbl...[color=blue]
        > Ankit,
        >
        > You do this:
        >
        > p.OnScanComplet e += new OnScanCompleteE ventHandler(p_O nScanComplete);
        >
        > This is a guess based on the event handler type of the event, as well[/color]
        as[color=blue]
        > your method, but it should give you the idea.
        >
        > Hope this helps.
        >
        >
        > --
        > - Nicholas Paldino [.NET/C# MVP]
        > - mvp@spam.guard. caspershouse.co m
        >
        > "Ankit Aneja" <efextra@newsgr oups.nospam> wrote in message
        > news:eLp%239sKA GHA.3136@TK2MSF TNGP15.phx.gbl. ..[color=green]
        > >
        > > i am using com dll in my project which fires up event
        > >
        > > code in vb is like this
        > > Option Explicit
        > > Dim WithEvents p As CLAMXLib.ClamEn gine
        > > Dim mresult As ClamResult
        > >
        > > Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult)
        > > Set mresult = result
        > > End Sub
        > >
        > >
        > >
        > > in c#
        > >
        > > CLAMXLib.ClamEn gine p;
        > > ClamResult mResult;
        > >
        > > //now how will i catch events
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Ankit Aneja

          #5
          Re: event handling

          code of class in which i have to catch up event
          public class clamresults
          {
          CLAMXLib.ClamEn gine p;
          ClamResult mResult;
          public clamresults()
          {
          //
          // TODO: Add constructor logic here
          //
          p=new ClamEngineClass ();
          p.Database.Path ="E:\\projec ts backup\\ankitcl am
          backup\\Clamtes t\\database\\";

          }
          public string loadDatabase(st ring command,string dirpath)
          {

          if(command=="SC AN")
          {
          mResult=scanfil e(dirpath);
          }
          else if(command=="RA WSCAN")
          {
          mResult=scanBuf fer(dirpath);
          }
          else if(command=="CO NTSCAN")
          {
          mResult=scandir (dirpath);
          }

          return mResult.Summary ;

          }
          public ClamResult scandir(string dirpath)
          {
          p.Settings.Scan Support=ClamSup port.Scan_Stand ard;
          mResult= p.ScanDirectory (dirpath,0,Clam BoolType.False ,ClamBoolType.T rue);
          return mResult;

          }
          public ClamResult scanfile(string dirpath)
          {
          p.Settings.Scan Support=ClamSup port.Scan_Stand ard;
          mResult=p.ScanF ile(dirpath,Cla mBoolType.True) ;
          return mResult;

          }
          public ClamResult scanBuffer(stri ng dirpath)
          {
          mResult=p.ScanB uffer(dirpath,C lamBoolType.Fal se);
          return mResult;
          }



          }

          now how and where i will catch up events which will be generated from com
          dll
          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
          message news:#XvsIQLAGH A.2132@TK2MSFTN GP14.phx.gbl...[color=blue]
          > Ankit,
          >
          > You do this:
          >
          > p.OnScanComplet e += new OnScanCompleteE ventHandler(p_O nScanComplete);
          >
          > This is a guess based on the event handler type of the event, as well[/color]
          as[color=blue]
          > your method, but it should give you the idea.
          >
          > Hope this helps.
          >
          >
          > --
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >
          > "Ankit Aneja" <efextra@newsgr oups.nospam> wrote in message
          > news:eLp%239sKA GHA.3136@TK2MSF TNGP15.phx.gbl. ..[color=green]
          > >
          > > i am using com dll in my project which fires up event
          > >
          > > code in vb is like this
          > > Option Explicit
          > > Dim WithEvents p As CLAMXLib.ClamEn gine
          > > Dim mresult As ClamResult
          > >
          > > Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult)
          > > Set mresult = result
          > > End Sub
          > >
          > >
          > >
          > > in c#
          > >
          > > CLAMXLib.ClamEn gine p;
          > > ClamResult mResult;
          > >
          > > //now how will i catch events
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Kevin Yu [MSFT]

            #6
            Re: event handling

            Hi Ankit,

            You can add it in the constructor after you create the p.

            public clamresults()
            {
            //
            // TODO: Add constructor logic here
            //
            p=new ClamEngineClass ();
            p.Database.Path ="E:\\projec ts backup\\ankitcl am
            backup\\Clamtes t\\database\\";
            p.OnScanComplet e += new OnScanCompleteE ventHandler(p_O nScanComplete);
            }

            Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult)
            Set mresult = result
            End Sub

            Kevin Yu
            =======
            "This posting is provided "AS IS" with no warranties, and confers no
            rights."

            Comment

            • Ankit Aneja

              #7
              Re: event handling

              Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult)
              Set mresult = result
              End Sub
              is this c# code

              "Kevin Yu [MSFT]" <v-kevy@online.mic rosoft.com> wrote in message
              news:qJTOnNtAGH A.3764@TK2MSFTN GXA02.phx.gbl.. .[color=blue]
              > Hi Ankit,
              >
              > You can add it in the constructor after you create the p.
              >
              > public clamresults()
              > {
              > //
              > // TODO: Add constructor logic here
              > //
              > p=new ClamEngineClass ();
              > p.Database.Path ="E:\\projec ts backup\\ankitcl am
              > backup\\Clamtes t\\database\\";
              > p.OnScanComplet e += new OnScanCompleteE ventHandler(p_O nScanComplete);
              > }
              >
              > Private Sub p_OnScanComplet e(ByVal result As CLAMXLib.IClamR esult)
              > Set mresult = result
              > End Sub
              >
              > Kevin Yu
              > =======
              > "This posting is provided "AS IS" with no warranties, and confers no
              > rights."
              >[/color]


              Comment

              • Kevin Yu [MSFT]

                #8
                Re: event handling

                Sorry, my mistake.

                private void p_OnScanComplet e(CLAMXLib.ICla mResult result)
                {
                Set mresult = result
                }

                Sometimes I just feel a little dizzy when changing between C# and VB.NET.
                :-)

                Kevin Yu
                =======
                "This posting is provided "AS IS" with no warranties, and confers no
                rights."

                Comment

                Working...