|
You forgot one important thing:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr pIE = FindWindow("IEFrame", null);
if(pIE != IntPtr.Zero)
{
} [To the original poster] Without that, only the ANSI version of the function would be used; you would not be able to find Windows with Unicode text, plus you would be unnecessarily converting the encoding on Windows NT (i.e., Windows NT 4, Windows 2000, Windows XP, Windows 2003, "Longhorn", and all future Windows OSes), which natively supports Unicode (same as the .NET Framework).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I have two groupboxes in my application form. The user chooses an input type in the first groupbox and then a DSP function in the second.
I would like to implement the following:
1. Choose a particular DSP function by clicking the corresponding radio button.
2. Each DSP function has a set of parameters that can be changed by the user. These function-specific parameters are stored in groupboxes specific to the DSP function.
i.e.
DSP_Function_1's parameters can be set using GroupBox1,
DSP_Function_2's parameters can be set using GroupBox2, etc.
All parameter related groupboxes are of the same size and open in the same space.
Also, I want these groupboxes to open in my main form and not a separate form.
What would be the simplest way to implement this?
|
|
|
|
|
Hi there!
I am a newbie in C#, and I am making a program using the AVIFile.
Now I have a problem, it seems that the functions getframeclose() and close() from avistream and avimanager doesn’t release all the memory that they use.
In the task manager the "Mem Usage" increase to 90000K when in the start it was 13000k.
The problem is in this group of instructions, the only thing that I want is one frame of the video.
AviManager aviManager = new AviManager(aux, true);
VideoStream aviStream = aviManager.GetVideoStream();
aviStream.GetFrameOpen();
Bitmap bmp = aviStream.GetBitmap(Convert.ToInt32(Position));
aviStream.GetFrameClose();
aviManager.Close();
With this group of instructions the "Mem Usage" in the task manager increases 20000k!!!!
I don´t think that this is the size of Bitmap, Am I wrong?!
How can I solve my problem?!
COuld you help me?!
Thanks you very much, Sérgio Órfão
|
|
|
|
|
Deterministic finalization (or lack there of) has been a large debate ever since .NET was release in beta. You should read up on garbage collection, which is what .NET uses to clean up resources. There are several articles here on CP and MSDN, here are a few:
Garbage Collector Basics and Performance Hints[^]
Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework[^]
Quick tip, if your objects implement IDisposable interface, wrap them in a using statement. This will automatically emit try/finally blocks around your code and then call Dispose on the object for you. An example:
using(Bitmap b = new Bitmap(32, 32))
{
}
Looks like:
try
{
Bitmap b = new Bitmap(32, 32);
}
finally
{
b.Dispose();
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
First of all, I want to thank you for your reply.
I was trying to implement your suggestion but when I put this instruction
using(AviManager aviManager = new AviManager(aux, true))
the compiler gave me this error
Cannot implicitly convert type 'AviFile.AviManager' to 'System.IDisposable'
Is it possible to makr my object implement IDIsposable interface?!
If not, how can I do the Dispose function?!
I tried this way
public void Dispose()
{
Finalize();
System.GC.SuppressFinalize(this);
}
But didn´t work =/
Can I make a dispose function for this class?!! If yes, how?!
Thanks again, Sérgio
|
|
|
|
|
If you have written the AviManager class you can obviously change it to include the IDisposable interface (and obviously implement the Dispose method), otherwise you can subclass the AviManager and thus implement the IDisposable interface. You will need to know how to clean up the resources in AviManager .
public class MyAviManager : AviManager, IDisposable
{
void Dispose()
{
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Adding a method isn't enough - you have to implement the interface that defines that method. Just do what Nick said.
You NEVER call Finalize() - especially not in IDisposable.Dispose . You really should read Implementing Finalize and Dispose to Clean Up Unmanaged Resources[^].
Also, if you're not going to free native resources, there's no reason to implement IDisposable . The GC will release managed resources, but unmanaged resources (i.e., file, graphics, images handles, etc.) you must release (or release from other objects by calling their IDisposable.Dispose implementation, if possible).
The Bitmap in your first code snippet is currently the only thing that implements IDisposable , so you should use using as Nick suggested.
Be sure to read that link I posted above to learn more about IDisposable and managed and unmanaged resources.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi,
I'm writing a logging utility and I need to wrap the string.Format method. I'd like to call the Trace method of MyLog like this:
<br />
MyLog.Trace("Var1:{0};Var2:{1};", MyVar1, MyVar2);<br />
The Trace method should then use the string.Format function to produce a properly looking string. I thought the signature for my Trace method should be:
<br />
public void Trace(string s, object[] args){};<br />
But the compiler complains:
cannot convert from 'string' to 'object[]'
when coding:
<br />
string sFun = "Hello World!";<br />
MyLog.Trace("Say {0}", sFun);<br />
How can this be done? Any help is greatly appreceated.
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
www.emvoid.de
|
|
|
|
|
Matthias Steinbart wrote:
public void Trace(string s, object[] args){};
Change it to:
public void Trace(string s, params object[] args)
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi folks
i am looking for some samples using Mesh objects (from Direct3DX) to draw simple 3D objects like a box or sphere (Mesh.Sphere()).
Thanks.
|
|
|
|
|
There are samples in the DirectX SDK[^] for C++ (unmanaged), C# and VB.NET (both managed, of course). You'll need to install the Managed DirectX libraries to run the managed samples (IIRC, the SDK now installs the managed runtime, but the DirectX runtime setup and managed libraries are separate).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I would like to convert a integer into a byte-array:
0x1234 ->
b[0]=1, b[1]=2 ... b[3]=4
How is this to be done?
Thanks!
Ariadne
|
|
|
|
|
So, looking at your example, what you want is to take, in groups of 4 bits, the integer and place it in to a byte array in big-endian ordering? So, that for a System.Int32 you would get byte array containing 8 elements? Is this right?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
I'm seek for two solutions:
(1) How can I address the particular bytes of a int variable
(2) I need finaly an byte-Array with
int = 0x1234
byte [3] -> [0]
int 0x1 -> 0x4
Ariadne
|
|
|
|
|
I'm guessing that you're bytes are merely representational to your integer, because the integer 0x1234 is actually only 2 bytes large (2 hex digits are a byte). For that, you can use BitConverter.GetBytes .
If it is representational, you'll need to parse it yourself. You could first transform the number to a hex string and then parse each numeric value to a byte:
string val = 0x1234.ToString("x");
byte[] buf = new byte[val.Length];
for (int i=0; i<val.Length; i++)
buf[i] = (byte)((int)val[i] - 48);
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi..
I am trying to write a windows service and this service have some jobs which must be done just only once at a day. My windows service read a file,which all job info stay in the file, when it starts up and create job objects and push them to a array, named Jobs.
Every job object has;
-->time
-->ok (default:false)
-->job to do.
Job[0] -----> 14:50<br />
Jobs[1] -----> 13:24 <br />
Jobs[2] -----> 13:12<br />
.<br />
.<br />
.
So I put a timer that checks if its is the exact time for every job. the interval of the timer is minute (1000ms). if any of Jobs is done the ok flag turns to true. And the job never done again. When the clock show 24 every thing starts again..
But there is smthg wrong that I could not found.
1. I could not debug the timer events. I attach the process to vs.net to see what is going on but the timer event code confused me that it smtimes turn over and over. How could I debug a timer code
2. If the two or more jobs times are same what will happen. Must I use thread to solve this problem. How could I use a timer and threads together?
karanba
|
|
|
|
|
karanba wrote:
1. I could not debug the timer events. I attach the process to vs.net to see what is going on but the timer event code confused me that it smtimes turn over and over. How could I debug a timer code
1000 ms is 1 second, not 1 minute. 60000 ms is 1 minute. There's nothing special about debugging a timer event. All you need to do is attach the debugger to your running service.
karanba wrote:
2. If the two or more jobs times are same what will happen. Must I use thread to solve this problem. How could I use a timer and threads together?
This all depends on how your checking to see what jobs need to be run and how your executing these jobs and what they are. I'm assuming your doing this inside your timer event, but it all depends on how your doing this.
Without a code sample, it's impossible to tell you what might happen or what you have to do.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanx the 10000 to 60000 ms solve the first problem.
on the second issue;
the timer code try to read an url and smtimes this could be long than 2 minute to get a url.
here is the job instructor
public job(string url, string ms, int tp)<br />
{<br />
this.url = url;<br />
this.type = tp;<br />
this.ok=false;<br />
if(tp==1)<br />
{<br />
timer = new System.Timers.Timer();<br />
timer.Elapsed+=new ElapsedEventHandler(OnTimedEvent); <br />
timer.Interval=System.Convert.ToInt32(ms);<br />
this.interval = System.Convert.ToInt32(ms);<br />
timer.Enabled=true;<br />
}<br />
else if(tp==0)<br />
{<br />
this.onTime = System.Convert.ToDateTime(ms); <br />
}<br />
}
and the OnTimedEvent
private void OnTimedEvent(object source, ElapsedEventArgs e)<br />
{ <br />
extras.readURLfromUri(this.url);<br />
}
I want to be sure that if two read url request come on the same time both will done as posible as the CPU and network is available.
karanba
|
|
|
|
|
Hi there. I am having trouble in C# trying to get from a mapped network drive letter to an actual network machine name. Is there a method somewhere to performn this conversion.
Cheers,
Brian.
|
|
|
|
|
There are several ways, but nothing exposed in the .NET Base Class Libraries (BCL). C#, keep in mind, is just one of many languages that target the CLR and can access the BCL.
One way is to P/Invoke QueryDosDevice . The output is perhaps not quite the format you are looking for, but is the actual mount point for a drive:
using System;
using System.Runtime.InteropServices;
class Test
{
const int MAX_PATH = 260;
static void Main(string[] args)
{
if (args.Length != 1) Environment.Exit(-1);
string path = new string('\0', MAX_PATH);
QueryDosDevice(args[0], path, MAX_PATH);
Console.WriteLine("Mount point: " + path);
}
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern int QueryDosDevice(string name, string path, int max);
} Paste this to a file, compile it with csc.exe /t:exe <Filename.cs>, and run it on the command line, passing a drive mapping in (like U:, if U: is your user profile drive, for example). Do not include a trailing backslash (i.e., don't pass "U:\").
There are many other functions documented in the Platform SDK. I encourage you to try searching.
If you need help constructing Platform Invoke (P/Invoke) methods for native functions, take a look at http://pinvoke.net[^] or as here.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
There is nothing native in the .NET BCL that'll do this for your. You'll have to call into (P/Invoke) the Win32 WNet (Windows Networking) API to get this information. Everything will come from the MPR.DLL file.
To enumerate the connected resources (mapped drives), you'll need to use the WNetOpenEnum , WNetEnumResource , and WNetCloseEnum functions. You'll also need to supply the structures used, NETRESOURCE , and the values for the constants used by WNetOpenEnum .
You can pickup the declarations for the functions, structures and constants from PInvoke.net, here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Back in my C++ days, I relied on BoundsChecker to help identify potential memory leaks and resource leaks since I write mainly server-based services that run 24x7.
With .NET, managed code and garbage collection, is there still a need for these third-party tools? What's your experience?
Also, can someone explain this...I have a console .NET application that starts up taking around 9K of memory. By the time everything gets loaded, Task Manager shows it taking around 20K. Fine. But when the console window is minimized, the memory (as reported by Task Manager goes down to like 3K! WTF?!
Barry Etter
|
|
|
|
|
Well the suite that BoundsChecker is in is changing to more of a profiling and performance tool. They actually have a free profiler (community edition) for VS.Net. Its not the best, but its not bad either. Compuware [^]
As for you memory question, if you look at any application, esp VS.Net when its up and then minimize it and there will be a difference in the memory used. I think that this is due to the OS getting rid of some of the memory pages that it does not need. I have observed this with all windows apps, not just console apps.
Steve Maier, MCSD MCAD
|
|
|
|
|
Yes there is such a use, but a CLR profiler is a better choice. Many classes in the .NET BCL (and third-party libraries) rely on native resources. These are unmanaged resources because the CLR does not manage them. File handles are a good example. FileStream (actually, any String ) implements IDisposable because there may be a file handle (there is for a FileStream ) or some other native resource that must be closed when finished. You must call the IDisposable.Dispose implementation when finished with such an object. If you are a class designer, you should follow the dispose pattern discussed in the .NET Framework SDK and other articles:
class MyObject : IDisposable
{
~MyObject()
{
Dispose(false);
}
void IDisposable.Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
}
}
} Unmanaged resources will be freed aventually. There is no gaurantee of when the GC runs, however, and you should almost never call GC.Collect (repeated calls can greatly hinder the performance of your application). This is why IDisposable exists. The using block statement is good to make sure that - even in case of exception - your objects are disposed:
using (FileStream file = File.Open("file.txt", FileMode.Open))
{
} Is the same as:
FileStream file = File.Open("file.txt", FileMode.Open));
try
{
}
finally
{
if (file != null) ((IDisposable)file).Dispose(0;
} So, exceptions will still be thrown, but at least the file is disposed and the native file handle is released.
So, in a round-about way, you should be able to see that while objects are garbage collected, resources they use (i.e., unmanaged resources) are not. Using a profile will help you find those problems, although it's a good rule of thumb to always dispose of any object that implements IDisposable anywhere up the class inheritance hierarchy.
Profilers can also help you find bottlenecks in your code; any platform is susceptible to that since it's typically human fault.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi People,
I have a problem with changing the BackColor of a System.Windows.Forms.DataGrid cell. Actually I don't want to change the whole Style of the DataGrid - what I want is to change just the backcolor of an exact Cell that corresponds to certain requirements.
Does anyone knows how can this be done. I have looked in the MSDN and I'm starting to believe that this is not possible.
I would be grateful for any help.
|
|
|
|
|