Subject: Implementing Callback Functions Via ConnectionPoin
Posted By: innkeeper Post Date: 9/11/2006 11:28:22 AM
I need to create a COM object and write some callback functions.. I can do it on VBScript but i need to do it in C#.

For example to do it on VBScript:

Set myVar = WScript.CreateObject("Company.Object", "Handle_");

After that I just need to write callback functions which have "Handle_" prefix. So how to this in C#?


Reply By: Ankur_Verma Reply Date: 9/11/2006 1:15:55 PM
A quick reply,

Is it a windowed control, that u could drop on a form?
If u can drop it on a form, you will get all the events
listed for the control and you can easily add a handler
for them.

Do write back if you r still stuck. Its solvable.

Regards
Ankur
Reply By: innkeeper Reply Date: 9/11/2006 1:31:53 PM
No, it's a console application. Let me say a little more about it. I have a SDK from some company which gives me some additional functions to operate with disks. In order to use it, i need to create a COM object. I have several samples writte in VBScript and JScript, and it also should work in C# but there is no any help about it. To create a COM object in C# i use the following code:
object myVar = Activator.CreateInstance(Type.GetTypeFromProgID("Company.Object"));

And it works. But now i also need to write some callback functions. I have a VBScript sample, where they create COM like that:
Set myVar = WScript.CreateObject("Company.Object", "Handle_");

So i just need to rewrite this line in C#, but i don't know how. It also written that i can implement callback functions via ConnectionPoint. Maybe i should create a COM object as always and the connect to it somehow?



Reply By: Ankur_Verma Reply Date: 9/14/2006 3:54:41 AM
Well in C# its a bit easier. Just do one of the following

1) If its a windowed control, i.e. if the control has a UI, add it to your tool
box and than drop it on your application windows. Its events will be listed in
the property window, you can add a handler to those events from there.

2) If it is a simple object with no UI, just add the control dll as a reference
to your project. In the class view of Solution exlorer expend the referered
control lib till you get the object you want to use. You will see that as
you click the object you wanna use, its methods and events will be listed
in a box just under solution explorer. With that information you
can add a handler to the events in the code something like this.

        void CallBackHandler()
        {
            MessageBox.Show("Called Back");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AnSimpCMLib.SimpOb ss = new AnSimpCMLib.SimpOb();
            ss.CallBzack += new AnSimpCMLib._ISimpObEvents_CallBzackEventHandler(this.CallBackHandler);
            ss.CallMe();
        }

Do write back.

Regards
Ankur

Go to topic 49727

Return to index page 175
Return to index page 174
Return to index page 173
Return to index page 172
Return to index page 171
Return to index page 170
Return to index page 169
Return to index page 168
Return to index page 167
Return to index page 166