Help - Search - Members - Calendar
Full Version: Skype4COM C# .NET Example - Full Project
Skype Community > English > Development, Betas and Skype Garage > Skype Public API
TheUberOverlord


NOTE: I am moving my web site, the old example is currently not available, but this is a newer example here:
http://forum.skype.com/index.php?showtopic=142821

I created this C# example so that people can learn a little better on how to process status messages for Skype4COMLib. Basically, it shows how to deal with ambiguous references and processes status messages for Attachment, Connection, Call, User, and Message status.

Additionally is has a Silent Mode button so you can enable silent mode as well. It has 2 links as well, the top one opens a browser window to the Skype.com site for additional Skype4COMLib examples, the Copyright link opens a browser window to my web site for addtional examples as well.

It also has the ability to start Skype if it is not running, as well as stop when a Skype user logs off or Skype is stopped. It uses Checkboxes for these 2 options. It was done In Microsoft Visual C# 2005 Express Edition which is free and can be found here:

http://msdn.microsoft.com/vstudio/express/visualcsharp/

The Entire C# project is contained here which contains all source and object:

http://testing.onlytherightanswers.com/Sky...y_ZOverLord.zip

It also is in the Skype4COM example pages under CS here as well:

https://developer.skype.com/Docs/Skype4COM/...ple?action=show

NOTE: You will need to have a copy of the latest Skype4COMLib installed on your system, which was not included in the Zip file can can be found here ("If you have Skype 3.0 for Windows on your system, it should be there already"):

https://developer.skype.com/Download

What can this do? ("From the comments in the source code"):

