EventLog evtLog = new EventLog();
evtLog.Source = "TestSource";
evtLog.WriteEntry("This is a test", EventLogEntryType.Information);
I now decide to use my own custom log so I change "System" to "TestLog".
This doesn't do anything. The event is still logged to the "System" log even if I try deleting the source but if I use a different source, it then gets logged correctly to "TestLog"
If I go into the registry, I find a list of sources for the System event log but even if I delete the TestSource entry from there it still logs events to the System event log.
This MSDN article suggests that you can remove a source association from a log but it's not correct as far as I can tell:
I want derived class to automatically call a particular base class method BEFORE "return" statement, how can I do that?
class SomeDerived : SomeBase <br />
public SomeDerived() << Constructor called *After* SomeBase's constructor is invoked<br />
SomeMethod(); << This is what I plan to do, but I don't want burden of invoking thisbaseclass method to resides on Derived class (and at same time I can't put this on base class constructor because this must wait till Derived class finishes before invoking)<br />
class SomeBase<br />
You can't make it do it automatically. With MFC, you could use PostMessage, which would then cause the message to be sent when the current method had ended, but I don't believe C# supports anything like that, nor am I sure what would happen if you p/invoked PostMessage.
You can't do that. But why would you want to do it anyway? It's against OO principles, and the solution you pointed out is perfectly valid. Everything else would make things much more complicated, obfuscated, and error-prone...
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
What you should do is use the GCHandle class to pin objects (so the GC won't move them around),
then obtain their address, pass that as an IntPtr, and afterwards free the handle.
You don't need to do this for strings though: a read-only string can be passed as is, and your C code will get a valid char*. For a writable string, use a StringBuilder instead.
Make sure you describe the structs correctly; be careful with the size of simple types,
long in C# is 64-bit, in most C environments it is 32-bit; and char in C# is 16-bit, in C it is 8-bit. Also be careful with alignment, the byte stuffing rules could be different on both sides.