|
There is a tremendous amount out there. I really should have kept a list but here are two.
http://msdn.microsoft.com/msdnmag/issues/02/03/AOP/default.aspx
http://msdn.microsoft.com/msdnmag/issues/03/03/contextsinnet/
Robert
|
|
|
|
|
Interesting - since the public inception of .NET (and even for a while before that with some of my newer COM libraries) I've already been programming like most of what I read. I guess it just made sense too - to basically delegate responsibility to unknown objects at compile time and piece together those components at runtime. The application I architected for work works very much like that, although it could use a complete overhaul (the CEO gave me a couple weeks to design an app that has about 400,000 lines of actual code, is Internet-deployed, and now includes far too many "modules" to be deployed in such a way - plus it had to be easy enough for entry-level programmers / industrial engineers - who are now much better through lots of tutalige - to work on).
I've spent a lot of time in previous years studying COM (started about the time it evolved from OLE to COM) and especially all the interfaces that Office commonly implements. With a sprinkle of that with some of the stuff I developed since I originally architect the app (that is, I knew from the start this would come back to bite us so I kept track of everything I wanted to do in the first place but couldn't because we either didn't have time for a good design or didn't have the technical help from the rest of the code monkeys that was necessary). The Microsoft Patterns and Practices added a few more good ideas to the batch.
Thanks for the resources, though! At least I got a better grip on it and - strangly enough - realize that I've been doing it for a while so I don't feel like I'm missing the train!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Here's a MS WebTV piece detailing your original post.
http://www.microsoft.com/downloads/details.aspx?FamilyId=EF89345E-01A6-4AB1-8DDF-565286CC5DAC&displaylang=en
The presenter mentions that this is a more lightweight solution than using the MessageSink chain, implying that it could work the MessageSink chain.
In fact it can, using the ReturnValue property of MethodReturnMessageWrapper which can be assigned.
IMessage retMsg = nextSink.SyncProcessMessage(msg);
MethodReturnMessageWrapper mrm = new MethodReturnMessageWrapper((IMethodReturnMessage)retMsg);
Console.WriteLine("Here is the intercepted ReturnValue {0}", mrm.ReturnValue);
Robert Zurer
robert@zurer.com
Robert Zurer
robert@zurer.com
|
|
|
|
|
I need to get the following code working in C#:
char szText[255];
::SendMessage(hwndCurr, WM_GETTEXT, 255, (LPARAM)szText);
m_strPassword = szText;
And I've defined the SendMessage function
const int WM_GETTEXT = 0x000D;
[DllImport("user32.dll")]
static extern int SendMessage(IntPtr window, int message, int wparam, [Out]long lparam);
Does anybody know what I should do to make this work?
Andreas Philipson
|
|
|
|
|
Define it like so:
const int WM_GETTEXT = 0x000D;
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
static extern int SendMessage(IntPtr hWnd, int msg, int wParam, out char[] lParam); You can get the HWND from controls' Handle property (and remember that Form derives from Control , so it has a handle too). Notice that I also used the out keyword (not the OutAttribute , which you could still use). This is necessary to get this to work in .NET. Call it like so:
char[] text = new char[255];
SendMessage(myTextBox.Handle, WM_GETTEXT, 255, out text);
password = text; Now, if you're some cracker trying to get a password from another application, keep in mind that calls to WM_GETTEXT from another process for Edit controls (TextBox controls in .NET) with the ES_PASSWORD style set return an empty string (or NULL - I don't remember)...and get a life!
If you're not a cracker, ignore the above statement except the bit about password fields in other processes!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the help! I'll try it when I get home.
And regarding my use of this code - I'm trying to create a Password Manager which allows Drag&Drop to any edit control.
Andreas Philipson
|
|
|
|
|
After changing the solution to
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
static extern int SendMessage(IntPtr hWnd, int msg, int wParam, [Out]StringBuilder lParam);
It works perfectly! Thanks again!
Andreas Philipson
|
|
|
|
|
Thank you Heath Stewart:
I saw all of the source-code.But they are local-hooks
I really want to know journal-hooks .
thamk you.
sdfasd
|
|
|
|
|
I have a problem with axWebBrowser/Word, then opening a document in axWebBrowser.
I want to open the document without commandbars and ruler, but word get the settings from a template file (Normal.dot) witch has the settings from the last used word document stored.
I do not want to delete the users registry settings or template file might not be so popular, even if it's recreated the next time word ends.
Please, how can i by code (C#) turn the commandbars and rulers off in both office 2000 and XP.....
any help is appriciated: martin.jonsson@ifsab.se
Martin Jonsson
|
|
|
|
|
Both the WebBrowser control (and MSHTML that it hosts) and Word implement the IOleCommandTarget . This interface (or rather, its implementation) allows for command execution using simple strings (when used in automation) or command IDs. The WebBrowser control also has a custom set of command IDs, as well as MSHTML.
One of the standard command IDs, OLECMDID_HIDETOOLBARS , should be supported by Word. I'm not sure if IOleCommandTarget implementations MUST support the standards, but rest assured Office most likely does because the standard OLEDMCID enumerations were first defined by Office 95 (good indication that Office supports them still).
Now, because the WebBrowser control is an ActiveX container, getting its IOleCommandTarget interface (in .NET, querying for an interface is as simple as casting your object to said interface) and sending that command may just be enough. You'll either have to create an interop assumly with IOleCommandTarget and the various enumerations it uses, or create it yourself.
You can also send the command IDs (perhaps identified by their numbers, like OLECMDID_HIDETOOLBARS is defined as 24) through IWebBrowser2.ExecWB (IWebBrowser2 is the class interface for the WebBrowser control). I don't know if this will automatically be sent to the automation server (in this case, Word.Application) but - depending on how everything is sited - it's pretty likely and definitely worth a try. If not, you'll have to request the child object from the WebBrowser's site to get the Word doc in order to get the Word.Application, and cast to IOleCommandTarget to execute the command on it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi I am karthik, I need to create application, which creates thread dynamically and I need to pass unique Data/message to the thread (dynamically created thread).
How to pass Data/message from the application to the thread? It varies from thread to thread.
|
|
|
|
|
You cannot pass parematers to a method on a new thread. The method signature must be as follows:
void DoStuff(){
}
Instead of passing parameters use static variables. Note: Access to a static variable from multiple threads must be synchronized ..
|
|
|
|
|
A better way than using Thread as the above Anonymous person said, is to use worker threads in a thread pool, which can take a state object (which could be a single object, and array, collection, list, whatever). See ThreadPool.QueueUserWorkItem . There are many other useful methods that are helpful when synchronizing threads in the ThreadPool class you should check out. The ThreadPool , btw, is to make sure your application doesn't spawn threads uncontrollably. Many times, this is very important unless you're dealing with real-time apps (and most you write in your life won't be) otherwise you could monopolize the system's resources.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
I'm a beginner Windows programmer. I need to write a program that will copy files across networked servers, which may need to authenticate the user as he/she access the remote server. The user may type "\\remoteserver\d$\afile". If the user has accounts on both servers, it will just copy. If the currently logged in user does not have the same account on the remote server, the program is supposed to get the user id and password and pass it along to the remote server, just like the Windows Explorer.
I went round and round and trying with WNet APIs, System.Security.Permissions, System.Security.Principal. I did not get anywhere.
Any help will be greatly appreciated.
Thanks!!
|
|
|
|
|
Actually - in a domain setup - the user account doesn't exist on different computers (except, perhaps, different DCs that either cache or backup accounts). That's only a low-grade workgroup trick or for local users.
To accomplish what you want, you have to program the prompt yourself and deal with impersonation (which may cause problems on the local end if the impersonated user doesn't have access to the source resource). The fact is that .NET is a basic framework and doesn't include all functionality in Windows.
First, attempt a File.Copy . If you get an UnauthorizedAccessException , show a modal dialog to get the username and password (of course, mask the password using the TextBox.PasswordChar property). Then you're going to want to impersonate the requested user account. See the SDK documentation for WindowsIdentity.Impersonate for details and very good example source (P/Invoking native functions is required in .NET 1.x at least). Finally, perform the File.Copy again, and undo and close the impersonation handles (this is covered in the sample source I mentioned).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath, Thank you so much for your help. I will give it a try.
~Sherry
|
|
|
|
|
Im am trying to write an application that involves alot of TextBoxes that the user can input to. Is there a way to create an array of TextBoxes so I can just loop through them all?
Thanks
Matt
|
|
|
|
|
Yes. The easiest (if not the most type-safe) way is to create an ArrayList and Add(aTextBox) for each TextBox that is created.
Then when you need to loop over them you can do
foreach(object obj in myArrayOfTextBoxes)
{
TextBox tb = (TextBox)obj;
}
I'd recommend creating a type-safe collection to hold your text boxes in though.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
|
|
|
|
|
TextBox[] txt = new TextBox[10];
txt[0] = txtForm1;
txt[1] = txtForm2;
....
Sorry, no short way that I know of.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
Support Bone
|
|
|
|
|
TextBox[] txt = new TextBox[] {txtForm1, txtForm2};
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Let me start by saying I am very new to multithreading.
I have a web app where I want to execute two searches in parallel, when the both finish, move on and process the returned data. I did what I thought would accomplish this but my search times did not change. What am I missing?
Also, if it matters, both search functions are adding nodes to the same xml document in memory. Each function has duplicate checking before it enters the data. Could I be getting caught by resource locking to keep from really multithreading? thoughts?
Here is a piece of what I have so far. Thanks in advance.
<br />
Thread seaThread = new Thread(new ThreadStart(GetSeaAttachments)); <br />
Thread ilThread = new Thread(new ThreadStart(GetIlAttachements)); <br />
<br />
seaThread.Start(); <br />
ilThread.Start(); <br />
<br />
seaThread.Join();<br />
ilThread.Join();<br />
<br />
if (seaThread.IsAlive)<br />
{<br />
seaThread.Abort();<br />
}<br />
if (ilThread.IsAlive)<br />
{<br />
ilThread.Abort();<br />
}<br />
|
|
|
|
|
The reason you're not noticing any differences in time - and why you don't currently have to worry about resource locking - is in the following code you wrote:
seaThread.Join();
ilThread.Join(); The method Thread.Join blocks the current thread (your page's thread of execution) till the thread is done. So in your code, the page thread waits till the seaThread is finished, then executes the ilThread and waits till it finishes. This also means that your checks to see if the thread is still alive are pointless. The thread is alive until it either completes or is aborted. Since you're joining thread, the thread will be allowed to complete unless the thread itself (or another thread with a reference to said thread) aborts itself.
As far as resource locking is concerned, resources are synchronized unless otherwise stated. Some resources (like various collects and lists) have a SyncRoot (as it's commonly called), which returns a static object that's been initialized. With this, you can (and must in this case) perform locking yourself. In C#, you have the handy lock keyword. You don't have to use the SyncRoot for classes that have it, though - this is simply for disparate threads in different blocks of code (so you don't have to worry about passing your own object to synchronized against).
To use your own sync objects, one typically locks against typeof(MyType) for static methods and properties that need to be synchronized, and locks against this for instance methods and properties. See the lock keyword documentation for more information and examples.
So, to add resource locking to your XmlDocument (which doesn't have the SyncRoot property I was talking about), your threads need to lock against something (like either this , which refers to the page, or to the instance of your XmlDocument (make sure you've instantiated it first, though, since locking against null throws an exception). For example, lets say that both threads want to write something to the document. In either thread, do something like this:
XmlElement elem = this.myXmlDocument.CreateElement("exmaple");
lock(this.myXmlDocument)
{
this.myXmlDocument.DocumentRoot.ChildNodes.Add(elem);
} Notice how I created the element before locking? Knowing when to lock your resources is important. Locking them too early could result in O(n) execution times, instead of O(n/m) (where m is the number of threads) like you desire. And you typically don't need to worry about locking while reading a resource, unless you face a potential reader/writer problem. In that case, see the ReaderWriterLock in the System.Threading namespace.
Finally, to suggest a solution to your problem, see the documentation for the ThreadPool class. Besides the benefits gained from a thread pool (like you don't have too many threads spawning uncontrollably), you have many other gains from methods like ThreadPool.RegisterWaitForSingleObject , which lets you use a WaitHandle you want to create (such as an AutoResetEvent handle or a Mutex ) which gives you signaling (helpful when synchronizing threads) capabilities, plus it allows you to pass state information to the thread that will be spawned (where the Thread class forces you to use fields to store data, which isn't thread safe without going to a lot of work to synchronize).
Basically, you'd be wise to read the SDK documentation for the System.Threading namespace. It may be daunting at first, but - when yielded properly - can be very powerful.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for all the information But I am still a little confused. The seaThread.join line stops the current thread from processing till the seaThread finishes. That is what I want and since I have already started the ilThread, shouldn't it continue to run. the ilThread.join will hold the main thread in case it takes longer. I do want the main processing to stop till both threads finish.
I have looked into the threadpool a bit but find it just as confusing. I don't think my task really that complicated. How will thread pooling help me there?
For simplicity sake, I tried this with just a console program and it is working as I would expect. It is below.
<br />
using System;<br />
using System.Threading;<br />
<br />
namespace test_multithreading<br />
{<br />
class Class1<br />
{<br />
public static void PrintCurDateTime()<br />
{ <br />
Console.WriteLine( " Secondary Thread Started" );<br />
for (int i = 1; i <= 10; i++)<br />
{<br />
Console.WriteLine(" Second Thread working");<br />
Thread.Sleep(1985);<br />
}<br />
Console.WriteLine( " Second Thread time: " + DateTime.Now.ToLongTimeString() );<br />
Console.WriteLine( " Second Thread Finished" );<br />
} <br />
public static void PrintFutureDateTime()<br />
{ <br />
Console.WriteLine( " Third Thread Started" );<br />
for (int i = 1; i <= 100; i++)<br />
{<br />
Console.WriteLine(" Third Thread working");<br />
Thread.Sleep(93);<br />
}<br />
Console.WriteLine( " Third Thread time: " + DateTime.Now.ToLongTimeString() );<br />
Console.WriteLine( " Third Thread Finished" );<br />
} <br />
public static int Main(String[] args)<br />
{<br />
Console.WriteLine("Main Thread \n");<br />
<br />
try<br />
{<br />
Thread futThread = new Thread(new ThreadStart( PrintFutureDateTime ));<br />
futThread.Priority = ThreadPriority.Highest;<br />
futThread.Start();<br />
<br />
Thread secThread = new Thread(new ThreadStart( PrintCurDateTime ));<br />
secThread.Priority = ThreadPriority.Highest;<br />
secThread.Start();<br />
<br />
Console.WriteLine("Waiting for theads to join");<br />
secThread.Join();<br />
futThread.Join();<br />
Console.WriteLine("Joined");<br />
<br />
Console.WriteLine( "Main Thread time: " + DateTime.Now.ToLongTimeString() );<br />
<br />
}<br />
catch (Exception e) <br />
{<br />
Console.WriteLine( e.ToString());<br />
}<br />
return 0;<br />
} <br />
}<br />
}<br />
|
|
|
|
|
Hi,
I want to know how can I play audio files like mp3 files with basic functionality of play/pause/stop/forward/rewind.
Thanks.
Paul
|
|
|
|
|
You could try searching first. Use that little textbox torward the top of this page labeled "Search:", or click "Search Comments" to search this forum because that topic has been covered to death. There are plenty of examples on CodeProject, and many more if you google the 'net.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|