Example of Skype4COM status messages. Includes:
//
// Attachment Status
// Connection Status
// User Status
// Call Status
// Message Status
// Silent Mode
//
// As you can see the release version of this example program is very small, 24KB to be
// exact, not including the Interop and other .NET files. Checkbox settings are stored
// without the use of any registry data by using the .NET Application Settings User data.
//
// Any of the links listed here can be opened by simply holding down the CTRL key and
// clicking on the link.
//
// NOTE: This example program does NOT include the Skype4COMLib .dll. If you are using the
// Skype 3.0 for Windows release, the Skype4COMLib .dll should be already installed
// on your system. If needed you can download the latest Skype4COMLib .dll and
// then register it from here: https://developer.skype.com/Docs/Skype4COM
//
// Also includes CheckBoxes to stop at user logoff and Exit as well as Start Skype if needed.
// Added a Silent Mode Button as well. You can clear the text in the window at anytime by
// using the "Clear" button".
//
// Ways to use this Example program:
//
// 1. Start The Example program with Skype not running and the "Start Skype if not running"
// checkbox is checked. This will show you how this example program starts Skype and
// attaches to the Skype client. You can then change User status, make a test call to
// Echo123, send a chat message to Echo123 and see that the Example program is processing
// all the events as it should.
//
// 2. Stop this Example program while Skype is running. Start the Example program and do the
// same tests as above to see the events processed.
//
// 3. Uncheck the "Start Skype if not running" checkbox. Stop Skype. Stop this example
// program, then start this example program, and then start Skype. Do the same tests as
// above and see that the Example program is processing all the events as it should.
//
// 4. Leaving the "Start Skype if not running" checkbox unchecked. Start Skype then start
// this program, so you can see what happens when Skype is already running vs stopped
// as in the above example.
//
// 5. By checking the "Stop at Skype Logoff or Exit" you can test to see that this
// example program goes away when that checkbox is checked when the Skype User logs off
// or the Skype client is stopped. If you uncheck this checkbox, and the Skype user logs
// off or the Skype client is stopped you can see how this example program links back up
// to the Skype client when another logon is tried, or the Skype client is re-started.
//
// 6. By unchecking the "Stop at Skype Logoff or Exit" checkbox, you can see what status
// messages are sent when a Skype User logs off or exits Skype. You can also see how
// to re-attach when a Skype User logs back in, or the Skype client is restarted.
//
// 7. Additional logic could be added to this example program if needed to help you isolate
// and locate problems you may have in another program, and this can be done quickly.
//
// 8. By removing the authorization in the Skype client via Tools -> Options -> Privacy ->
// Manage other programs Access to Skype, you can use the same tests above to act as if
// it was a new installation in each case using different checkbox settings and even
// using the "Silent Mode" button as well.
//
// 9. The "Silent Mode" button can be used in four ways:
//
// a. If Skype is NOT running and the "Start Skype if not running" checkbox is checked
// and you click on the "Silent Mode" button. Skype will be started and as soon as
// this example program attaches to Skype. The Silent Mode request will be processed.
//
// b. If Skype is NOT running and the "Start Skype if not running" checkbox is NOT
// checked, the Silent Mode request will be queued until Skype is started and this
// example program attaches to Skype and then the Silent mode request will be
// processed.
//
// c. If Skype is running, and this example program is attached to Skype then the
// Silent mode request will be processed immediately.
//
// d. If Skype is running, but no Skype User is logged in, the Silent Mode request will
// be queued and processed as soon as this example program is attached to the Skype
// client ("Once a Skype User Logs On").
//
// This also shows how you can integrate a Skype interface into your application that
// can spawn Skype at some later time, not just at your application startup, but based on
// a button or link click. So as you can see, you can start Skype at anytime, not just
// at your application startup. If Skype was not running, and your application does other
// things that does not require the Skype interface, this can be useful to invoke Skype
// when needed, if it was not running already.
//
// NOTE: The Silent Mode request response does timeout, however it does complete. This
// causes a GUI hang at the moment, a bug report has been filed for this.
//
//10. Try all these above examples and any more you can think of using Auto-Logon and also
// without automatically logging in when Skype starts. You can see that this example
// program handles all these situations without throwing any exceptions ("minus the one
// listed above"). It is important to plan for all the possible situations that your
// application could encounter while interfacing to Skype and this example program is a
// way to show you how to deal with these situations gracefully. You can run this example
// program in debug if needed to see this.
//
// The intent of this example program was to show methods to handle all the initialization
// possibilities in a C# programming environment using Microsoft Visual C# 2005 Express
// Edition when interfacing to Skype4COMLib. Which is FREE and can be located at:
//
// http://msdn.microsoft.com/vstudio/express/visualcsharp/
//
// Documentation on Skype4COMLib can be found here:
//
// https://developer.skype.com/Docs/Skype4COM
//
// There are many other status messages and events that Skype4COMLib supports but most of
// the popular ones are used here as examples to get you started with learning how to
// interface to the Skype4COMLib using C# and at no cost by using the Microsoft Express
// Edition.
//
// Things can get a little tricky when using C# to interface to Skype4COMLib. This is because
// there are some ambiguous references for Attachment and Connection events. This means that
// in order to process these events you really need two attach statements, one for normal
// processing of the other events and one for the Skype class that handles Attachment and
// Connection events.
//
// Hopefully by looking at this code, and playing with it a bit, you can
// see why things are done here as they are, any questions just shout.
//
// ZOverLord AKA on Skype as TheUberOverLord


Any questions please shout.
tomaten
I search for a documentation of the "protocol" parameter in the Skype.Attach command. Default was 5, you use 7. Where are the difference?
TheUberOverlord
QUOTE(tomaten @ Thu Jan 4 2007, 01:47) [snapback]339287[/snapback]

I search for a documentation of the "protocol" parameter in the Skype.Attach command. Default was 5, you use 7. Where are the difference?


Yes, I am working on getting more info on "7" here is the "protocol" list of differences, 7 is not yet listed:

https://developer.skype.com/Docs/ApiDoc/Skype_protocol
TheUberOverlord
QUOTE(tomaten @ Thu Jan 4 2007, 01:47) [snapback]339287[/snapback]

I search for a documentation of the "protocol" parameter in the Skype.Attach command. Default was 5, you use 7. Where are the difference?


Protocol 7 was created to support "Call Transfer" according to the 3.0 API release notes, in the Protocol section:

https://developer.skype.com/Docs/DevNotes?a...-2006-11-08.pdf

API release notes can be found on this page:

