event handling

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
S

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

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.
 
A

Ankit Aneja

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
 
A

Ankit Aneja

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
 
K

Kevin Yu [MSFT]

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."
 
A

Ankit Aneja

Private Sub p_OnScanComplete(ByVal result As CLAMXLib.IClamResult)
Set mresult = result
End Sub
is this c# code
 
K

Kevin Yu [MSFT]

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

Top