|
Thanks, I'll look into these causes and hopefully find the reasons.
I didn't mean to exclude anybody else, I just couldn't think of any other VIP names right offhand. I wanted a straightforward, and knowledgeable answer on this question, and I knew I'd get it if you answered. I appreciate the help!
- D
|
|
|
|
|
Hello people, I know that System.Security.Cryptography is a good way to protect data but now I have another problem. How to protect my private key? I can't leave may key on EXE or DLL's becaus C# is an easy way for reverse engeneering... I don't just said easy but... SO VERY MUCH EASY A LOT (lol)... What can I do to protect this?
Wender Oliveira
.NET Programmer
|
|
|
|
|
You wouldn't distribute your private key anyway. That's always bad no matter what you're doing.
If you're looking for a way to verify data, you'll want to use digital signatures. This allows you to distribute your public key (it's public, so it doesn't really matter*) and verify the signature of the signed data (it's a digest of the signed data encrypted with your private key; RSA and DSA implement this differently).
While my article probably isn't what you're looking for, read Using XML Digital Signatures for Application Licensing[^] for a good conceptual overview.
If you need to encrypt data, it's often best you use services provided by the OS. If you'll always run on Windows, read How To Create a DPAPI Library[^] on MSDN. This is a handy API for storing encrypted credentials, and is used by Passport (at least the local implementation that MSN and Windows Messengers use as well as IE for web sites). It's also very customizable and does most of the work for you.
If you want to implement your own encryption, generate a key pair on the machine after the app's installed. Store that in a key container. This method is fool proof, but not cryptoanalyst proof.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i was under the impression that ANY time a control is accessed by a thread that didn't create the control, the call has to be marshaled to the creating thread, and .NET provides this by returning TRUE from Invoke.Required, and then using Invoke() passing it a delegate. many times i find myself forgetting to do this, and am reminded with mysterious crashes when the control is accessed from another thread. other times i forget, i am not reminded because it seems to work fine, which doesn't make sense to me. i stepped through code and confirmed that another (non-creating) thread was writing to a RichTextBox without a problem. my question is, why is this? is it just the richTExtBox that can be accessed from another thread?
|
|
|
|
|
You can call Control.Invoke, .BeginInvoke, .EndInvoke, .CreateGraphics on any thread you please.
The RTB will blow up on you eventually, though, I've seen it several times.
#include "witty_sig.h"
|
|
|
|
|
A flaw in .NET 1.x, which has been corrected in 2.0 beta so far. In fact you will get the following error image in Visual Studio 2005 when you try to perform such an act.
Threading Error[^]
- Nick Parker My Blog | My Articles
|
|
|
|
|
|
Heath Stewart wrote:
Been coding with threads improperly, have we Nick?
Nope, just testing things out to see the difference in 2.0, isn't that what every developer is doing??
Heath Stewart wrote:
I certainly hope they fix the escaped character problem, though!
I'm not aware of what your talking about, can you expand?
- Nick Parker My Blog | My Articles
|
|
|
|
|
Nick Parker wrote:
isn't that what every developer is doing??
No, I just compiled a simple app with one line: DoesEverything.TestAllNewAPIs() . Didn't you?
Nick Parker wrote:
I'm not aware of what your talking about, can you expand?
Expand! Excellent choice of words, and very relevent!
Look at the text in the screenshot. You'll see a lot of \r\n. They should be expanded (see what I mean) to the actual characters that they represent (0x10 and 0x13), not displayed in the text.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
"illegal operation occurred was:\r\n\r\n\tat"
#include "witty_sig.h"
|
|
|
|
|
Is it always a good idea to use Control.Invoke and Control.InvokeRequired ? Yes. Most definitely.
Is it always necessary? Not always.
Some things will work, but could possibly cause problems down the road. It's always a good idea to use the ISynchronizeInvoke implementation when you know that other threads will be updating controls, but you may not always see problems if you don't. This really comes down to the differences between PostMessage and SendMessage (native APIs) that are used internally (and some times you just get lucky).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm facing the following problem in trying to code a DSP application in C#.
I need to create an array of objects of a class "cBiquad" using its default constructor.
The number of cBiquad objects is "mnNumBiquads".
How do I do this?
I tried the following:
int mnNumBiquads = (mnOrder + 1)/2;
int[] Biquad = new int[mnNumBiquads];
for (int i = 0; i < mnNumBiquads; i++)
{
Biquad[i] = new cBiquad();
}
However, this gives me the obvious error of not being able to implicitly convert cBiquad to int.
Could somebody suggest what I could do?
|
|
|
|
|
crushinghellhammer wrote:
Could somebody suggest what I could do?
int size = 10;
cBiquad[] cba = new cBiquad[size];
for(int i = 0; i < size; i++)
cba[i] = new cBiquad();
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thanks, Nick. I *just* figured out myself, as well.
cBiquad[] arrBiquads = new cBiquad[mnNumBiquads];
for (int i = 0; i < mnNumBiquads; i++)
{
arrBiquads[i] = new cBiquad(); }
Is there a more elegant way of doing this, as in instantiating the array in just one line, using the default cBiquad constructor.
I mean:
cBiquad[] arrBiquads = something...
|
|
|
|
|
crushinghellhammer wrote:
Is there a more elegant way of doing this
Nope, that's about it. You could write a class factory of sorts that would take care of this for you, depending on what you are doing that may be overhead.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi,
I'm trying to get a custom control to render its contents into a bitmap by sending it a WM_PRINT message. This works great if XP themes are not enabled. If XP themes are enabled, some controls (textbox, listview, listbox, treeview, datetimepicker) forget how to draw a themed border and draw an unthemed 3d border instead - and the groupbox only draws its background
Any ideas on how to get round this?
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
First, don't handle the WM_PAINT message. Override OnPaint for your controls (unless you're using an IMessageFilter or something) and use Control.SetStyle with the ControlStyles enumeration (read the .NET Framework SDK documentation for details) to control exactly what gets drawn.
If you don't want this code to run on Windows XP, use the Environment.Version property to determine on what platform and version of the OS the environment (the CLR) is running. Use that as a condition to executing certain code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a number of controls that are interacted with using mouse events. These work fine until the area they are in is scrollable, then, because they are tied to the screen location rather than the parent client area location, they don't function properly.
How would I calculate the location in relation to the parent instead?
Seems like a simple thing, but i'm mildly confused by it.
Regards
Cata
|
|
|
|
|
|
Thanks Nick, but that didn't solve the problem.
I tried point to client using the parent panel calling the method using the screen point taken from the control. This works the same as before however.
The problem I have is with scrolling. The client area remains the same, even if the client area has been scrolled down or across. This means that the information I am getting is still out of sync with the display. I can't find a way to get the X and Y values of the scrollable client.
I.e. if i scroll halfway down both X + Y axis, it still tells me I'm clicking on coordinates {300, 375}, when it should say i'm on {5300,5375}.
Any other ideas?
Cata
|
|
|
|
|
Hi,
I want to update both the contents and the checked state of items in a CheckedListBox on the ItemCheck event. It turns out that when removing an item that occurs before the checked item (the one that is being processed), both this checked item and the one after it will appear to be checked after the event finishes. To illustrate, here is some code that first populates a CheckedListBox with a sequence of integers (named checkedListBox), and then when an item is checked, removes this item, and also checks the previous item if it was even, or the following item if it was odd.
private void checkedListBox_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
// get the currently checked index
int checkedItemIndex = (int)checkedListBox.Items[checkedListBox.SelectedIndex];
bool checkedEven = checkedItemIndex % 2 == 0 ? true : false;
// remove the event handler for now - it is triggered by SetItemCheckState
checkedListBox.ItemCheck -= new ItemCheckEventHandler(checkedListBox_ItemCheck);
// if it was an even number, check the previous index
// ie - checking 4 will result in 3 being checked
// else, check the following index
// ie - checking 5 will result in 6 being checked
if (checkedItemIndex > 1 && checkedEven)
checkedListBox.SetItemCheckState(checkedItemIndex - 1, CheckState.Checked);
else if (checkedItemIndex < checkedListBox.Items.Count - 1)
checkedListBox.SetItemCheckState(checkedItemIndex, CheckState.Checked);
checkedListBox.ItemCheck += new ItemCheckEventHandler(checkedListBox_ItemCheck);
// remove the currently clicked index
checkedListBox.Items.RemoveAt(checkedItemIndex);
}
// here is the code to populate the box
private void resetListBoxContents()
{
checkedListBox.Items.Clear();
for (int i=0; i < 20; i++)
checkedListBox.Items.Add(i);
}
As you see, when checking 9, 9 is removed and 10 is checked. But when 4 is checked and removed, 3 becomes checked, as it should be, but so is 5, which should not be.
Any help in this matter would be greatly appreciated. Thanks!
|
|
|
|
|
Just a question, what is the purpose of having the check box if the item disappears as soon as you click on it?
- Nick Parker My Blog | My Articles
|
|
|
|
|
In actual use, probably none - I've only used to illustrate the problem I've been having. In the real implemenation, I'm removing entries from the box which are mutually exclusive with the checked item.
The problem seems to be that the check gets set after the event has finished, and instead of applying it to the clicked item (which may have moved in this case), it checks the index of where that item originally was. Does this make sense?
Perhaps there is another control I can use to facilatate this behavior?
|
|
|
|
|
Found the solution - when editing the state of the currently checked item, do so through the ItemCheckEventArgs parameter. Easy fix.
|
|
|
|
|
I am writing a custom grid, inherited from datagrid. I use data-binding to populate grid from an ArrayList.
When I click the column header, I am capturing the click and sorting the arraylist and re assign the data source to populate grid with sorted data.
My problem is, I do not get the sort arrow in the column header. How can get this?
Thanks in advance.
- TOJO
|
|
|
|