https://developer.skype.com/Docs/DevNotes
BobS
I would like Skype to auto-answer with live video enabled. The configuration settings allow this nicely. However, I would like the the live video window to be visible. The user in this case is some one who can see and talk, but can NOT operater the computer in any manner. Essentially I would like Skype to be running on the computer, which is simply operating as a video phone that auto-answers. In looking at the Skype API for Windows and your very nice C# example using Skype4Com, I can not see a way to control the size and visisiblity of the live video window. Is there any way to control the size and position of the video window?
TheUberOverlord
QUOTE(BobS @ Tue Jan 9 2007, 14:10) [snapback]341844[/snapback]

I would like Skype to auto-answer with live video enabled. The configuration settings allow this nicely. However, I would like the the live video window to be visible. The user in this case is some one who can see and talk, but can NOT operater the computer in any manner. Essentially I would like Skype to be running on the computer, which is simply operating as a video phone that auto-answers. In looking at the Skype API for Windows and your very nice C# example using Skype4Com, I can not see a way to control the size and visisiblity of the live video window. Is there any way to control the size and position of the video window?


Would this be for accessability? there could be a few problems like.....how would the person hang up?

If you implemented something like a voice recognition interface, it could be doable. I have one example here:

http://testing.onlytherightanswers.com/mod...icle&sid=51
BobS
[indent]
QUOTE(TheUberOverlord @ Wed Jan 10 2007, 02:06) [snapback]341995[/snapback]

Would this be for accessability? there could be a few problems like.....how would the person hang up?

If you implemented something like a voice recognition interface, it could be doable. I have one example here:

http://testing.onlytherightanswers.com/mod...icle&sid=51

The user is atypical in that the user can not remember voice comands because of Alzhimers disease, although the user can still see and converse well. I tried your voice recognition sample and looked a the HTML to see the principles used. It all worked nicely for me.

I can not see any Skype api to activate and resize the Video in Window. I can see that the windows have unique Window's class names and that I should be able to find the region button to which the WM_LBUTTONDOWN message is posted when the user clicks on the button in the initial live video window. Therefore I should be able to programmatically "click" the button by posting a message to it. Similary I should be able to position and resize the Video in Window after it is created. The disadvantage of this approach is that when Skype changes the user interface buttons and windows, it will no longer work.

Am I missing something, or is this about the only way to activate and reposition the Video in Window?
TheUberOverlord
QUOTE(BobS @ Wed Jan 10 2007, 17:40) [snapback]342438[/snapback]

[indent]
The user is atypical in that the user can not remember voice comands because of Alzhimers disease, although the user can still see and converse well. I tried your voice recognition sample and looked a the HTML to see the principles used. It all worked nicely for me.

I can not see any Skype api to activate and resize the Video in Window. I can see that the windows have unique Window's class names and that I should be able to find the region button to which the WM_LBUTTONDOWN message is posted when the user clicks on the button in the initial live video window. Therefore I should be able to programmatically "click" the button by posting a message to it. Similary I should be able to position and resize the Video in Window after it is created. The disadvantage of this approach is that when Skype changes the user interface buttons and windows, it will no longer work.

Am I missing something, or is this about the only way to activate and reposition the Video in Window?


You got it, basically you would need to do as you are saying, currently there is no other method via the API interfaces to do so.
merton_a
QUOTE(TheUberOverlord @ Sat Dec 30 2006, 08:47) [snapback]337407[/snapback]


I created this C# example so that people can learn a little better on how to process status messages for Skype4COMLib. Basically, it shows how to deal with ambiguous references and processes status messages for Attachment, Connection, Call, User, and Message status.

...

Any questions please shout.


I have already used your example to simplify my code a lot - thanks!

I have a question about the ambiguous reference thing:

I had built my code using only a single Skype object, so I edited your (very excellent!) example as follows:

Keep only one Skype object:

public Skype skype = new Skype();

Set up the event handlers as follows (the type conversion gets around the ambiguous reference messages):

((_ISkypeEvents_Event)skype).AttachmentStatus += OurAttachmentStatus;
((_ISkypeEvents_Event)skype).ConnectionStatus += OurConnectionStatus;

