|
In your class define a static field (static int instanceCount = 0), and then in the constructor increment this with instanceCount++
And decrement in the destructor.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
It depends on the activation type. If you use a client-activated single call remoting object, then you'll need to use a static field like the first reply mentioned. If you're using a singleton, then since each client gets the same instance, you can use a simple instance field.
In either case, if you want to persist this, consider either logging each time a client connects to a file or database along with some basic information about the client, much as a web or FTP server would do. It's more robust and if the machine fails, you won't have to worry about your counter being reset. Another possibility is to use performance counters (see System.Diagnostics.PerformanceCounter ) which can be persisted by setting up a performance monitor and logging it with the perf counter you would create. This is even more robust since you don't actually need to write a log parser.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Here i use BitBlt(destDC,x,y,w,h,srcDC,x,y,SRCCOPY) to copy srcDC into
destDC.
i think GetPixel(destDC,x,y) can get the Pixel info at Point(x,y).
and my question is :
can i get bytes info from destDC directly ?
because i think get bytes directly is faster than GetPixel()'s way.
why do i bring out this question?
i have read a msdn help 'How to save a true color bitmap into a Gif file'
which tells me how to get the pixelinfo and save the bitmap into a gif
file.And the help says while doing pixels processing,the LockBits() method
is more efficient than GetPixel()'s way.
so i think whether there is a way to get bytes info from DC directly like
LockBits() do.
|
|
|
|
|
Yes, use lockbits. If you're using C#, unless you're loading the old GDI functions directly and calling them, you can do it exactly as they describe, and as I show in my image processing articles. If you've got a HDC, and not a Bitmap, you can create a Bitmap from a HDC, otherwise you'll need for the image to be a DIBSection, in which case you'd have a pointer to the image data already.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
oh,thanks for ur suggestion.
and where can i find ur "image processing articles"?
while i m looking for DIBSection on MSDN,i dont know the
corresponding types in C# to types in C such as LPVOID ,and so on.
|
|
|
|
|
fu0 wrote:
and where can i find ur "image processing articles"?
I don't know what 'ur' means, but my image processing articles are here on the code project site.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hello:
Is there a way to set application properties that are global and accessible from all points in the program. I have tried public static classes, constants, properties on the main form, properties in the app object, but it always tells me that the "prop" is not in scope.
How do you guys handle this kind of problem for setting application wide defaults. It was easy in vfp, but i'm pulling my hair out here (what's left of it anyway).
Thanks.
|
|
|
|
|
Having one class with static fields is good. Just make shure that all class'es are in the same namespace.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
The classes are in different namespaces. I thought adding a reference to the individual namespaces would allow me access to the class from anywhere. Is that not true?
|
|
|
|
|
By adding refrence you mean:
using YourNameSpace; ?
the using statment is only aplied to one file if it is placed outside the namespace {} block!
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Thanks for replying, but I'm still lost. I'm trying to load the values into a static structure now. The values are loaded, but when I try to access them from the watchwindow, I get the "out of score" error.
Pardon me, but here is the code. Can you tell me what's wrong?
<font size = 1>using System;
using System;
using AMS.Profile;
namespace MySpace
{
public class AppStartUp
{
public AppStartUp()
{
}
public struct AppDefaults
{
public static string server = "";
public static string dataBase = "";
public static string adminPath = "c:\vsdevelop";
public static string sqlConn = "";
}
public static void SetAppDefaults()
{
Registry profile = new Registry();
AppDefaults.server = profile.GetValue("DBSettings","DBServer","");
AppDefaults.dataBase = profile.GetValue("DBSettings","DBName","");
AppDefaults.adminPath = "c:\vsdevelop";
AppDefaults.sqlConn = "SERVER=" + AppDefaults.server.ToUpper().Trim() + ";UID=uid; PWD=pwd;DATABASE=database";
}
public static void LoadProgramSettings()
{
SetAppDefaults();
}
}
}
</code>
|
|
|
|
|
You are trying to set a value to a field that is inside the structure, onyl specifying the class ...
And even so I think you must declare the structure as static too ...
but I really don't know why you are using a structure in the above code (dump it)...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Thanks for your help. I've finally been able to get it to work.
Dump it in favor of what? classes.
There has been some discussion on speed using structures for static storage. It seems that most favor the structure. You reasons?
|
|
|
|
|
It has no sense in using a structure like that.
There is no need for you to "group" fields inside a structure, becouse you already have them inside your class.
Maybe you should read some article that covers the OO aproach to desigening programms
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
To add, you may want to consider caching the settings instead of reading them from the registry each time. If they can be changed throughout your application, then have additional methods on this class that can reset some flag so that the values would be read and cached again.
Also, use a private constructor so that callers can't instantiate this class since that would serve no purpose. In .NET 2.0, you don't need to do this if you use static classes (prefix your class declaration with static ). This will be out early next year, just FYI.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello:
Thanks for responding. I'm loading the values into the global properties one time at application startup. In that instance, would caching the values give me any benefit?
|
|
|
|
|
Well first, you need to expose them. You're simply setting them on a struct, which goes out of scope so they can never be read again. While I don't particularly find this approach to settings at all attractive from an OO standpoint, the least you can do is provide static properties on this class using the guidelines I outlined. What you're doing right now won't work at all because the struct simply goes out of scope like in the rest of your thread the other replier mentioned.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, I think in a near time you'll hate me, I'm porting code from C to C#, I've this structure define in unrar.h
<br />
struct RAROpenArchiveDataEx<br />
{<br />
char *ArcName;<br />
wchar_t *ArcNameW;<br />
unsigned int OpenMode;<br />
unsigned int OpenResult;<br />
char *CmtBuf;<br />
unsigned int CmtBufSize;<br />
unsigned int CmtSize;<br />
unsigned int CmtState;<br />
unsigned int Flags;<br />
unsigned int Reserved[32];<br />
};<br />
and should be used by unrar.dll's function
HANDLE PASCAL RAROpenArchiveEx(struct RAROpenArchiveDataEx *ArchiveData);
I tryied using mashalling to mirror dll's structure in C#, but invoking RAROpenArchiveEx it hangs up, supposing due to the pointer to ArchiveData....
How should I go on? I don't know how to convert
unsigned int Reserved[32];
wchar_t *ArcNameW;
thanks....
|
|
|
|
|
Paolo Ponzano wrote:
Hi, I think in a near time you'll hate me, I'm porting code from C to C#, I've this structure define in unrar.h
I think in a near time you'll hate me, but why aren't you using managed C++? Simply write a bunch of wrapper classes, compile with /CLR, and you're done!
Due to technical difficulties my previous signature, "I see dump people" will be off until further notice. Too many people were thinking I was talking about them...
|
|
|
|
|
I don't know...... I started with C# and since I also have applied a lot of improvement I don't want to redo all again =)
May I only do the unpacking routine in C++ managed and all the rest in C#?
|
|
|
|
|
Thats the idea
|
|
|
|
|
but have I to create a new project and write a dll that will be invoked? or what? can I use C++ code in a C# project? I don't think so.....and I don't also how to let C# to use C++ code...thanks again
Paolo
|
|
|
|
|
It should look something like this:
[StructLayout(LayoutKind.Sequential)]
public struct RAROpenArchiveDataEx
{
[MarshalAs(UnmanagedType.LPStr)] string ArcName;
[MarshalAs(UnmanagedType.LPWStr)] string ArcNameW;
[MarshalAs(UnmanagedType.U4)] int OpenMode;
[MarshalAs(UnmanagedType.U4)] int OpenResult;
[MarshalAs(UnmanagedType.LPStr)] string CmtBuf;
[MarshalAs(UnmanagedType.U4)] int CmtBufSize;
[MarshalAs(UnmanagedType.U4)] int CmtSize;
[MarshalAs(UnmanagedType.U4)] int CmtState;
[MarshalAs(UnmanagedType.U4)] int Flags;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)] int[] Reserved;
}
[DllImport("rar32.dll")]
private static extern IntPtr RAROpenArchiveEx(ref RAROpenArchiveDataEx data);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks a lot... but how I declare in my method the structure??
this way -> RarOpenArchiveDataEx data = new RarOpenArchiveDataEx()???
or since in dll's function RAROpenArchiveEx I've a ref to that structure I need to use something I don't know?
thanks again
Paolo
|
|
|
|
|
Create an instance of your struct and pass it to your method:
RAROpenArchiveDataEx data = new RAROpenArchiveDataEx();
IntPtr retVal = RAROpenArchiveEx(ref data);
Microsoft MVP, Visual C#
My Articles
|
|
|
|