You're welcome. Sorry for the delay, I've been on vacation, RVing the Oregon Coast. It was really great. I'm not sure there is any generic "best" way, it depends on what you want to do with it. Keeping it in memory may help performance slightly, but the OS does enough caching that it's likely to have only a minimal effect in most cases, so I'd concentrate on what's most convienent from your application's standpoint to start. In many cases, I think about making a pass through a file, building an in-memory data structure from it's contents because I want to access it randomly (say by a persons's name) rather than sequentially. Good luck Burt Harris
Burt Harris
Posts
-
a better way? -
use pointers in c#Hello Ista, In C#, there are two kinds of types, value types and reference types. A very limited set of information fits into the value type category, for example int, and double. Most types, including string and all objects are reference types. Variables declared as reference types don't actually hold the underlying data, but instead have a reference to it, this is very much like pointer, but you don't have to use *. Several variables can hold references to the same object, copying from one variable (or collection) to another doesn't duplicate the underlying data, it just copies a pointer. In short, I don't think you need pointers, the standard collections should work the way you want. Burt Harris
-
a better way?Great, I'll try to add a few constructive comments: 1) Early on, you handle a null value for fstream by showing a message box, then returning a null from the GetIndex() function. Typically, in C# we handle that sort of unexpected condition by throwing a an exception, rather than returning null. Error handling can be done at higher levels with try/catch blocks. 2) I'm guessing you might be thinking the line
StreamReader fstreamCopy = fstream;
is copying the original StreamReader fstream, so that it's position won't be changed. It doesn't work that way, since StreamReader is a reference class, you assignment just creates an alternate name for the same object fstream referrs to. 3) At the bottom, you loop through the ArrayList to create a string array to return. There might be a better way to do this:tmpIndex.CopyTo( 0, indIndex, 0, tmpIndex.Count );
Burt Harris -
Pocket PC programming in C#I think you'll have to use P-invoke for sounds. The following code should get you started. I think it will port to PocketPC, but it may take a little work:
using System;
using System.Runtime.InteropServices;namespace ConsoleApplication1
{
class Class1
{
[ DllImport( "WinMM.dll" ) ]
private extern static void PlaySound(
string soundName,
int hModule,
int dwFlags );private const int SND\_FILENAME = 0x20000; /\* name is file name \*/ \[STAThread\] static void Main(string\[\] args) { PlaySound( "C:\\\\Windows\\\\Media\\\\ChatKick.wav", 0, SND\_FILENAME ); } }
}
Burt Harris
-
getting attribute values from AssemblyInfo.csI think those two attributes are converted into information in a version resource, and not retained as attributes. You should be able to access them via
FileVersionInfo.GetVersionInfo()
. Burt Harris -
How do I use WSAStartup() in C# ??I don't think there is a public declaration of the WSADATA structure in any namespace Microsoft provides. Typically, writing in managed code, you don't need to call WSAStartup directly, using code in the System.Net.Sockets namespace will take care of calling it automatically for you. Is there some reason System.Net.Sockets isn't doing what you want? Burt Harris
-
Windows Service And Custom DLLWhat I'd do is attach to the service with a debugger and trace thru it. I gather your C# service is an EXE, and it's connecting to a different C# DLL. Is the EXE built with a reference to the DLL, or are you trying to do something different? Do they exist in the same directory? One possibility is there is some problem locating the DLL. There's a tool called FUSLOGVW that helps in tracking this sort of thing. Another thing to check is what account the service is running under. Some accounts, like the XP local and network service accounts have enough privilidge to write to an existing event log source, but not enough to create a new source. Creating of the new source typically happens at installation time. Hope some of that helps you. Burt Harris
-
Windows Service InstallationOK, I think I can help with this one. In the Solution Explorer, select your deployment project and press "Custom Actions Editor" icon near the top of the Solution Explorer. In the Custom Actions window, select the root node, "Custom Actions". Right-click and choose "Add custom action..." Select the file that you normally run InstallUtil on as the custom action. This will have an effect like running InstallUtil during setup, and do the right think at uninstall time too. Burt Harris
-
Design question about windows services...You need to wait in your OnStop function until your service has finished shutting down. You might do this with a ManualResetEvent like this:
ManualResetEvent done = new ManualResetEvent(false); protected override void OnStop() { // Tell your service to shut down done.WaitOne(); }
Then in your other routine, running on the other thread, just calldone.Set();
when you are all done, just before returning. Burt Harris -
GUI for desktop applicationYou may find some free components to snazz-up your U/I at http://www.sellsbrothers.com/tools/genghis/ Burt Harris
-
Setting environment variables from installer?The Windows Installer Environment table has a good solution for setting environment variables, but unfortunately the Visual Studio deployments projects don't give you a way to author entries in the appropriate table. You'll have to use some other tool to author that part of your setup. If you've got money to spend, there are several more sophisticated setup packages that give you a GUI authoring tool and access to this. I've also done things like this by using the Orca tool (part of the Windows Installer SDK portion of the Platform SDK) to create a merge module (.MSM file) which I include into a setup otherwise authored in Visual Studio's deployment project tool. This will take you more learning & effort, but it's a free download Burt Harris
-
RSA File EncryptionRSA encryption is typically not used for bulk encryption, like a whole file. Instead what would typically be done would be done is to use a symmetrical-key encryption (like DES, RC-2 or RC-4) to using a randomly selected key, then encrypt this key using RSA so that it can be sent along with the encrypted file. This might be a good starting point for you: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/security/cryptographic_keys.asp Burt Harris
-
"out keyword" in COM interopYou probably just need to add the "out" keyword to your function call, just before the variable name.
void foo( YourComObject com ) { object o; com.GetXyz( out o ); ... }
Burt Harris -
TypeBuilder Problems in My Compiler.Hmm, TypeBuilder itself is derrived from Type, perhaps that's what you need. I also see the following remark in the documentation for TypeBuilder: To retrieve a Type object for an incomplete type, use ModuleBuilder.GetType with a string representing the type name, such as "MyType" or "MyType[]". Burt Harris
-
Array of HashesSounds like your trying to apply Perl design to a C# program. Before you go too far, you should first try to understand the database access classes in the System.Data namespace. A DataTable acts a lot like an array of DataRows, where individual fields can be accessed by name. But if you really want something like a perl array of hashes, it might look like this:
using System.Collections; ... ArrayList a = new ArrayList(); Hashtable h = new Hashtable(); h.Add( "One", 1 ); h.Add( "Two", 2 ); a.Add( h ); // Later h = (Hashtable)a[0]; Console.WriteLine( h["One"] );
Burt Harris
-
Question About SocketsHello Jesse, You are trying to call BeginReceive on the wrong socket. The socket you set up with the Listen() and BeginAccept() requests will simply deliver callbacks to you when clients attempt to connect. In your AcceptCallBack function, you must call EndAccept(), which will return to you a new socket connected to that client. You would then call BeginReceive() on that new socket. Also, in your Receiver() function, you should use this new socket to call EndReceive() on. The return value from this is the number of bytes you actually received (which may be smaller than you requested.) Note also that if something goes wrong with the network connection, the EndReceive() function will throw an exception, you should be prepaired to handle that. Hope that helps. Burt Harris
-
Very very annoyingI'm not aware of such a feature in VS 2003, though I'm not on the VS team. I've tried reproducing it on Windows XP Professional Service Pack 1, and I'm not seeing the behavior you are describing. I've tried both while in design mode and debugging. I'm just guessing, but this sounds like it might be more related to OS version or settings than VS itself. For example, a potentailly related issue oddity in Windows 2000 Professional is described in http://support.microsoft.com/default.aspx?scid=kb;en-us;262088 [^] Burt Harris
-
Hide source codeTake a look at http://www.preemptive.com[^], they provide the technology integrated into VS 2003. Burt Harris
-
Outlining #regionI tend to use keyboard shortcuts to manipulate outlining. Ctrl+M,Ctrl+P is a quick way to turn outlining, but it's not "permanant". Tools\Options\Text Editor\C#\Formatting can change the defaults when a file is opened. (At least on VS 2003, not sure about 2002). Burt Harris
-
Creating ActiveX Control Using .NET???Not all ActiveX controls are going to be usable in InternetExplorer. Generally speaking, this is for security reasons: HTML pages from evil web sites might be able to perform nasty operations through the controls. Here's a link to an article that might help clarify: http://msdn.microsoft.com/library/default.asp?url=/workshop/components/activex/safety.asp[^] Burt Harris