|
I have a solution that is not particularly elegant but I use it in a speech recognition application I am writing.
My scenario is that I have a keyhook class that listens for a button being pressed.
In the KeyHook class I declare the following at the top of the class.
private static TestApp.MainForm m_InstanceRef = null;
public static TestApp.MainForm InstanceRef
{
get
{
return m_InstanceRef;
}
set
{
m_InstanceRef = value;
}
} Within the main form I call the KeyHook class using the following syntax:
KeyHook.InstanceRef = this;
KeyHook.Listen();
Within the KeyHook class I then run a method when the key that I want is pressed, called EnableCheck(), in the main form thus:
InstanceRef.EnableCheck();
Like you I am a learner with C#, and hopefully will always be one, and feel a more elegant solution would be to throw an event that could be picked up by the main form.
This way of doing things breaks the rules of OOP but it works.
Regards
Guy
You always pass failure on the way to success.
|
|
|
|
|
Hi,
is it possible that I can use the Excel Chart Object from Office 2002
in my C# application as embedded or so but not as excel application only Chart object from it.
thx in advance
|
|
|
|
|
It should be. Google might help out.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
Hi
I've got a problem with some security-settings while remoting with TcpChannels.
I've got a server and client. When the connection is estabilished and the client tries to run a method that is going to the server, the client throws the following exception:
************** Exception Text **************
System.Security.Authentication.AuthenticationException: A remote side security requirement was not fulfilled during authentication. Try increasing the ProtectionLevel and/or ImpersonationLevel. ---> System.ComponentModel.Win32Exception: The network logon failed
--- End of inner exception stack trace ---
Server stack trace:
at System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential credential, String targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.CreateAuthenticatedStream(Stream netStream, String machinePortAndSid)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.CreateSocketHandler(Socket socket, SocketCache socketCache, String machinePortAndSid)
at System.Runtime.Remoting.Channels.SocketCache.CreateSocketHandler(Socket socket, String machineAndPort)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Interface.IServer.test(String msg, IClient cO)
at Client.Form1.btnSend_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.832 (QFE.050727-8300)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Client
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/Administrator/Desktop/Neuer%20Ordner/Client.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.832 (QFE.050727-8300)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.832 (QFE.050727-8300)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.832 (QFE.050727-8300)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.832 (QFE.050727-8300)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
Interface
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/Administrator/Desktop/Neuer%20Ordner/Interface.DLL
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.832 (QFE.050727-8300)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.832 (QFE.050727-8300)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
I created the following solution, that will be the network-engine for some projects (yes, there is a socket-connection too in that solution):
http://www.krifi-ware.de/ngame/networkengine.zip
There error only occurs, when the client is on a different machine than the server.
When server and client are running on the same machine, the error only occurs, when you are using an external IP (at my machine the Local-LAN IP and localhost (127.0.0.1) are working and the hamachi-IP (a VPN) is like the client is on an external machine).
|
|
|
|
|
Difference between two dates .(MM/DD/YY)
One date is given through Textbox are in the same format as System date.
Other is just system date .
I want to get date,month,year differences
|
|
|
|
|
The right way to do this is by converting to two DateTime objects, then apply
whatever it is you need, e.g. subtract to get a TimeSpan.
You should not operate on date strings yourself, use TryParse() instead.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
What Luc said, plus:
Don't use TextBoxes for dates, use a DateTimePicker.
Use ISO 8601-compliant formats -- YYYY-MM-DD.
|
|
|
|
|
I'm trying to BitBlt a portion of an image to another but all I get is the background color of the source bmp! Any ideas?
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
The code that you have written is incorrect.
If you show the code, you may have a chance of getting a more specific analysis.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I have had this happen to me when I use the WinAPI BitBlt method. What I had to do is make a call to CreateCompatibleDC[^], then copy the bitmap to that DC, and finally use BitBlt from the resulting DC. Without seeing any of your code, I have NO idea if this will help, but my guess is that it might.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hello,
anyone knows if there is a configuration framework available which provides saving of configuration and edit the configuration in an graphical editor..
Best regards
Hansjörg
|
|
|
|
|
|
Hello,
I search some configuration framework with which I can make application configuration. Edit inside the application, load and save a new configuration. The property grid is for sure usefull to make such a framework, but it is only a part of it...
Til now I have found NINI which looks good. But it provides only to part of saving and loading...I search also the part of the graphical representation of the configuration data.
Best regards
Hansjörg
|
|
|
|
|
How do I go about getting 24bit audio to play using directSound? 8 and 16 bit audio plays fine, but when ever I go to play 24 bit audio, my program throws an 'Value does not fall within the expected range.' exception on:
sound = new SecondaryBuffer(dataGridResults.CurrentRow.Cells[3].Value.ToString(), d, dSound);
The creation and initialization:
private Device dSound;<br />
private SecondaryBuffer sound;<br />
private BufferDescription d = new BufferDescription();<br />
<br />
dSound = new Device();<br />
dSound.SetCooperativeLevel(this, CooperativeLevel.Priority);<br />
d.LocateInHardware = true;<br />
<br />
d.ControlPan = true;<br />
d.ControlVolume = true;<br />
d.ControlFrequency = true;<br />
d.ControlEffects = true;<br />
d.GlobalFocus = true;<br />
How do I fix this?
|
|
|
|
|
Is the file a Wav or an MP3?
|
|
|
|
|
The file is a wav recorded at 44100.
|
|
|
|
|
I remember reading something about this a loooooooong time ago, but I can't remember what and I can't for the life of me remember where. Bear with me while I try and see if I can dig it up.
One other question, does the DirectX sample application (included with the DX SDK) do the same thing when you try and play the file?
|
|
|
|
|
Thanks for any help you can give.
I tried the file in several of the sample applications, and they all give 'File to large. You should stream large files'. However, I get this message even with files that play correctly in my app.
|
|
|
|
|
I'm running into exactly the same problem here and I haven't worked it out yet.
Did you get anywhere with this?
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I created a brand new project and open clissview diagram window. Then i added 2 class Person and Employee i want to add the inhertiance line to show the relationship but visual studio doesn't let me to drag and drop the inhertance symbol from the toolbox window.
I know If i create these two classes then i will automatically but i want to create class diagram first then actually creating classes.
Any help thanks
|
|
|
|
|
Don't drag and drop it, just click the inheritance tool and your cursor will now change on the designer. You then click on the child class and you will see a line start to draw. You finally click on your base class and the inheritance has thus been completed.
Hope that helped.
Also, quick question. Shouldn't the employee just be an enum of PersonType?
|
|
|
|
|
|
Hello,
I'm trying to eliminate a huge switch() block in my code by the use of Reflection. I added a dictionary to the class, and then tried populating it in a static constructor. The goal is that later I'll simply get delegates from this dictionary and use DynamicInvoke on them, which would replace the switch.
An example of what I'm trying to do:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ClassA a = new ClassA();
}
}
class ClassA
{
static ClassA()
{
foreach (MethodInfo mi in typeof(ClassA).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic))
if (mi.ReturnType == typeof(UInt16))
{
ParameterInfo[] pis = mi.GetParameters();
if ((pis[0].ParameterType == typeof(String).MakeArrayType()) &&
(pis[1].ParameterType == typeof(Byte).MakeArrayType()) &&
(pis[2].ParameterType == typeof(Byte).MakeArrayType().MakeByRefType()) &&
(pis[2].IsOut))
{
CallbackMethods.Add(mi.Name, Delegate.CreateDelegate(typeof(CallbackMethodDelegate), mi));
}
}
}
private static Dictionary<string, delegate=""> CallbackMethods = new Dictionary<string, delegate="">();
private delegate UInt16 CallbackMethodDelegate(String[] header, Byte[] mgedDataIn, out Byte[] mgedDataOut);
private UInt16 Method1(String[] header, Byte[] mgedDataIn, out Byte[] mgedDataOut)
{
mgedDataOut = null;
return (UInt16)0;
}
}
}</string,></string,>
Executing this code gives me a TypeInitializationException when running the Delegate.CreateDelegate() method.
This is undoubtedly linked to the fact that I want to invoke instance methods, while the delegates are being created in a static constructor. In fact, if I copy and paste the code of my static constructor into an instance constructor, make the dictionary an instance variable, and call a different overload of CreateDelegate (the one that receives firstArgument, since I now have this ) it works.
So my question would be: is there a way to create these delegates in the static constructor, and then later when calling DynamicInvoke on them, bind them to the correct instance of the class?
Thanks in advance for any suggestions you can offer.
Leonardo Pelisoli
|
|
|
|
|
Instead of making a dictionary of method name to a delegate, why not make it a dictionary from name to method info? Then, just call the method later using reflection by calling MethodInfo.Invoke().
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Skippums,
Thanks for your suggestion. I've indeed done as you said one time before, and it works. However, as far as I understand it, reflection done in this fashion is very slow when compared to a normal method call.
In this part of the application, I can't really afford the performance loss. That leaves me with delegates as my only choice since they are, as I understand it, much faster than reflection.
Leonardo Pelisoli
|
|
|
|
|