|
Could not get it to work.
Here's the problem: Class A implements the interface IClient that is on the server, everything's fine. When the method Foo of the class A is executed, the event is raised, passing some data class as a reference. Now, in order to subscribe to the event from the server, I need to do something like this:
Foo f = new Foo();
IClient icl = f as IClient();
and then:
icl.SomeEvent += new ... bla, bla...
but I DO NOT HAVE a reference to class A, method Foo, which is the whole point from the very beginning. Is there another way to subscribe to the event that is wrapped in the interface without having to know the class that's implementing it on the client side?
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
You can have a reference to Class A on the server side without knowing its type as long as it implements an interface the server knows about and the reference is passed as a reference to that interface type.
Let's look at a bit of code so that what I wrote above is more concrete.
In the server library, you have the IClient interface:
public interface IClient
{
event EventHandler ClientChanged;
}
Also, we have the Server class:
public class Server
{
public void Connect(IClient client)
{
client.ClientChanged += new EventHandler(HandleClientChangedEvent);
}
public void Disconnect(IClient client)
{
client.ClientChanged -= new EventHandler(HandleClientChangedEvent);
}
private void HandleClientChangedEvent(object sender, EventArgs e)
{
}
}
Now, the Server can attach and detach itself to the client's event without having to know its type. All it knows is that the client implements the IClient interface.
Make sense?
On the client side, we do have to know about the server, but the dependency is one-side, i.e. not circular, so we're ok:
public class SomeClient
{
public SomeClient(Server s)
{
s.Connect(this);
}
}
-- modified at 13:12 Saturday 26th November, 2005
|
|
|
|
|
Yes, you are right. It works. It was just not that obvious how to get the client throught the interface in order to subscribe to the event.
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
Seems the only reasonable way of playing a sounds - such as a .wav is to go back down to Win32?
Am I right or wrong.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Giles wrote: Seems the only reasonable way of playing a sounds - such as a .wav is to go back down to Win32?
System.Media[^]
|
|
|
|
|
I guessed there would be something like that. Problem is .NET 1.1.
I've currently got a third party lib, and it does not like 2.0, as its a wrapper for a C++ class, linked to the 7.1 C++ runtime.
Sorry, should have been more specific.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Giles wrote: I guessed there would be something like that. Problem is .NET 1.1.
I've currently got a third party lib, and it does not like 2.0, as its a wrapper for a C++ class, linked to the 7.1 C++ runtime.
Ah, well in that case, yeah, looks like platform invoke is the way to go. If you just need simple .wav playback, the sndPlaySound looks like it could do the job for you.
If you need some help in this area, let us know. I've had some experience wrapping the MIDI API, so I may be able to give you some pointers on wrapping the sndPlaySound function, or probably someone here at Code Project has already done it.
|
|
|
|
|
Leslie Sanford wrote: If you need some help in this area, let us know. I've had some experience wrapping the MIDI API, so I may be able to give you some pointers on wrapping the sndPlaySound function, or probably someone here at Code Project has already done it.
Thanks. I saw the artiles on CP. Seemed pretty straight formward, and I've used the MM library before from CPP.
Was just hoping there was a cleaner way. Nice to know the've fixed it of sorts for the future.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Is there any one that can point me in the right direction on how to create a generic printer driver, or is there a walktrough on who to create a printer driver.
I would like a generic printer driver that a can handle the flow of chars and do wath ever a mant with them.
|
|
|
|
|
Not in C# you don't.
For the time being you need to use very low level C++, using the Driver Development Kit or DDK.
There are some good articles on CP about an introduction the black art of driver development.
Saying that in future, becuase so many printer drivers are badly written in Windows Vista, MS is going to make all printer drivers user mode.
http://www.microsoft.com/whdc/devtools/ddk/default.mspx[^]
Saying that you could probably fudge it using a serial cable, or even a netowork based printer, but not by using USB port.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
is there a way i can move the mouse to position (x,y) when a function is called?
|
|
|
|
|
Use Cursor.Position from the Winforms namespace.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
I am having a lot of problems with source safe going very slow pulling files. I'm using NAnt to do a GET and build my application. The application consists of about 1000 files, and it takes nearly 10 minutes just to get the files to the server to build. Does anyone else experience this?
Also, how can I make it just pull the changed files? I have another project which contains about 5000 xml files and it takes over an hour to pull all of these, when only 30 have changed. There has to be a way to pull only these 30 in a matter of less than a minute.
Thanks!
Curtis
|
|
|
|
|
glocklt4 wrote: Does anyone else experience this?
Everyone. And that's why anyone with at least a mid-sized project or more than 3 or 5 person working on the same projects migrate to other VCS, like CVS, SVN, Perforce, Bitkeeper, etc.
I see dead pixels
Yes, even I am blogging now!
|
|
|
|
|
So there is now way to make it really only pull the lastest files?
GREAT!!
|
|
|
|
|
Hi there.
I am having a bit of a problem with Paint. I have a form and then when a user selects a certain choice from a menu the program puts several label controls with a text on the form. The program is also supposed to draw some lines when the same selection is made but it does not. This is what I did:
private void dowhatIwant(object sender, EventArgs e)
{
this.Paint += new PaintEventHandler(p2_Paint);
...
... //here is the code that puts the labels on the form
}
...
...
private void p2_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black,1);
Point p1 = new Point(88, 32);
Point p2 = new Point(299, 32);
g.DrawLine(p, p1, p2);
Point p3 = new Point(68, 106);
Point p4 = new Point(115, 106);
g.DrawLine(p, p3, p4);
...
...
}
I have several more lines I want to draw but only the first one shows? Can someone please show me the error of my ways?
Thank you,
FJ
|
|
|
|
|
|
Ok, I have a listview and a treeview. Gif's are being dragged from Listview and borught over to the treeview. I have managed to create a Ghost icon of the GIF when the user clicks on the picture, but the problem I have is that when drag starts, the ICON changes from the ghost icon to the default NO cursor. When it gets in the treeview, its the drag icon.
Can someone suggest as to where I may be going wrong. I can obviosuly post codes snippets, butI am not sure it will be of any help. Its something more basic as to the dragdrop effects that I am not setting.
I mean the drag drop works, the Ghost ICON, would be the icing on the cake.
Thanks for any input.
Sameer
|
|
|
|
|
Could it be because your ListView does not have the
AllowDrop<code> property set to true? In this case, Windows Forms would specify the NO_CURSOR because you can't drop there. <br />
<br />
"we must lose precision to make significant statements about complex systems."<br />
-deKorvin on uncertainty
|
|
|
|
|
I am having a problem with trying to get a series of wav files to play, I just want a simple button that when you press it, it will play a list of wav files, so far all that happen when I try and do this is it will play the last audio file stated in the code several times (the amount of other files I have tried to play.)
Any help that can be given will be much appreciated
Thank you
RoB
|
|
|
|
|
Since you didn't write a single line of code it's impossible to tell you what you did wrong.
Which environment are you using? .NET 1.1? 2.0?
What are you using to play your wave files? There's no built-in class to do this, so what are you doing?
Could it be that you're P/invoking sndPlaySound and specified the wrong flags?
mav
|
|
|
|
|
Thanks for your reply
I am using .net 1.1
The bits of code I have been using are shown below:-
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Runtime.InteropServices;
private string currentSoundFileName;
[DllImport("winmm.dll")] //load the sound libary
public static extern long PlaySound(String lpszName, long hModule, long dwFlags);
private Thread soundThread = null;
public void PlaySoundInThread(string wavefile)
{
currentSoundFileName = wavefile;
soundThread = new Thread(new ThreadStart(PlayASound));
soundThread.Start();
}
public void PlayASound()
{
if (currentSoundFileName.Length > 0)
{
PlaySound(Application.StartupPath + "\\" +currentSoundFileName, 0, 0);
}
currentSoundFileName = "";
soundThread.Abort();
}
Then I use the line below to play a wave file (i have stored the wav file in the debug directory)
PlaySoundInThread("1.wav");
This works with one wav file but when I have tried to play another wave file after this, I just replete the line of code with a different wav file entered, and that's where my problem is, it does not work.
Thanks
RoB
|
|
|
|
|
First, you've got the signature wrong. It's:
[DllImport("winmm.dll", SetLastError=true)]
static extern bool PlaySound(string pszSound, System.UIntPtr hmod, uint fdwSound);
your trying to pass two long 's (64-bit values!) in where the function is looking for two 32-bit numbers.
Second, you don't need to launch another thread to play the sound. Starting a thread is a VERY expensive process, taking forever and a day to start one. If you look at the docs for PlaySound on MSDN or PInvoke.net[^], you'll see that if you pass in the fdwSound parameter with the value 1, the function will start playing the sound asychronously, meaning it plays the sound without your code waiting for it to complete.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
GOT IT WORKING!
Thank you mav & dave.
the code i used is below:-
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices; // for PlaySound()
using Microsoft.Win32; // RegistryKey
namespace WindowsApplication2
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
[DllImport("winmm.dll", SetLastError=true)]
static extern bool PlaySound(string pszSound,
System.UIntPtr hmod, uint fdwSound);
[Flags]
public enum SoundFlags : int
{
SND_SYNC = 0x0000, // play synchronously (default)
SND_ASYNC = 0x0001, // play asynchronously
SND_NODEFAULT = 0x0002, // silence (!default) if sound not found
SND_MEMORY = 0x0004, // pszSound points to a memory file
SND_LOOP = 0x0008, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x0010, // don't stop any currently playing sound
SND_NOWAIT = 0x00002000, // don't wait if the driver is busy
SND_ALIAS = 0x00010000, // name is a registry alias
SND_ALIAS_ID = 0x00110000, // alias is a predefined id
SND_FILENAME = 0x00020000, // name is file name
SND_RESOURCE = 0x00040004 // name is resource name or atom
}
private System.Windows.Forms.Button button1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 56);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(176, 72);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public static void Play (string strFileName)
{
PlaySound (strFileName, UIntPtr.Zero, (uint)(SoundFlags.SND_FILENAME | SoundFlags.SND_SYNC));
}
private void button1_Click(object sender, System.EventArgs e)
{
string strFileName1 = "1.wav";
string strFileName2 = "2.wav";
Play(strFileName1);
Play(strFileName2);
}
}
}
|
|
|
|
|