|
Thanks for the info. I think I find the solution. I've just created a simple .Net Remoting server(which is kind of new to me) and a .Net client. It seems to work nicely as expected. I then created another simple MFC application using managed extensions to simply delegate all calls to the .Net Remoting server. All the non-managed applications can call via the MFC application. I run through a quick test and it seems to work great. I have not yet to test using Process.Start to launch the server if the server is not running, but it should work. One caveat, if I want to use any COM dlls in the .Net Remoting server, the COM dlls must be dual interfaced automation objects (inherit from IDispatch not IUnknown), or I'll get a "QueryInterface failed" error, which seems make sense. I appreciate any suggestions or comments you may have. Thanks again for your help.
|
|
|
|
|
QueryInterface is a method of IUnknown - not IDispatch - so I don't see what could be the problem. More information may be helpful.
For example - have you created an RCW (runtime callable wrapper) or are you trying to create an automation object? Automation objects - i.e., objects that are late-bound - require either dual or IDispatch inheritence in order to invoke methods at runtime.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Sorry, I replied to myself. Please see my last response. Thanks.
|
|
|
|
|
As a test, I had two COM objects: one is inherit from IDispatch and the other is from IUnKnown. The .Net Remoting server can call any functions exposed by these two objects without any error. When a .Net client call the server to access any functions exposed by the IUnknown COM object, it gives "QueryInterface failed" error, but OK for the IDispatch COM object. I am not sure why it needs to call QueryInterface.
|
|
|
|
|
Jason Ruan wrote:
I am not sure why it needs to call QueryInterface.
All methods exposed by IUnknown - which every interface inherits from - is essential to COM. QueryInterface (or just "QI" for us COM-heads, like you QI for an interface) is how you get a reference to an object based on an interface it exposes, or you get E_NOTIMPLEMENTED if it doesn't support that interface. When an interface is attributed with the ComImportAttribute , the CLR will QI for that interface using the compiler-generated GUID or the GUID in the GuidAttribute for that interface when you cast an object to that interface.
Do the clients make calls directly on the COM object through the remoting proxy, or does the remoting object proxy calls to the COM object? If the clients make calls directly on the COM object through the remoting proxy then the client need a reference to the interface, either defined in the client assemblies or exposed in a shared assembly (unlike managed interfaces, you can define interface with the ComImportAttribute how every many times you want, so long as you use it only to communicate with the COM object, not passing the interface itself since the Type must be the same).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Is there a reason for the .NET Framework installation (versions 1.1 or 2.0) to ask for the machine to restart after the installation?
I want to distribute an application (smart client) and I don't know if the customer machine runs the .NET Framework. So I want the customer to run a URL. This will check if the machine has the .NET Framework. If it has then only the application will be installed. If not then the .NET Framework will be installed first and then the application.
I know that there is an Updater application block and in .NET 2.0 the click once support this feature. The "how to install?" is not the point.
The thing that bothers me is the fact that the user will have to restart his/her machine after the .NET Framework installation. This overhead is intolerable. I just want it to be opaque for the customer that he/she uses a smart client.
From my experince the .NET Framework installation never asked for restart (1.1 and 2.0), but a friend told me that he was asked to do it.
Does anyone know what are the cases which the .NET Framework asks for restart?
|
|
|
|
|
The .NET Framework does not require a restart - the service pack does (trust me - I help create them). If you go to MSDN and download just the RTMs a reboot will not be necessary (unless, of course, you installed a service pack and haven't reboot yet). When you install the service pack a reboot is required because files are in use. I can't go into details.
The best way is to write your own bootstrapper that eats the reboot code (return code 3010) and proceeds to install your application. You might warn the user that they should reboot later but it most likely won't be necessary depending on what native libraries or assemblies you use in your application.
Writing your own bootstrapper isn't hard. See Using the Setup.exe Bootstrapper Sample with an Application (.NET Framework Developer's Guide)[^] for more information and an example.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Ami Bar wrote:
Does anyone know what are the cases which the .NET Framework asks for restart?
Most modern installers need to restart a machine when some file they need to replace/upgrade is in use.
Yes, even I am blogging now!
|
|
|
|
|
Hello,
I have a ListBox with +/- 10 items (URL)
How to download from Internet these files (maybe with one or more threads).
P.S. Number of items may varies.
Many thanks for your help.
Frederic.
|
|
|
|
|
|
Yes, I know but how to transfer to webclient the contain of listbox (items) and how create many threads without dommage application ?
Thanks in advance.
|
|
|
|
|
...and Nick gave you the answer if you dig a little deeper into the application. The HttpWebRequest and HttpWebResponse define Begin* methods that asynchronously invoke downloads. This uses a thread pool to minimize CPU load by your process.
There is a catch: the default ServicePointManager that the requests use limit request to a host to 2. You'll need to either change ServicePointManager.DefaultConnectionLimit to another number before every instantiating a WebRequest object to another host, or create your own ServicePoint and change it's ConnectionLimit property accordingly to the hosts in your list.
In the future, if you have a question be more specific. If you ask a generic question it's hard to give you a non-generic, and if you don't provide details we can't know what you do and don't know, or what you've tried and haven't tried.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi
Is there anything like "Time to Live" for a Windows Form.
I want to close one after a few seconds. Is that possible?
I got VS 2003..
Greetings from Germany
|
|
|
|
|
Maybe I'm not understanding your question, but you can run a timer when your form starts up, then close the form after a certain amount of time lapses.
Any remotely useful information on my blog will be removed immediately. There are 10 kinds of people in the world. Those who have heard of the ubiquitous, overused, worn-out-like-an-old-shoe binary "joke" and those who haven't.
Judah Himango
|
|
|
|
|
The .NET Framework base class libraries (BCL) are a toolkit. Specific functionality like this is something you have to add.
In this case, all you need to do (if you're of the drag-n-drop variety) is to drag the Timer component from your toolbox in VS.NET onto your form. Set the internal you want (if by "a few seconds" you mean 3 seconds, you set it to 3000 (milliseconds). Switch to the event tab in the PropertyGrid and double-click the Tick event to add a handler. In the handler, add the following:
private void timer1_Tick(object sender, EventArgs e)
{
if (InvokeRequired)
{
MethodInvoker d = new MethodInvoker(Close);
Invoke(d, null);
}
else Close();
} This extra code is necessary because the event handler may fire on a different thread. You should not modify controls on threads other than the thread on which they were created, which is why the Control.InvokeRequired property and Control.Invoke method exist. The MethodInvoker is a standard delegate that takes no parameters and returns void. Often times you would have to declare your own delegates (which are like managed function pointers, or callbacks).
Don't forget to set the Enabled property to true . This would get set in InitializeComponent which is called from the constructor. If your form takes a while to open, you may consider overriding OnLoad (better than handling the Load event when you derive from a control that defines the event you want) and setting Enabled to true in your handler to make sure the timer doesn't start until your form is loaded (just before it displays).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I want to change text color on a single line of text with DrawString().
Ex. <red>The <blue>qui<red>ck, b<blue>rown f<red>ox easily jumps over the lazy dog.
I'm trying to use Graphics.MeasureCharacterRanges(), this method gets the ranges
of a number of characters. All fine. Then I can use a TextureBrush with a colored
image to change the text color. The problem is that I can't use this method when rendering
Italic style text. The color rectangles don't compensate for italics text.
If anyone have any tips or a better method to do this, I will be very grathful.
Many thanks, Gywox
<br />
public void DrawTextColor(PaintEventArgs e)<br />
{<br />
Graphics graphics = e.Graphics;<br />
Rectangle layoutRect = new Rectangle(20, 20, 400, 100);<br />
Font tnrFont = new Font("Times New Roman", 24, FontStyle.Italic);<br />
StringFormat strFormat = new StringFormat();<br />
CharacterRange[] charRanges = {<br />
new CharacterRange(3, 4), <br />
new CharacterRange(12, 6) };<br />
Region[] charRegions = new Region[charRanges.Length];<br />
string str = "The quick, brown fox easily jumps over the lazy dog.";<br />
strFormat.SetMeasurableCharacterRanges(charRanges);<br />
<br />
Image image = new Bitmap(layoutRect.Width, layoutRect.Height);<br />
Graphics graphicsImage = Graphics.FromImage(image);<br />
graphicsImage.FillRectangle(Brushes.Red, 0, 0, image.Width, image.Height);<br />
<br />
charRegions = graphics.MeasureCharacterRanges(str, tnrFont, layoutRect, strFormat);<br />
for (int index = 0; index < charRegions.Length; index++)<br />
{<br />
RectangleF boundsRect = charRegions[index].GetBounds(graphics);<br />
graphicsImage.FillRectangle(Brushes.Blue, boundsRect);<br />
}<br />
TextureBrush textureBrush = new TextureBrush(image);<br />
graphics.DrawString(str, tnrFont, textureBrush, layoutRect, strFormat);<br />
}<br />
Gywox
|
|
|
|
|
Is there a way to test if a file is locked, without opening a FileStream? I find it particularly annoying that when you try to open a file that's locked, an exception is thrown. That's a really dumb use for an exception, but equally dumb is that there is no "test" function, as far as I know.
Interestingly, .NET 2.0 fixes a lot of this by providing "can succeed" type of methods, which is much faster than throwing an exception.
And yes, I know that a "can succeed" on a file lock might return true but then the subsequent Open call will fail because the file got suddenly locked.
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Would you rather have return codes like all the Win32 APIs? An exception is what should be thrown from the constructor. Would you rather it return null and not know why it returned null?
This is consistent with how the native APIs work, as I'm sure you know. When you call CreateFile you will get a return code that states the file is locked.
BTW, I don't see any such "can succeed"-type methods in the latest bits for 2.0 for the file-related APIs. Where did you see such information?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
When you call CreateFile you will get a return code that states the file is locked.
There is no CreateFile method in the .NET FileStream implementation. The API call is embedded in the constructor, it would seem. I would much rather have a method that I can call to test whether the file is locked.
Personally, I've never liked exceptions, except (haha) that they are a useful way of cleaning up the stack. They're innapropriately and inconsistently applied, and often abused.
Heath Stewart wrote:
I don't see any such "can succeed"-type methods in the latest bits for 2.0 for the file-related APIs
Sorry, I meant in general that there's an effort to do this, not that it is specifically done with file-related API's.
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Marc Clifton wrote:
There is no CreateFile method in the .NET FileStream implementation.
Yes, this I know. But if you look at the context, I was talking about native APIs, so I was talking about the native CreateFile API.
Exceptions can be abused, but I think the BCL has a pretty tight reign on them. I see abuses mostly in third-party code (the "less commercial" kind), or just a complete absence of throwing - and especially catching - them.
I personally like them (and other exception mechanisms, like SEH) better than return codes. You don't have to add different conditions with different localized texts (unless you're defining your own exceptions or using your own text, for that matter). The code impact is minimal, but I realize they do cause a slight performance drain to throw, as opposed to just returning an error code. I guess it's really just a matter of opinion, though.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I hate to (cough) agree with Marc, but he's right. There no way an exception should be thrown when you can anticipate the failure of a method call beforehand. Exceptions are better thrown when a caller passes a NULL pointer or some other incorrect parameter value to a method when he shouldn't have; that's something you don't expect; that's something you don't know how to deal with; that's something you don't have an error value for; that's when you throw an exception.
Exceptions are for non-recoverable program failures. Proper error-handling is anticipating that a file you're trying to open may not exist; that should not be the cause of an exception.
Seems to me if the framework is going to provide file locking, it needs to provide a test method that does more than just test to see if the file is locked; it should be able to test, lock the file and open it all in one call, because between the return of the test and any attempt to open the file, someone else may beat you to the it, causing you to get the very exception you're trying to avoid by calling the test.
Marc's (cough) correct, as Microsoft has a bad design and implementation, and should fix the problem.
Also, there is no difference in all of the possible errors you can from win32 and the abundance of exceptions you can get from .NET. Exceptions as used today are little more than typed "goto" statements masquerading as objects, deluding people into believing they have OO error management.
When you force a developer to accept exceptions, you're telling him his program is going to run slower so all of the junior programmers using the language can write code that doesn't do proper failure testing, or instead put error-handling code in an else-statement that appears nowhere near the if-statement that tested the condition that failed. A good portion of exception code and logic entanglements (got that word from Marc) can be corrected by correcting the use of if-statements. Namely, don't handle errors in an else clause.
|
|
|
|
|
I'm writing a winforms app in C# that uses XMLHttp to download jpg's from the web. I previously used WebRequest, but decided to switch to XMLHttp because it utilizees IE's browser cache.
However, I can't figure out how to convert the response from XMLHttp into a bitmap. I've tried loading the response into a byte array, converting that to a memory stream, and then using the stream to create the bitmap, but no luck.
Can anoyone give me a pointer on doing this?
Better yet, does anyone know of a .NET framework method that will use the IE cache for http transactions? I know I can build my own using the Cache object, but really don't want to have to do that.
|
|
|
|
|
Does the response actually contain bitmap data, like for a GIF, JPG, PNG, etc. (or perhaps another image that would just be downloaded as binary data instead of being displayed in a page)? Your subject is misleading, which is why I ask.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi gurus,
I would like to know how to access to the "enable" property of all controls within a form using the foreach loop?
I wish to disable all controls during an operation and enable them once the operation is complete.
Thanks.
Best regards
There is no spoon.
|
|
|
|
|
foreach (Control c in form.Controls)
c.Enabled = false;
Any remotely useful information on my blog will be removed immediately. There are 10 kinds of people in the world. Those who have heard of the ubiquitous, overused, worn-out-like-an-old-shoe binary "joke" and those who haven't.
Judah Himango
|
|
|
|
|