|
Correct, now WHY?
The return value is not being set. You were supposed to work that one out.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Dude, yer spittin' into the wind. All that's gonna happen is you'll end up with spit all over yourself. Nothing else will change.
We are CodeProject of Borg. Assistance is futile.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
I know. I like to help, I really do. The problem is, well you know EXACTLY what the problem is.
So I've resolved to trying to prod them in the right direction. Using an electrified cattle stick. As the average intelligence comes out around duckweed, one has to derive what little pleasure is available.
In other news, it is now afternoon here and the Gin should be kickiing in around about now.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Dumbest mistake I've seen all day.
What happens when you use a function which is not a void?
The function has to return something eg:
private bool rawr()
{
bool returnObject = false;
...
return returnObject;
}
It's not rocket science it just common sense!
hmmm pie
modified on Saturday, March 14, 2009 6:56 AM
|
|
|
|
|
Thanks everyone!
finally code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program app = new Program();
Console.ReadLine();
}
Program()
{
bool ok = false;
double[] w = new double[25];
double[] l = new double[25];
double[] u = new double[25];
double[] z = new double[25];
double ft = 0.0, fx = 0.0, alpha = 0.0, h = 0.0, k = 0.0, vv = 0.0, t = 0.0, x = 0.0;
int n = 0, m = 0, m1 = 0, m2 = 0, n1 = 0, flag = 0, i1 = 0, i = 0, j = 0;
input(ref ok, ref fx, ref ft, ref alpha, ref n, ref m);
if (ok)
{
m1 = m - 1;
m2 = m - 2;
h = fx / m;
k = ft / n;
vv = alpha * k / (h * h);
for (i = 1; i <= m1; i++) w[i - 1] = F(i * h);
l[0] = 1.0 - 2.0 * vv;
u[0] = vv / l[0];
for (i = 2; i <= m2; i++)
{
l[i - 1] = 1.0 - 2.0 * vv - vv * u[i - 2];
u[i - 1] = vv / l[i - 1];
}
l[m1 - 1] = 1.0 - 2.0 * vv - vv * u[m2 - 1];
for (j = 1; j <= n; j++)
{
z[0] = w[0] / l[0];
for (i = 2; i <= m1; i++)
z[i - 1] = (w[i - 1] - vv * z[i - 2]) / l[i - 1];
w[m1 - 1] = z[m1 - 1];
for (i1 = 1; i1 <= m2; i1++)
{
i = m2 - i1 + 1;
w[i - 1] = z[i - 1] - u[i - 1] * w[i];
}
}
output(ft, x, m1, ref w, h);
}
}
private double F(double X)
{
double f;
f = 0.3061 * X * X - 2.1286 * X + 38.11;
return f;
}
private void input(ref bool ok, ref double fx, ref double ft, ref double alpha, ref int n, ref int m)
{
try
{
FileStream fs = new FileStream("D:\\1.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);
string[] lines = new string[10];
string line;
int i = 0;
while ((line = sr.ReadLine()) != null)
{
lines[i++] = (line);
}
fx = double.Parse(lines[0]);
ft = double.Parse(lines[1]);
alpha = double.Parse(lines[2]);
m = Int32.Parse(lines[3]);
n = Int32.Parse(lines[4]);
}
catch (Exception e)
{
Console.WriteLine("Exception in ShowFile: {0}", e);
}
ok = true;
}
public void output(double ft, double x, int m1, ref double[] w, double h)
{
System.IO.StreamWriter oup;
System.IO.TextWriter tmp = Console.Out;
Console.WriteLine("Choice of output method.");
Console.WriteLine("1. Output to screen");
Console.WriteLine("2. Output to text file");
int flag = Convert.ToInt32(Console.ReadLine());
if (flag == 2)
{
Console.WriteLine("Sample: C:\\Data\\1.txt");
string name = Console.ReadLine();
try
{
name = name.Replace(@"\", @"\\");
oup = new System.IO.StreamWriter(name);
Console.SetOut(oup);
write(ft, x, m1, ref w, h);
oup.Close();
}
catch (System.IO.IOException expc)
{
Console.WriteLine(expc.Message + " file dont extract.");
}
}
else
{
write(ft, x, m1, ref w, h);
}
}
private void write(double ft, double x, int m1, ref double[] w, double h)
{
Console.WriteLine("I\tX(I)\tW(X(I),{0:#.#})", ft);
for (int i = 1; i <= m1; i++)
{
x = i * h;
Console.WriteLine("{0:#.##}\t{1:#.###}\t\t{2:#.###}", i, x, w[i - 1]);
}
}
}
}
|
|
|
|
|
You really don't need to post the code every frakking time you put up a message.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
Calm down, Chris has just ordered a couple of extra 250 TB dirve racks for when the next term starts.
And now sport, Gin 3 Tonic 2. Gin goes onto to meet Liver in the next round.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi,
I'm trying to write a service that runs only in safe mode,
for that i need to figure out if I'm in safe mode or not,
how do i do that in c# ? (i cant use System.Windows.Forms.SystemInformation.BootMode since i'm in a service and no forms)
Thanks
Aviad.
|
|
|
|
|
aviadqwerty wrote: i cant use System.Windows.Forms.SystemInformation.BootMode since i'm in a service
I doubt that. Why would it be impossible to add a reference to ths System.Windows.Forms DLL and use the SystemInformation.BootMode enum? you don't need a GUI to do that. Have you tried it, what happened?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hello! I am following this guide about switching background wallpaper via a windows service http://www.codeproject.com/KB/cs/C__Wallpaper_Switcher.aspx[^] but cant get it right.
My service is up and running (it do other things så of that I am certain) but the background wont just change. If I try exactly the same code in a win form app it works (and SystemParametersInfo returns 1) but not in my service (SystemParametersInfo returns 0). Has Vista something to do with it, security limitations? Is it posible to get better error messages from SystemParametersInfo?
|
|
|
|
|
Don't ask here, it's not our code. Any qiestion regarding an article should be posted on the article. It's really quite a clever idea - you ask the person who wrote it why you're having a problem.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Well then maybe I can change my question a bit? Regardless of the article, how do I change the background image within a windows service? I have search the web for hours now and all code are variations of the code as shown in the article (pretty much c# to me and this is a c# forum, right?)...
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, String pvParam, UInt32 fWinIni);
private static UInt32 SPI_SETDESKWALLPAPER = 20;
private static UInt32 SPIF_UPDATEINIFILE = 0x1;
/.../
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, @"C:\...\test.bmp", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
Works perfectly in win forms in vista but not in my service of some reason.
|
|
|
|
|
It's a service. You shouldn't be able to access the UI from a service.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
It won't work in a service because the service is running under a different account and Desktop. You're actually changing the wallpaper for a desktop that you cannot see.
This should not be done from a service at all. This should be a user app launched from the Run key in the registry. Wallpaper setting a user specific, not machine specific. This means that every user can have their own wallpaper, without affecting other users.
|
|
|
|
|
Ok, thanks. I did find a "half workaround". It is possible to change the wallpaper registry key with the standard service account. Not directly in HKEY_CURRENT_USER but in HKEY_USER. And hkey_current_user is in fact only a copy of one of thoose in the hkey_users, just find the right one (the one with write permissions is the same as hkey_current_user so just loop them through an try them out...)
Changing the wallpaper key only applies when the computer is restarted, but it was quite fun anyway. The image has to be find locally but if removed, I made my service download the correct image aswell...
RegistryKey Keys = Registry.Users;
foreach (string Keyname in Keys.GetSubKeyNames())
{
try
{
RegistryKey Key = Registry.Users.OpenSubKey(Keyname.ToString() + "\\Control Panel\\Desktop", true);
Key.SetValue("WallPaper", "C:\\Users\\" + UsersDir + "\\Desktop\\funny.jpg", RegistryValueKind.String);
}
catch { }
}
Not very serious project maybe but I've learned alot on the way.
|
|
|
|
|
CURRENT_USER is a pointer to the correct user hive under USERS, not a copy of it.
maxald wrote: just find the right one (the one with write permissions is the same as hkey_current_user so just loop them through an try them out...)
This is wrong. Services run, by default, as the Local System account, not a user account. They also don't normally have any idea anyone is logged in, if at all. The fact that the service found A user have that it could write to is mearly a coinicedence. It did not find THE known user account, unless you've written code to try and figure out which user that is.
|
|
|
|
|
Thanks for clearing things out, I'm all new to programming so I really appreciate that!
I find one other thing on this subject... when looping trough all user folders in c:\Users within my service, it has write permissions only in the logged in user folder. Is this a coinicedence aswell or could this be part of a solution finding who is the logged in user?
|
|
|
|
|
It's the exact same situation. It cannot be relied upon to determine who is logged in, if anyone. Also, since XP/Vista/7 can have multiple people logged in at the same time, who's the one at the console?? There's no way to tell. Also, it's not just a user account that's logged in. There are also built-in accounts that are being used, such as Local System, Network Service, Local Service, ... Are you going to needlessly attempt to change those accounts too??
That's why I said the best place to use this would be a user app launched out of the Registry's Run key, not a service. That way, the app runs as the user, only when a user is logged in, and doesn't have to worry about figuring out who's logged in.
|
|
|
|
|
hi friends,
i downloaded inpout32.dll file and included to my resource file.
i get the following error
'C:\WINDOWS\INPOUT32.DLL' is not a valid Win32 resource file
wat should i do now?
cheers,
priya
|
|
|
|
|
Have you Googled it?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
hi friend
I'm new to programming i don no how to do it
|
|
|
|
|
he meant Google
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Well, I would start by getting a good book on the programming language you are trying to learn. Importing and using DLLs is not exactly a step after Hello World.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
I suppose by "importing a dll file" you mean that you want to use that Dll in your application. In order to do that you need to reference the Dll in your build (if the Dll is a .NET Dll) or you need to load specific functions from the Dll via P/Invoke (if it is a native - that is non .NET Dll).
Either way I suggest you look for a Dll tutorial if you are new to this.
You should be able to find information on Codeproject searching for P/Invoke (short for Platform Invoke) or looking for some basic C# tutorials which probably also explain usage of Dlls.
|
|
|
|
|
Hi All,
I have .Prn file which was generated out of PCL printer.I need to find a string in that file and then I have to replace it with another string.
Iam able to do it by using stream writer,streamreader,Binary reader,binary writer and file streams.
But if gave a print(LPR)for it, it get failed and giving me syntax error as Illegal tag.
If I print original file it is printing very well.
I came to know that while writing it has lost some of its originality ,so it was failed
Please help me
Thanks in advance
|
|
|
|
|