Remove the cSkype.Attach() call; and change all references to cSkype (The SkypeClass object) to refer to the skype object instead.

When I run both your version and my version simultaneously, I see only minor differences in the message stream, which may be down to the speed of the machine (Core 2 Duo running Vista) and/or the order in which the two apps link to Skype. For example, with both running and Skype stopped, when I start Skype my version sees an extra cusOffline message prior to the cusOnline arriving (I can provide screenshots if necessary)

Is this a valid implementation?

Also (generic C# question, maybe?), how come the ambiguous references are necessary? Why do they exist in the first place?
TheUberOverlord
QUOTE(merton_a @ Sat Mar 10 2007, 19:25) [snapback]370559[/snapback]

I have already used your example to simplify my code a lot - thanks!

I have a question about the ambiguous reference thing:

I had built my code using only a single Skype object, so I edited your (very excellent!) example as follows:

Keep only one Skype object:

public Skype skype = new Skype();

Set up the event handlers as follows (the type conversion gets around the ambiguous reference messages):

((_ISkypeEvents_Event)skype).AttachmentStatus += OurAttachmentStatus;
((_ISkypeEvents_Event)skype).ConnectionStatus += OurConnectionStatus;

Remove the cSkype.Attach() call; and change all references to cSkype (The SkypeClass object) to refer to the skype object instead.

When I run both your version and my version simultaneously, I see only minor differences in the message stream, which may be down to the speed of the machine (Core 2 Duo running Vista) and/or the order in which the two apps link to Skype. For example, with both running and Skype stopped, when I start Skype my version sees an extra cusOffline message prior to the cusOnline arriving (I can provide screenshots if necessary)

Is this a valid implementation?

Also (generic C# question, maybe?), how come the ambiguous references are necessary? Why do they exist in the first place?


Not sure there is really a right or wrong implementation, but the method that I used allowed you to limit event firing to only attachment and connection events, until the attach success was received for the "cSkype" attach request. Only then would any other events fire after the attach to "skype" was completed.

So for example, it would be impossible to receive a "Call" status event, using my method, until the original attach request was completed for the "cSkype" attach because that event interface would not have been created yet for the events under "skype".

Also, try using your modifications to the example program where:

1. Skype is not runnng yet, and is launched by the example program, with no auto-logon, creating a delay for the attachment.

2. The example program does not stop when a user logs out and some time goes by before another logon is attempted.

3. The Example program does not go away and the Skype client is stopped and started and logged on again, with some delay before logon.

4. Delete the approval in the Skype Client for the Example program, and delay answering the approval to allow the program to connect. Of course this would only happen once, if the person approves it for the future, but it could time out, not just the first time, but each time there is a delay, if the person decided to approve the program each time it runs, and waits too long when they do so.

Again, not sure that using a single attach is a bad idea, just can see how timeouts could happen with the attach requests and/or GUI hangs can take place waiting for an attach response. But it seemed the easiest method to cover all the bases in a generic kind of way.

As for "how come the ambiguous references are necessary?" I will ask Andres that question as well.

Curious to see what your results are of the above tests with your mods to the example program.
merton_a
QUOTE(TheUberOverlord @ Sun Mar 11 2007, 05:12) [snapback]370591[/snapback]

So for example, it would be impossible to receive a "Call" status event, using my method, until the original attach request was completed for the "cSkype" attach because that event interface would not have been created yet for the events under "skype".


I hadn't thought about the order in which events arrive being dependent on the attach, but you're right. So far, with all of the tests you suggested, the only difference between "yours" and "mine" (for want of better terminology!) is that whenever a user logs on, mine gets

apiAttachAvailable
conOnline
cusOnline
apiAttachSuccess

while yours gets the last two events in the other order, which does make more sense, I agree!

QUOTE
Also, try using your modifications to the example program where:

4. Delete the approval in the Skype Client for the Example program, and delay answering the approval to allow the program to connect.


How long is the timeout? I thought around 30 seconds by default?

I've waited for 1 minute +, and had no problems... I'm impatient, though... smile.png

QUOTE
Again, not sure that using a single attach is a bad idea, just can see how timeouts could happen with the attach requests and/or GUI hangs can take place waiting for an attach response. But it seemed the easiest method to cover all the bases in a generic kind of way.


I'm going to have to think about the message order - I don't suppose that just delaying the hooking of the non-Attach/non-Connection message handlers until the Attach & connection have succeeded would work, would it? Probably easier to use the second object, anyway...

QUOTE
As for "how come the ambiguous references are necessary?" I will ask Andres that question as well.


I guess it'd be a big change to make now, to remove them - might break too many apps.

I think that the order of messages that I see could be considered a semi-bug - if you're not attached, you shouldn't have access to anything. Could be considered a security breach, albeit a minor one smile.png

I have to admit as well - I think that some more details of the semantics behind the objects, events, etc in the API would be useful - for example, it appears that the Attachment status relates to the connection between my app and the Skype Client/API, while the Connection status relates to the connection between the Skype Client, and the Skype servers. Is this correct?

Sorry for the essay...
TheUberOverlord
QUOTE(merton_a @ Sun Mar 11 2007, 00:07) [snapback]370595[/snapback]

I hadn't thought about the order in which events arrive being dependent on the attach, but you're right. So far, with all of the tests you suggested, the only difference between "yours" and "mine" (for want of better terminology!) is that whenever a user logs on, mine gets

apiAttachAvailable
conOnline
cusOnline
apiAttachSuccess

while yours gets the last two events in the other order, which does make more sense, I agree!
How long is the timeout? I thought around 30 seconds by default?

I've waited for 1 minute +, and had no problems... I'm impatient, though... smile.png
I'm going to have to think about the message order - I don't suppose that just delaying the hooking of the non-Attach/non-Connection message handlers until the Attach & connection have succeeded would work, would it? Probably easier to use the second object, anyway...
I guess it'd be a big change to make now, to remove them - might break too many apps.

I think that the order of messages that I see could be considered a semi-bug - if you're not attached, you shouldn't have access to anything. Could be considered a security breach, albeit a minor one smile.png

I have to admit as well - I think that some more details of the semantics behind the objects, events, etc in the API would be useful - for example, it appears that the Attachment status relates to the connection between my app and the Skype Client/API, while the Connection status relates to the connection between the Skype Client, and the Skype servers. Is this correct?

Sorry for the essay...


Yes, as I said there really is no right/wrong way when comparing a single attach vs using my method, other than being able to limit event firing, maybe do some building of tables or lists prior to having events fire, once you know you are attached, before you start processing other events, and yes the connection status is client to server.
mr_anderson
QUOTE(BobS @ Wed Jan 10 2007, 23:40) [snapback]342438[/snapback]

[indent]
The user is atypical in that the user can not remember voice comands because of Alzhimers disease, although the user can still see and converse well. I tried your voice recognition sample and looked a the HTML to see the principles used. It all worked nicely for me.

I can not see any Skype api to activate and resize the Video in Window. I can see that the windows have unique Window's class names and that I should be able to find the region button to which the WM_LBUTTONDOWN message is posted when the user clicks on the button in the initial live video window. Therefore I should be able to programmatically "click" the button by posting a message to it. Similary I should be able to position and resize the Video in Window after it is created. The disadvantage of this approach is that when Skype changes the user interface buttons and windows, it will no longer work.

Am I missing something, or is this about the only way to activate and reposition the Video in Window?


Hi guys, I am developing a Skype-based application for disabled people (similar to yours, Bob) and I have the problem of setting the position and the dimention of the skype video window. I understood that (as you said) there are non methods given by the API, so I think we should use Windows methods, am I right? If yes, can anybody explain me how to manage the video Window? I am using C#.
Thanks
mr_anderson
tibord
HI All

I can't access the site http://testing.onlytherightanswers.com where the sample is located... the site does not work any more. can someone tell me where else i can download it.

thanks much
TheUberOverlord
I created a much better example:

http://forum.skype.com/index.php?showtopic=142821

I am moving this web site to another host, so it is down at the moment. I will update this old example as well soon.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.