I have been trying to write the clipboard content to an external windows application (currently running process) from a C#(WPF) application using SendMessage API and WM_PASTE. Can't get it work. Here is the sample code
publicconstint WM_PASTE = 0x0302;
publicstaticexternInt32 FindWindow(String lpClassName,String lpWindowName);
publicstaticexternint SendMessage(int hWnd, int msg, int wParam, IntPtr lParam);
privatevoid btn_Click(object sender, System.EventArgs e)
hwnd = FindWindow(null, "Untitled - Notepad");
if (hwnd != 0)
Clipboard.SetText("sample text from clipboard");
hwnd = FindWindow(null, "Untitled - Notepad");
SendMessage(hwnd, WM_PASTE, 0, IntPtr.Zero);
I'm a student and I'm doing my thesis. I'm using ACOS3 1.07.18, according to it's manual book, the 18 is mean that the card can contain 24KB of data. I want to ask you how to use all of that 24KB?
I have formatted it, first I'm trying to format it using 94 files, but I got a problem in record number 31 (record number starts from 0), the card return code that the address could not be found. I read the manual once more, I found that in the personalizetion stage I only can make 31 files.
I formatted the card using 31 files (record number 0 - 30) with 254 Bytes record length in each. That's mean I only can use 31 x 254 Bytes = 7.874 Bytes.
Please help me what should I do to use that 24 KB?
OK, I'm sorry for that mistake and thanks to OriginalGriff for replying my post. I mean, my programming language is C#, and I have to write some data to the smart card. But I have a problem with the smart card as I wrote before. I hope someone who have ever used a smart card could help me.
You can't rely on the Garbage Collector to play along like that - it could decide to collect those delegates at any point in time since they were not referred to anymore, possibly infinitely long into the future.
Window1 should unsubscribe before closing (in the OnClosing event, for example?)
Ooh so it's out of your control, well that changes matters..
I don't see any solutions then, except a couple of really really dirty things.
You can, with reflection, extract the Target Object from a delegate object. You can then check whether it is a Window1 and whether it has closed yet.
You could also try to subscribe to the OnClosing of Window1 (through that Target Object) and when it's triggered delete all delegates which have Window1 as Target Object.
Before I waste time going down this road, is that going to solve the original issue (of Window1 closing and still having a listener)? It would seem that wrapping a delegate in a WeakReference should theoretically have the same effect, no?
I'm not really liking WeakEventManager to be honest with you. Seems like everybody has to implement the IWeakEventListener interface.
I'm just really curious why my previous idea didn't work... of storing the WeakReferences myself???
I'm not sure to be honest whether it will solve your problem. Every weak reference solution seems to have pros and cons. The event model employed by .NET is flawed in this regard and relies on consumers unsubscribing correctly.
Another option maybe to forget about events in the normal way and go back to generating old fashioned windows messages or something similar so interested parties can override WndProc and catch the event there - no direct subscription... Maybe not practical or possible in your situation, certainly not as elegant as events, but worth a thought?
For an item of hardware I have written a Shared library to make it easy to use the API for this hardware. The library sets up data structures and handles, buffers etc for simple program use.
For example to arrange data to be transmitted I call routings like:-
UINT16 TransmitData( UINT unit, UINT addr, TXBUFFER * tx_buffer );
However in VS2008 I used C++ in a MFC dialog application, which all worked well.
Having moved to VS2010, I now see that the intellisence does not work with this product.
So my thoughts were to use C# for the Windows forms and link in the Shared Library.
I have built the Shared Library in VS2010 so I need to understand how to access these function in a C# program. Is this using ‘Wrappers’ and how does the libraries API001.LIB and API001.h files link in?
For a C++ MFC program I included the headers and LIB files with the PATH set up for the DLL’s.
You can create a C++/CLI class library and include the .lib and .h there. Then create a managed class in C++ that wraps the functions. Finally, make a reference from the C# application to the C++/CLI project.
I always thought IDictionary checks key when adding elements by calling GetHashCode overrides - but I did a simple experiment, seems like it only call Equals (i.e. Even if two instances with same hash code added to a Hashtable or Dictionary, it won't blow up so long "Equals" return false)
I digged around MSDN[^] and found that "Override the Equals method whenever you implement the equality operator (==), and make them do the same thing. This allows infrastructure code such as Hashtable and ArrayList, which use the Equals method, to behave the same way as user code written using the equality operator."
So this confirms Hashtable or Dictionary uses only "Equals", not "GetHashCode" --- then what's "GetHashCode" for? Doesn't seems like "Hashtable" or "Dictionary<k,v>" are using it at all..?!?
The hashcode is only used balance the hash table.
What doesn't work is if A.GetHashCode() != B.GetHashCode() but A.Equals(B). That is, it may work accidentally but all bets are off.
That means that GetHashCode could return 0 and everything will still work. Performance will suffer though.