|
Make sure you're cleaning up code. If you use any IDisposable implementations (ADO.NET connections and commands are a good example), make sure you call Dispose on them when finished. It's a good idea to using a using block to make sure resources are released:
using (SqlConnection conn = new SqlConnection(...))
{
} It's also a good idea to instrument your service (using the Event Viewer, WMI events, etc.) so that you know what's going on. Obviously this would be a hard problem to debug (given the amount of time before things start going haywire), so instrumenting your app and responding to events will let you know when a problem starts.
Read some of the exception management and instrumentation blocks in the MSDN Patterns and Practices[^] section.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I created a C# project and I would like to call functions in my existing C++ project, so I add the C++ project to my C# solution. Can someone please tell me how to call a C++ function from a C# project? Thank you for your great help.
|
|
|
|
|
you need to add reference to the project in your C# project. This is a guess.
|
|
|
|
|
If this is a Managed C++ project, then it produces an assembly that you can use like any other assembly in your C# project.
If you want to call exported native functions, you need to learn about Platform Invoke. Read Consuming Unmanaged DLL Functions[^] and Marshaling Data with Platform Invoke[^].
If your project is a native VC++ project, your C# doesn't need a reference to it. Just make sure the compiled DLL is resolvable (i.e., either in the application's directory or in a directory within the PATH environment variable).
Read about the LoadLibrary API in the Platform SDK for the exact steps that the Winodws executable loader uses to resolve executables.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Fairly simple: i need to get the correct [THEME]_STARTBUTTON_BMP resource from the msstyles file, according to the current theme. UXTHEME reports Homestead for olive, Metallic for Metallic ... but... NormalColor for blue. i need the string "blue" if the current theme is in fact, the blue theme, in order to get the correct bitmap resource. IS THIS POSSIBLE?????
P.D.: I've tried, but uxtheme doesn't supports direct painting of startbutton resource, so, i thought the key is inside the .msstyles file itself. If i have the exact location where: DEFAULT=BLUE, then i read it and my problem is over. AFAIK, this location doesn't exists. PLZ HELPP!!!!
|
|
|
|
|
(this probably really belongs in the VS IDE board, but I'd rather Mr. Stewart took a read - apologies all)
Is there a way to programmatically create the "Add Reference" dialog as seen in the VS.NET IDE? I'm aiming at creating a wizard to generate a particular type of component. During this wizard process, the user will need to select an existing .NET assembly (one that conforms to interface X). I'm wobbling between writing my own file chooser, but if the "Add Reference" dialog is a creatable control, I'd rather use that.
Any ideas?
Jeremy Kimball
I have traveled the gutters, lo these many days, with no signs of life. Well met.
-brianwelsch
|
|
|
|
|
Currently, the way the Add Reference works is as follows:
Go to the registry
Under the Framework it get the list of directories
Under each directory it gets each item in the GAC
You could probably do something similar where you have either a number of well-known directories or a way of dynamically constructing a directory list. For each assembly in each directory, you would then do an Assembly.Load and check to see if it exposes IMyInterface.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Thanks for the replies guys...I'll probably end up going with the Registry iteration route. Kinda fits what I was thinking before I came up with the Add Reference idea.
Jeremy Kimball
I have traveled the gutters, lo these many days, with no signs of life. Well met.
-brianwelsch
|
|
|
|
|
As theRealCondor said, you go to the registry. Enumerate the keys under HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\AssemblyFolders. If you want, you could also have your dialog enumerate the GAC using fusion.dll. Read Undocumented Fusion[^] here on CodeProject for more details.
And, no, this really doesn't belong in the IDE forum, since you're only talking about programming something like the IDE has. Just my opinion, anyway.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What exactly is the point of enumerating GAC assemblies? It's not like VS will let you add references to assemblies that are sitting in the GAC.
|
|
|
|
|
See ExecuteCommand Method (DTE Object). You'll want "Project.AddReference", I think...
DTE.ExecuteCommand("Project.AddReference", "");
Try it in the immediate window by typing "Project.AddReference" It'll bring up your requested dialog.
Ian Mariano - Bliki | Blog
"We are all wave equations in the information matrix of the universe" - me
|
|
|
|
|
Nifty...never screwed much with the Command Window. Nice to know what it can do.
Jeremy Kimball
I have traveled the gutters, lo these many days, with no signs of life. Well met.
-brianwelsch
|
|
|
|
|
The following doesn't seem to work...
foreach (Form f in this.MdiChildren)
{
f.Close();
}
I recieve the following error "Specified cast is not valid."
Am I missing something.
Sweet
|
|
|
|
|
You can't change a collection while enumerating it. Calling Close ultimately will change the collection. Instead, use:
for (int i=0; i<MdiChildren; i++)
{
Form f = (Form)MdiChildren[i];
f.Close();
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Right now comes the this. I've got 3 mdichildren forms and when I click the button to close all the forms, only 2 closes and 1 stays open until I click the button again. Is it because I did the following like u showed except I added .Length.
for (int i = 0; i < MdiChildren.Length; i++)
{
Form f = (Form)MdiChildren[i];
f.Close();
}
Sweet
|
|
|
|
|
Sorry - I made a mistake. You should either run through the array backward or make a copy of the array (and forgetting .Length was a typo - it's only sample code):
for (int i=MdiChildren.Length; i >= 0; i--)
{
Form f = MdiChildren[i];
f.Close();
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks it works. All I had to do is add the - 1
for (int i = MdiChildren.Length - 1; i >= 0; i--)
{
Form f = MdiChildren[i];
f.Close();
}
The Author of the book I'm reading should revise his book.
My brain is 2 small for all the knowledge that I need.
|
|
|
|
|
You were real close, here is my CloseAllChildren process for my MDIParent:
private void CloseAllChildren()
{
System.Windows.Forms.Form[] myChildren = this.MdiChildren;
foreach (Form child in myChildren)
{
child.Close();
}
return;
}
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Hi everyone.
Could anyone give me a few pointers on how to write a writepixel method with directx for .NET please?
Thanks.
|
|
|
|
|
Without going into too much detail, it's not quite that easy. There are two ways to do what you're talking about. One is blitting a one pixel blob to the location specified. The other involves locking the surface buffer, and then using the desired coordinates (x,y) and the stride of the surface (# of bytes/scan line) to determine the offset needed to set.
Kinda like this: (not compilable code)
WritePixel(Surface surf, int x, int y, int col) {
int[] surfaceContents = surf.Lock(....);
int offset = (y * surf.width * surf.SurfaceDescription.Stride) + x;
surfaceContents[offset] = col;
surf.Unlock();
}
You're better off searching thru Google about the actual formula involving X, Y, and stride. I can't remember exactly where the stride fits in at this second.
Good luck
Jeremy Kimball
I have traveled the gutters, lo these many days, with no signs of life. Well met.
-brianwelsch
|
|
|
|
|
Hello again.
This is how I now try to do it
public void WritePixel(int color,int x, int y)
{
Array surfaceContents = _surface.Lock(LockFlags.SurfaceMemoryPointer);
int offset = ( x ) + ( _surface.SurfaceDescription.Pitch * y);
surfaceContents.SetValue(color,offset);
_surface.Unlock(null);
}
However I get an error that says lock doesn't return Array, although that it is what is stated in the ms documentation. Is this a bug or am I just doing things the wrong way?
Thanks.
|
|
|
|
|
It's of *type* Array, but think of it more as an Array of *something*.
As in:
Array == int[], or byte[,], etc.
Actually, if memory serves, Surface.Lock actually returns a 2D byte array, but my memory sucks, so check through Google to make sure.
If I'm right:
byte[,] surfaceContents = Surface.Lock(LockFlags.SurfaceMemoryPointer);
Good luck
Jeremy Kimball
I have traveled the gutters, lo these many days, with no signs of life. Well met.
-brianwelsch
|
|
|
|
|
I have a Custom Collection based on IList, so I can bind it to a datagrid. But if I change an item in the collection the information on the grid doesn't change.
How can I get this to work, like the dataset databinding works? If I update an item in a datatable in a dataset the grid gets updated instantly.
"Every rule in a world of bits and bytes can be bend or eventually be broken"
|
|
|
|
|
|
Hi all,
I have seen lots of articles on the subject of datagrid controls and check boxes. I am currently designing a goods movement system for the company i work for and i have most of it finished. However, on the last page i want to display a datagrid control with data that has been entered on previous pages, that bit i have done including formatting the datagrid (which took some figuring out but i got there in the end).
The user will have to go through each entry every week and tick them off one by one. I have added a DataGridBoolColumn object to the TableStyle.GridColumnStyles collection and the check box displays fine. However i have 2 problems.
1. The default value for the check boxes is true, i need it to be false and setting the value to false when setting up the column in code doesn't work. Although by answering the next question this might be solved.
2. Whenever i tick/untick the box then move the focus away from the cell in the grid the checkbox returns to a checked state.
any help that you can give me would be appreciated.
Cheers
KP
|
|
|
|