|
I am not familiar with HansBlomme code but, I would assume you are trapping the WM_QUIT (OnClose..) message and canceling the close. This is how windows shuts down apps. You probably trap this to hide your main window instead of killing the app when the [X] close button is pressed.
I handle this by making my main window hidden. This invisible window is the one that owns the notify icon. On double click (or open), I fire off the main UI window. When the main UI window closes, the hidden window keeps the app alive in the system tray. When windows says to shutdown, the hidden window shuts down.
|
|
|
|
|
I have a .NET DLL, whose class has a Main() method.
I want to create a new process from my application and put the DLL on that process.
I expect the Main() in the class to be treated as the entry point resulting in execution of the DLL.
The intention being that if the DLL crashes or hangs, the parent application is not affected.
Is this feasible? If so, how?
.kausthubh.
|
|
|
|
|
If I understand your question correctly then I don't think it is possible. You want to define your application entry point in a separate assembly. I know the IDE won't let you do it and I believe the command-line compiler will not let you do it either. The problem is that .NET uses delay-load on assemblies so the dll containing the entry point won't be loaded until it is needed (after the application starts). The entry point has to be defined before the application starts. I may be wrong here but I don't see a way of doing it directly. You could possibly do it through MSIL.
In regard to your intentions I don't think it'll give you what you want anyway. You can't "put" a DLL into another process directly. Due to the way dlls are loaded into Windows you can't simply load a dll into a process and then move it to another process. It would be a security hole. Debuggers and profilers get around it by debugging the app. This gives them direct access to the process'es memory. There is also an API to access a process'es memory directly but you have to basically be an admin before it'll work.
Irrelevant of all this if a method throws an exception, inside a dll or otherwise, then the parent application will be affected unless the method or one of its callers catches the exception. Having your entry point in a dll does nothing toward exception handling.
A way to get some of the functionality you want, putting the entry point into a dll, would be to call the entry point within the dll directly in the application main.
For the exception handling you should hook into the unhandled exception framework defined by .NET. For Windows Forms handle Application.ThreadException event. For all apps you can also handle the AppDomain.UnhandledException event. In both cases though you'll have no idea what happened and your program state should be considered to be corrupted.
|
|
|
|
|
Hi experts,
I am going to write a class which protocols error messages into a bug-file.
To identify the files/classes/memberfunctions which fails, I am searching for a (Pre)compiler directive
somthing like #file_name, #class_name, #member_fuction, #row which inserts automaticly the names at it's position.
Is there something like that available ?
Thank you in advance
Frank
fracalifa
|
|
|
|
|
C++'s __FILE__ and other pre-processor directives are handy and fast (since they are executed at compile-time), but you don't have anything like that in C#.You can have some comparable information with the StackTrace class and/or with stack trace information on exceptions.
Be aware that the StackTrace class is not a high-performance class, and can impact your performance seriously if you start logging using it.
Besides, the StackTrace class will only give you line numbers if you send a .PDB file with the file (even on Release builds, you can generate/send a .PDB file).
Yes, even I am blogging now!
|
|
|
|
|
|
whenever i use
setstyle( ... ) ;
and in my paint function i do something like
void paintMethod( .., .. )
{
using( Graphics g = e.Graphics )
{
g.doesSomeDrawing();
}
}
the ... statements replace the actual code wich is corect
i am getting an error message saying "Additional information: Invalid parameter used."
and if i don't use the using statement everything works fine .. no error message !
Lazar Mihai
Elev clasa XI C
Grup Scolar Sanitar
|
|
|
|
|
I suspect it is the using
you are copying an existing Graphics object, not assigning a new one.
Gary
In Scotland, there is no such thing as bad weather - only the wrong clothes. - Billy Connolly
|
|
|
|
|
You can either not use the using statement, safely, or you can try something like this:
Graphics g = e.Graphics;
using ( g )
{
g.doesSomeDrawing();
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The actual exception is because the caller of OnPaint (most often WndProc ) is trying to dispose the Graphics object and it's already been disposed.
He should not be using using at all.
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 thought it might be something along those lines, wasn't sure though. Too drugged up to think about it and no VS.NET at work to test it with. 8( Let me tell you, life sucks without a compiler at fingertips!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I didn't have a compiler.
Basically, if you didn't alloc it then you don't free it. In native APIs this isn't always the case, though, since some APIs alloc memory and expect the caller to free it. Such APIs should always document such a requirement.
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:
Basically, if you didn't alloc it then you don't free it. In native APIs this isn't always the case,
I've run into that many a time. I just wanted to try it before I stuck my foot in my mouth.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The answer is simple. The using statement resolves to the following code:
try
{
g.doesSomeDrawing();
}
finally
{
g.Dispose();
}
U are disposing a graphics object that u dont "own" (e.graphics). On a general basis you should only dispose graphic objects that you explicitly create through the Control's CreateGraphics() method or through a New Graphics() statement;
|
|
|
|
|
Thanks.. I get it now.. U've all been of great help
Lazar Mihai
The road to becoming a good programmer is paved with bad scripts !
|
|
|
|
|
Hello,
I run the program below to handle winmessages from an application written in a 4GL. From within PaintExtras() I would like to call a function in the 4GL program to retrieve some properties (to be able to draw the icon on different positions f.e.). How can I do that? I can send the 4GL 's window-HWND to NotifyWindow in my C# program.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class GenericWindow : NativeWindow
{
public const int WM_ERASEBKGND = 0x14;
public const int WM_DESTROY = 0x0002;
private const int GWL_WNDPROC = -4;
private const int WM_SYNCPAINT = 0x0088;
private const int WM_NCPAINT = 0x0085;
private const int WM_PAINT = 0x000F;
private IntPtr oldWndProc = IntPtr.Zero;
private Win32WndProc newWndProc = null;
private int hIcon;
#region Imported User32.DLL functions
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static public extern int GetDC(int hWnd);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int ReleaseDC(int hWnd,int hDc);
[DllImport("User32.dll")]
private static extern int DestroyIcon(int hIcon);
[DllImport("user32.dll")]
public static extern int DrawIcon(int hdc, int x,int y, int hIcon);
[DllImport("user32.dll", EntryPoint="CallWindowProc")]
private static extern int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
public static extern int ExtractIcon(int hInst, string lpszExeFileName, int nIconIndex);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, Win32WndProc newProc);
[DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
#endregion
// A delegate that matches Win32 WNDPROC:
private delegate int Win32WndProc(IntPtr hWnd, int Msg, int wParam, int lParam);
public GenericWindow()
{
}
public void NotifyWindow(int windowHandle)
{
this.AssignHandle((IntPtr)windowHandle);
oldWndProc = GetWindowLong((IntPtr)windowHandle,GWL_WNDPROC);
newWndProc = new Win32WndProc(MyWndProc);
SetWindowLong((IntPtr)windowHandle, GWL_WNDPROC,newWndProc);
PaintExtras();
}
private int MyWndProc(IntPtr hWnd, int Msg, int
wParam, int lParam)
{
int pHandle;
switch(Msg)
{
case WM_PAINT:
pHandle = CallWindowProc(oldWndProc, hWnd,Msg, wParam, lParam);
PaintExtras();
return pHandle;
case WM_DESTROY:
pHandle = CallWindowProc(oldWndProc, hWnd,Msg, wParam, lParam);
//MessageBox.Show("dest");
return pHandle;
default:
return CallWindowProc(oldWndProc, hWnd, Msg,
wParam, lParam);
}
}
public void PaintExtras()
{
int hdc = GetDC(this.Handle.ToInt32());
if (hdc != 0)
{
hIcon = ExtractIcon(this.Handle.ToInt32(),"C:\\progress10\\wrk\\experim\\down.ico",0);
int ret = DrawIcon (hdc, 1, 1, hIcon);
ret = DestroyIcon (hIcon);
ret = ReleaseDC(this.Handle.ToInt32(),hdc);
}
}
}
}
regards,
Stefan.
|
|
|
|
|
Hi,
I read from this tutorial at codeproject
Question A:
http://www.codeproject.com/csharp/GsXPathTutorial.asp
regarding xpath.. but i try to apply in my situation, and can't get it work...
just say this is my xml file:
Device.xml
=========
<?xml version="1.0" encoding="utf-8"?>
<DeviceList xmlns="http://tempuri.org/Device.xsd">
<!-- Device 1 -->
<Device id="1">
<Connection>
<Type>Titan123</Type>
<Open />
<ConfigCard>
<Name>Titan Suprema</Name>
<Length>13</Length>
</ConfigCard>
</Connection>
</Device>
<Device id="2">
<Connection>
<Type>BBB Hardware</Type>
<Open />
<ConfigCard>
<Name>BBB DH</Name>
<Length>6</Length>
</ConfigCard>
</Connection>
</Device>
</DeviceList>
In my C# code,
string devicePath = Application.StartupPath + @"\device.xml";
// open XmlTextReader
...
int nMaxId = 0;
// get maximum devices within XML script
while(xmlDevice.Read())
{
if (xmlDevice.IsStartElement() && xmlDevice.Name == "Device")
{
int nId = Int32.Parse(xmlDevice.GetAttribute("id"));
if (nMaxId < nId)
nMaxId = nId;
}
}
}
// Execute XPath here
XPathDocument xdoc = new XPathDocument(devicePath);
XPathNavigator nav = xdoc.CreateNavigator();
// loop into 2 possible devices and extract particular information
for (int i = 1; i < nMaxId + 1; i++)
{
XPathNodeIterator nodeItor = nav.Select(
"DeviceList/Device[@id='" + i + "']/Connection");
nodeItor.MoveNext();
TraverseChildren(nodeItor);
}
...
// from the article
private void TraverseChildren(XPathNodeIterator nodeItor)
{
XPathNodeIterator igor = nodeItor.Clone();
igor.Current.MoveToFirstChild();
bool more = false;
do
{
PrintNode(igor.Current);
more = igor.Current.MoveToNext();
}while(more);
}
private void PrintNode(XPathNavigator nav)
{
MessageBox.Show("Value: " + nav.Value +
" Type : " + nav.NodeType.ToString());
}
From this solution:
i get this instead:
MessageBox1 - Value: Titan123 Titan Suprema 13BBB Hardware BBB DH 6
MessageBox2 - Value: Titan123 Titan Suprema 13BBB Hardware BBB DH 6
(repeat the same message - why?)
Any help please?
I want to get the Output of this:
MessageBox1 - Value: Titan123 Titan Suprema 13
MessageBox2 - Value: BBB Hardware BBB H 6
Question B:
By the way how can i get the value of individual Type example,
showing the output here:
Type - Titan123
Name - Titan Suprema
Length - 13
i always only manage to get the type which is "Name" and the whole message "Titan123 Titan Suprema 13" instead separate data.
Any help please? Thanks.
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
|
|
|
|
|
If you have a question about an article here on this site, then use the message board at the bottom of the article. That's what the article-specific message boards are for.
http://www.codeproject.com/csharp/GsXPathTutorial.asp[^]
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]
|
|
|
|
|
Hello
I want to make an application which will list down all the sites and directories present in IIS in C# application..i found code snippets for creation of site and Virtual Directories but didn`t find any example for viewing the hosted sites
is there anyway to achieve this goal?
Please Help me
-adnan
|
|
|
|
|
The APIs that those samples used are the very APIs (most likely) for enumerating virtual sites and directories. It's important to understand the scope and goal of the examples, not to simply copy and paste for the same functionality.
Since I don't know what examples you're talking about and since there's so many ways of creating, enumerating, and deleting virtual hosts and directories, I recommend using System.DirectoryServices to enumerate the iis:// namespace provider. See http://www.netomatix.com/EnumWebDirs.aspx[^] for an example.
This is the preferred way of accessing IIS information and is supported by many automation clients, including Windows Script (VBScript; JScript), Visual Basic 6 / VBA, and more. .NET supports this through the System.DirectoryServices namespace that I mentioned before.
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]
|
|
|
|
|
Thanks for reply,can you explain me about this syntax?
IIS://" + this.DomainName + "/W3SVC
i have oftened seem syntax like
IIS://" + this.DomainName + "/W3SVC/1
What`s the difference?
-adnan
|
|
|
|
|
If you search for "iis://" on http://msdn.microsoft.com/library[^] you can learn quite a bit about it.
this.DomainName is just what it sounds like - the domain name. Replace this with whatever computer you want to connect that is running IIS. The IIS Programmatic Administration Reference[^] - specifically for the IIS ADSI Provider[^] - descrbes that what comes after the computer name is the service to which you want to connect. "W3SVC" is the world-wide web (w3) service (svc). The number after that is the virtual host number (this is not necessarily serialized).
The first line enumerates all virtual hosts, while the second enumerates the first virtual host (or rather, the virtual host who's identifier is "1").
Read the links above for more 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]
|
|
|
|
|
Thanks i tried the code and it worked..however i want to know that is it possible to view all VirtualFolders and site at once?
i created a site in my IIS as "abc.com" and then i provided
path as IIS://abc.com/W3SVC/1/Root
but it gave RPC error
how can I do this?
Thanks
-adnan
|
|
|
|
|
If you read the documentation that I linked it explains how to enumerate all virtual sites. As I also mentioned, the site index (represented by the "1" in your URL above) is not a serial number and is seemingly random. This is why you must enumerate the sites first, then their services, then their applications and their directories, and so on.
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]
|
|
|
|
|
thanks for keep sending me replies..i was actually giving machine name as "localhost" though my Machine name is something else
one thing i didnt understand that what`s the different between "IISWebDirectory" and "IISVirualDirectory" i can understand Virtual directory which normaly is created under "localhost" website but what`s webdirectory?
-adnan
|
|
|
|
|