|
Use a database I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Anticast wrote: The MSDN talks about user settings, but it says that they're saved to a user.config file, and it says that application settings can only be modified at design-time.
If they(MSDN) say you can only do it at design time they are wright. Here's why. Because altering the
data in a *.exe is dangerous. It is a compiled file so you can only add stuff at compile/design time.
So no I don't think there is.
As for a workaround I would create a binary file and store the byte[] for the object be it picture or whaterver in there. Or in a light weight DB such as SQLite or even a *.mdb file and store it in a byte or OLE Object for the *.mdb.
Just an ideea. Sure others have better ones. You just have to keep looking.
|
|
|
|
|
There is a way, it is complex and I haven't done so yet. Here is the gist of it:
- (first) exe holds executable code for second exe as a resource;
- first exe creates said second exe, launches it and exits;
- second exe modifies first exe, then launches it;
- first exe deletes second exe.
I don't think anything is worth all this trouble.
|
|
|
|
|
wouldn't this be a chain reaction?
|
|
|
|
|
if need be, use the control rods, aka Task Manager.
|
|
|
|
|
The short version is no, you can't.
The long version is yes, but only if you know EXACTLY what you are doing, the structure of an .EXE, how to update the various tables with new offsets, yada, yada, yada, ... and hope while you're doing this, that your app doesn't crash or the system doesn't hang, or the power doesn't fail, in the middle of writing the data to the .EXE file.
|
|
|
|
|
Okay, thanks everyone for your input!
|
|
|
|
|
You could save it in a resource file. The requirement is kinda strange, though..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
You have two options. I'll describe them in different posts so you don't get confused. This first post will be for the simpler option.
First, add a resource (say, a string) to your application like your normall would, at design time. Only, make sure the resource is as large as the largest list you expect to embed in the EXE. Make sure the beginning and end of the string has unique data that is not likely to appear randomly in the rest of the EXE. When you compile it, open the EXE in a hex editor and find the unique parts of the string. Make note of the beginning and end of the string in the EXE.
Modify the string in the EXE (using the hex editor) so that the first part of the string that is not being used up by the unique string at the beginning of the string contains a number: the index into the EXE the string is embedded. That way, at runtime, you can parse the string and find out where it is located in the EXE. You can then have the EXE copy itself to a new file and have it modify the new EXE to contain the new data in the string resource (after the number that indicates the byte position of the string in the EXE). You then have the old EXE run the new EXE and close itself... the new EXE will then presumably clean up the old EXE by deleting it. If you want, the new EXE could then copy itself to where the old EXE used to be and then run the newer EXE, which will then delete the new EXE. You can use a counter parameter to keep track of how many EXE's you are into the process.
Also, since the resource string is a constant length, but the data it contains is variable length, you'll either want to delimit the end of the actual resource data, or create another number in the beginning of the resource string that indicates the length of the data.
|
|
|
|
|
Now that you know the simple way, I'll describe the harder way.
First, you use the ResourceWriter class to create a resource out of the data you want to be embedded in the EXE.
Next, you use the C# compiler to embed that resource file into an assembly (the assembly is created from some C# code, so you can't just embed it in your primary assembly straight away). What is in the assembly is unimportant, as it will be ignored (you only want the assembly so you can have an assembly with a resource file embedded in it).
Next, you can use ILMerge to combine the assembly you just created with your main assembly.
You can then load that resource at runtime.
Those are most of the tools you'll need to accomplish this task. However, there are a few points you'll need to consider.
For one, you don't want multiple EXE's, so you'll want to make sure to embed the above tools into your main assembly (CSC and ILMerge). To run them, you'd then extract them to a file, run them, then delete them when you are done running them.
Next, combining the generated assembly with your main assembly will increase the size of the main assembly. To prevent it from increasing in size each time you run it, you'll wan to first compile the assembly and then add the assembly as a resource for itself. When you merge the main assembly with the generated one, you'll actually add the main assembly to the resource file you generate, then compile that resource file into a new assembly, then merge that generated assembly with the assembly you export from your resources.
The above ResourceWriter only works with strings. So, when you want to embed EXE's (aka byte arrays) and images and such, you'll need to embed them as strings. That means you'll have to do some parsing and deserializing.
You will have to do some switching of EXE's (i.e., delete the old one and run the new one) as I described in the "simple way" in my previous post.
|
|
|
|
|
Thank you for the detailed responses! I think I'll give your "Simple Way" a shot since I'm already doing most of that stuff anyway and I can make it work with a fixed string length.
Thank you very much!
|
|
|
|
|
I've been looking through some code with the Reflector, and I've kept seeing things like if (this <= null) and if (obj > null) etc
In MSIL the code was this:
L_0001: ldarg.0
L_0002: ldnull
L_0003: cgt.un
Well huh? What is going on here? What is it supposed to do? Is it just a weird way to check whether something is null ? But then why check this ?
The code looks as if it was produced by an F# compiler. Is it just that the F# compiler is being lame?
|
|
|
|
|
I don't know about F# but in C# the (this <= null) doesn't compile.
So yeah I guess the F# compiler is a little wierd.
|
|
|
|
|
Hi,
I am reading a text file successfully with the code below but the result is rounding down instead of rounding up I have tried to use Math.Ceiling to resolve this issue and have now come unstuck. Appreciate the help.
[Description("Displays Levels")]
public class MyCustomIndicator2 : Indicator
{
#region Variables
private string path = Cbi.Core.UserDataDir.ToString() + "PIn.txt";
private int[] levels;
private int count = 0;
private string readText = "";
private int roundedValue;
private int diff = int.MaxValue;
private int tmp, res = 0;
#endregion
protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
levels = new int[100000];
}
protected override void OnBarUpdate()
{
readText = File.ReadAllText("C:\\PIn.txt");
int roundedValue = ((int)Math.Ceiling(Close[0]));
string [] split = readText.Split(new Char [] {';'});
foreach (string s in split)
{
count++;
tmp = int.Parse(s);
levels[count] = tmp;
if (tmp > roundedValue)
{
if(diff == null)
diff = roundedValue;
if ((tmp - roundedValue) < diff)
{
res = tmp;
diff = tmp - roundedValue;
}
}
}
Print(res);
}
#region Properties
#endregion
}
}
Regards,
suprsnipes
|
|
|
|
|
The relevant code is missing - what is Close and how is it filled?
|
|
|
|
|
I have just tried your code and it finds the smallest number greater than X, where X is a float that I invented. Check your values to see where the discrepancy is. I also think the statement(s)
if(diff == null)
diff = roundedValue;
should read
if(diff == 0)
diff = roundedValue; txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
"If you have to include code, include the smallest snippet of code you can."
You really should only need to include
int roundedValue = ((int)Math.Ceiling(Close[0]));
and tell us the input and output values.
|
|
|
|
|
Hi again,
3.
if(diff == null) diff = roundedValue; is redundant (assuming it would compile, which it won't)
4.
levels = new int[100000]; will make it fail for a file with > 100000 numbers.
|
|
|
|
|
Luc Pattyn wrote: if(diff == null) diff = roundedValue; is redundant (assuming it would compile, which it won't)
Hm, it compiles fine on VC# Express 2008, just gives a warnimg that the expression always evaluates to false .txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Indeed, it does. But it shouldn't, as the types are incompatible and the equality test is doomed to fail.
|
|
|
|
|
You're right of course, so why does my compiler allow it, even at warning level 4? Now my program won't work, and yet the error is not obvious. I wonder if this happens in the full Visual Studio version? txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Richard MacCutchan wrote: I wonder if this happens in the full Visual Studio version?
I don't know, yet I am unaware of any difference, other than functionality, between them. I also assume it is the same csc.exe compiler after all (which is part of .NET, not of VS).
|
|
|
|
|
When you say you've tried using Math.Ceiling to resolve the issue, what were you using before? Some rounding functions use the acccountacy standard, where odd number round up and even round down (or the other way round) - is that what you were experiencing?Regards,
Rob Philpott.
|
|
|
|
|
Hi,
Yes but the code doesn't appear to do what I intended. I had to change the code because I was trying to compare an int to a double and when I made the appropriate changes the output was incorrect.
I then looked into trying to achieve what I require another way. I have managed to get the text document into a list and now need to create a loop function to compare the double value of Close[0] to find the nearest value within the list above the Close[0] which is what I have been researching today.
As a newbie I apologise for not having a very good understanding of C# but I'm having a crack and I'm sure as time goes by I will be better equipped.
Appreciate the help,
suprsnipes
|
|
|
|
|
I am try to Implement a graphical Password system .Can anyone help me with writing C# to implement Robust Discretization.
|
|
|
|