event handling

  • Thread starter Thread starter Ankit Aneja
  • Start date Start date
A

Ankit Aneja

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.ClamEngine
Dim mresult As ClamResult

Private Sub p_OnScanComplete(ByVal result As CLAMXLib.IClamResult)
Set mresult = result
End Sub



in c#

CLAMXLib.ClamEngine p;
ClamResult mResult;

//now how will i catch events
 
Ankit,

You do this:

p.OnScanComplete += new OnScanCompleteEventHandler(p_OnScanComplete);

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.
 
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_OnScanComplete(ByVal result As CLAMXLib.IClamResult) 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.
 
i am doing all this thin in a class i am not understanding where i will
write this
p.OnScanComplete += new OnScanCompleteEventHandler(p_OnScanComplete);

if i write p. inside any funtion it displays "OnScanComplete"
outside any function it displays nothing
Nicholas Paldino said:
Ankit,

You do this:

p.OnScanComplete += new OnScanCompleteEventHandler(p_OnScanComplete);

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]
- (e-mail address removed)

Ankit Aneja said:
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.ClamEngine
Dim mresult As ClamResult

Private Sub p_OnScanComplete(ByVal result As CLAMXLib.IClamResult)
Set mresult = result
End Sub



in c#

CLAMXLib.ClamEngine p;
ClamResult mResult;

//now how will i catch events
 
code of class in which i have to catch up event
public class clamresults
{
CLAMXLib.ClamEngine p;
ClamResult mResult;
public clamresults()
{
//
// TODO: Add constructor logic here
//
p=new ClamEngineClass();
p.Database.Path="E:\\projects backup\\ankitclam
backup\\Clamtest\\database\\";

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

if(command=="SCAN")
{
mResult=scanfile(dirpath);
}
else if(command=="RAWSCAN")
{
mResult=scanBuffer(dirpath);
}
else if(command=="CONTSCAN")
{
mResult=scandir(dirpath);
}

return mResult.Summary;

}
public ClamResult scandir(string dirpath)
{
p.Settings.ScanSupport=ClamSupport.Scan_Standard;
mResult= p.ScanDirectory(dirpath,0,ClamBoolType.False ,ClamBoolType.True);
return mResult;

}
public ClamResult scanfile(string dirpath)
{
p.Settings.ScanSupport=ClamSupport.Scan_Standard;
mResult=p.ScanFile(dirpath,ClamBoolType.True);
return mResult;

}
public ClamResult scanBuffer(string dirpath)
{
mResult=p.ScanBuffer(dirpath,ClamBoolType.False);
return mResult;
}



}

now how and where i will catch up events which will be generated from com
dll
Nicholas Paldino said:
Ankit,

You do this:

p.OnScanComplete += new OnScanCompleteEventHandler(p_OnScanComplete);

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]
- (e-mail address removed)

Ankit Aneja said:
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.ClamEngine
Dim mresult As ClamResult

Private Sub p_OnScanComplete(ByVal result As CLAMXLib.IClamResult)
Set mresult = result
End Sub



in c#

CLAMXLib.ClamEngine p;
ClamResult mResult;

//now how will i catch events
 
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:\\projects backup\\ankitclam
backup\\Clamtest\\database\\";
p.OnScanComplete += new OnScanCompleteEventHandler(p_OnScanComplete);
}

Private Sub p_OnScanComplete(ByVal result As CLAMXLib.IClamResult)
Set mresult = result
End Sub

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Private Sub p_OnScanComplete(ByVal result As CLAMXLib.IClamResult)
Set mresult = result
End Sub
is this c# code
 
Sorry, my mistake.

private void p_OnScanComplete(CLAMXLib.IClamResult 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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top