|
There is an article on MSDN written by Eric Gunnerson where he develops a plug-in system; his is more advanced but you can see how he does it.
HTH,
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Thanx will have a look
UPDATE: Had a quick look (still greek ) and will read some more. All my "plugin" does (well will do) is hook onto one object( Connection Class) and responds to events. He talks about going the interface way (I only need to call a single known method) , but he then opts for the delegate way. I presume the interface way is the one I should follow, but how???
|
|
|
|
|
I use interfaces in my article "Using reflection to extend .NET programs", which should give you an idea how you could alter Eric's code to use interfaces.
HTH,
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Thx
READ MSDN
|
|
|
|
|
Hi JTJ
Shot JTJ. It IS exactly what I meant "an easy way". The other article just confused me, but could prove helpful at a later stage. Just one more question. If I have an method e.g. Init(object sender) specified in the interface, does "sender" get passed by value or by reference? Or should I maybe define it as e.g. Init(ref object sender)?
OK, I lied just one more now. If I register eventlisteners on "sender" , do I need to deregister them when I "unload" the assembly or will they get "destroyed" automatically? And how does the "assembly" get disposed of? When the interface goes out of scope?
Thanx again
READ MSDN
|
|
|
|
|
leppie wrote:
If I have an method e.g. Init(object sender) specified in the interface, does "sender" get passed by value or by reference?
In this particular case, it will be passed by reference.
Everything is always passed by reference unless the type inherits from ValueType somewhere in the hierarchy. As a general rule if its a class it will be passed by reference; if it is a struct or a intrisnic type (int, float, bool) it will be passed by value. Though string is an intrisnic type it violates this rule by being a class; so it is passed by reference and not by value.
leppie wrote:
Or should I maybe define it as e.g. Init(ref object sender)?
Doing this means that you can change the value that the variable references; so that it is referencing something different. Generally you would want to leave the original variable referencing the same thing.
leppie wrote:
do I need to deregister them when I "unload" the assembly or will they get "destroyed" automatically?
I would unregister them just to be safe When dealing with finalizers you have no idea in what order or when things will happen. Unregistering them yourself would guarantee that it gets done.
leppie wrote:
And how does the "assembly" get disposed of? When the interface goes out of scope?
This is where Eric's article is superior to mine, and why I referred you to his instead of mine in the first place
Once an assembly is loaded into an AppDomain with the Assembly.Load* methods it stays there until the AppDomain is unloaded. The problem is that in my article all assemblies are loaded into the default AppDomain created when you execute a .NET program. So the only way to unload the assembly is to quit the program.
HTH,
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Many thanx again James, perhaps you should change HTH to TWH (this will help)
READ MSDN
|
|
|
|
|
Hi , the addy you gave points to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp04182002.asp
I found this one (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp05162002.asp) that seems to be more of an explanation of App Domains.
It seems this is the continuation of the 1st URL
READ MSDN
|
|
|
|
|
Makes sense, IIRC the article I gave you was written in April; and it is a monthly column.
Thanks for the other link; I'll add it to my bookmarks
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Unfortunately the code sample you can download is terribly incomplete (UPDATE: my bad, lack of sleep ), but I managed to move some of the "loader" bits to my code
Problem I have now is that my Connection object need to inherit from MarshalByRef so it can be accessed across domain boundries or from what I can see it needs to be Serializable (MarshalByVal ??). Unfortunately the latter is not an option (unless I rewrite the library I'm using ).
Is there any other ways to reference an "immutable" (iow I cant/wont change) object?
Thanx
READ MSDN
|
|
|
|
|
OK I was just about to give up, when I made a breakthru )
Plugin loads now in a new AppDomain, but I get a problem about "Serialization will not deserialize delegates to non-public methods."
All I know, this prevents my events from calling private methods. And changing them to public just prevents the Exception from being thrown.
Any suggestions?
I see this as well:
'Plugin': Loaded 'c:\documents and settings\lep\local settings\application data\assembly\dl\1231bdf657cfa4b58247156af46a487b\0c35d18d\008c64c0_2524c201\sampleinterface.dll', Symbols loaded.
Thats OK, assembly loaded in Plugin domain. BUT (big one )
I get this too:
'IrcBotUI.exe': Loaded 'c:\develop\ircbotui\bin\debug\sampleinterface.dll', Symbols loaded.
This is my main program domain. Should this happens as well? Is it because the "plugin" inherites from MarshalByRefObject?
TGIF
|
|
|
|
|
Thz James, I managed to get most of it going. Had to add make Connection class inherite from MarshalByRefObject as well as all objects within the class and some had to be made Serializable().
TGIF
|
|
|
|
|
Hi!
I would really like someone to explain to me how to use resource files with bitmaps...
Also I have this problem which with I hope you can help me...
I have this timer which calls a method called animation, which takes a bitmap, defines a rect, and then copies one piece of a bitmap into an imagebox.... this is done with a interval of 75 ms...
But if I do the same (call the animation method) with a for-loop, with a Thread.Sleep(75) within it, it throws an exception: out of memory.
Why
Also it didn't in the beginning, but even then, the funktion didn't show a smoothe series of images, but it just "froze" (apperantly).
Please Help!
|
|
|
|
|
If you have VS.NET (or Visual C# Standard or VB.NET Standard) embedding a bitmap resource is fairly easy.
1st: Add the bitmap to your project.
2nd: Set the "Build Action" of the bitmap to "Embedded Resource", this is set in the properties for the bitmap.
3rd: Figure out the name of the bitmap in the built assembly. To do this, take the default namespace of the project, then append any folders the bitmap may be in, finally append the bitmaps filename.
ex. The default namespace of your project is "defnamespace", the bitmap is placed inside a folder named "images" and the bitmap is named "mybitmap.bmp". The full name of the bitmap in the assembly is "defnamespace.images.mybitmap.bmp".
One of the Bitmap's constructors takes the namespace of a Type that is passed in, and appends the filename that is also passed in to find the bitmap to load from.
The constructor looks like this:
Bitmap(Type type, string filename)
To use it; supply the type that matches the full name of the bitmap; then for the filename supply what is missing.
ex. If the Type passed in has the namespace of "mycompany.myproduct" and the filename passed in is "images.mybitmap.bmp" it will search for a bitmap named "mycompany.myproduct.images.mybitmap.bmp".
If you prefer to get a Stream object (which works for any file) life gets easier for you
First you need a reference to the Assembly that contains the bitmap; unless you're dealing with multiple assemblies, you can get that by getting the Type that represents the class you are dealing with (GetType() for instance methods or typeof(MyClass) for static methods) then use the Assembly property on it.
Now call the GetManifestResourceStream and pass in the full name of the bitmap.
Use the stream it returns to load the bitmap up as if it were any other stream.
ex. The full name of the bitmap is "mycompany.myproduct.resources.mybitmap.bmp" and the class is named "MyClass".
System.IO.Stream stream = null;
Bitmap bitmap = null;
stream = typeof(MyClass).Assembly.GetManifestResourceStream("mycompany.myproduct.resources.mybitmap.bmp");
bitmap = new Bitmap(stream); There is an overload of GetManifestResourceStream which takes the same parameters as the Bitmap constructor that was discussed. But if you wanted to use that form, you may as well use the Bitmap constructor.
HTH,
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Has anyone had any experience with the MouseLeave event for the button control? Will it dependably fire or will it not go if the mouse is moved to quickly?
If necissary I could add some code to the form to check the position of the mouse, but I'd prefer not to .
Thanks,
Steve
|
|
|
|
|
See TrackMouseEvent
Normski. - Professional Windows Programmer
|
|
|
|
|
Hi,
Does anyone know if there is an update function in C# that will allow a TreeView to be sorted alphabetically? I have items being added to my tree but they just aren't being listing alphabetically. If I close my program out and rerun it -- it is then that they are listing alphabetically. Did I miss something? Any help would be greatly appreciated. Thank you.
cAptHiDDeN
|
|
|
|
|
Hi,
I would like to create a simple user control. It only should draw a border. I did that, added it to the toolbox, used it, and it was no problem.
But:
I would like my user control to be transparent, so that the background of the parent form is visible everywhere my user control does no drawing.
Hope you understand and give me an advise.
Thanks
|
|
|
|
|
I don't know how to do Localization in ASP.NET, if somebody has an example please provide.
Thanks in advance.
|
|
|
|
|
I have one c# form and a textbox on it. I want to accept only numric values through it .
Is there any such control property?
VIKS
|
|
|
|
|
Not built in. You can find various masked inputs that other people have made, or you can override OnKeyPressed and OnTextChanged to cancel any non-numeric input.
|
|
|
|
|
Thanx for the reply.
VIKS
|
|
|
|
|
You can use regular expressions to control the input; here you can find a short tutorial with examples for regular expressions: http://www.c-sharpcorner.com/3/RegExpPSD.asp
|
|
|
|
|
My situation is that I have two tables: tblKeyword and tblProjectKeyword.
tblKeyword contains a list of available keywords (intKeywordID, txtKeyword).
tblProjectKeyword (intProjectID, intKeywordID).
tblProjectKeyword.intKeywordID is a FK to tblKeyword.intKeywordID.
tblProjectKeyword.intProjectID is also a FK to another table. So the
tblProjectKeyword table is a Many-Many relationship... a join table.
What I'd like to do is bind the contents of tblKeyword to a CheckListBox
control but have all the matching records in tblProjectKeyword appear
checked for a specific project. My keywords work similar to the Categories
window in Outlook items... the user will be able to check/uncheck and add
more keywords to the list.... So, the CheckedListBox would contain ALL
keywords, and have only those in the tblProjectKeyword checked. Additions
to the list would be added to the tblKeyword table and checked items would
be added to the tblProjectKeyword table.
Currently I'm implementing this manually (creating all the items... when one
is checked, I add a record to the table, etc, etc). I was wondering if I
could use databinding with this complex example. I know you can bind a
table to it, but I didn't know if I could bind two tables with some specific
conditions.
Currently, I am binding the tblKeyword table to the control.. then stepping
through everything in the list, checking to see if it's in the tblProjectKeyword list, and checking those that are found. When the checked state changes, I manually add/delete items to the tblProjectKeyword Datatable.
Thanks for your input in advance!
AC
Andrew Connell
IM on MSN
andrew@aconnell.com
|
|
|
|
|
how do i get all the treenodes in a treeview including the subdirectories??
treenodecollection = treeview.topnode.nodes return only the child nodes of the topnode and doesnt include the subdirectories.
i = treeview.topnode.getnodecount(true) does return the count but doesnt seem to return the nodecollection as such.
Is there any method available or it has to be implemented recrusively.
thanks.
|
|
|
|