|
Add some exception handling to your code around the PInvoke calls and write to the error log in the catch blocks and you will be able to tell exactly what the problem is.
If it's a permission issue then you may need to specify a user to run the service as by setting the System.ServiceProcess.ServiceAccount[^]Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
The methods im invoking are GetAsyncKeyState, GetWindowText, and GetForegroundWindow, all of which return values. No exceptions are being thrown when i invoke, only when i run my app as a service they return a value of 0 (since all return either ints, shorts, or intptrs). Obviously the methods aren't being called for some reason. One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
-Robert Firth
|
|
|
|
|
jacobjordan wrote: GetWindowText, and GetForegroundWindow
those are GUI functions, your service by default has no user and no desktop, hence no GUI.
You must tell it somehow to allow user interaction and specify the account type. I don't know the details.
|
|
|
|
|
As Luc said, these are GUI functions. As the service isn't using the logged in user(s) desktop(s) these functions will not suceed or will fail gracefuly.
Why does this need to be a service? An app minimized to the tray would be able to do the job perfectly.Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I need to have it running no matter who is logged on, or if nobody is logged on. I know there are probably other ways of doing that, but creating a service was the first thing that came to mind. I would love it if you could suggest and easier way. One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
-Robert Firth
|
|
|
|
|
I see your logic for a service but services are non GUI in the sense that they have no UI of their own and can't (since Vista) interact directly with a user's UI.
jacobjordan wrote: or if nobody is logged on
That makes no sense as those calls will be useless.
jacobjordan wrote: no matter who is logged on
You can place the path to your exe in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run and your app will run at start up for all users - you can run it minimized to tray, or invisible by setting the Visible of the main form and ShowInTaskbar to false.Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Yes, sounds like a service.
However, what is a service going to do with some WindowText if it doesn't even know if anyone is logged in?
|
|
|
|
|
Found a good blog here[^] that may help you rethink and workaround your problemDave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Im writing a class to be called by different forms, Ive got the forms name using the sender but im having trouble saving this to the class because i don't know what form is calling the function.
class Login
{
Form CurrentForm;
if (Sender is form1)
{
form1 temp = (form1)Sender;
this.CurrentForm = temp;
}
Is there any way to declare a new class variable at runtime such as form1 CurrentForm;
Thanks
|
|
|
|
|
Hi,
not sure what it is you want.
Your code needs to reside inside a method, probably an event handler with a "sender" parameter.
Anyway, the solution probably needs a simple this.CurrentForm=sender as Form; with CurrentForm declared as a general Form, not a specialized one.
OTOH, if you were to explain your needs at a higher level, maybe a different approach would be advisable.
|
|
|
|
|
Yeah but then i cant use any methods hat are in the forms class
if (Sender is form1)
{
form1 temp = (form1)Sender;
form1.login()
}
The above works but i cant use form1 outside the if statment, I need a way os saving it at runtime like the class varibles here.
class Login
{
Form CurrentForm;
|
|
|
|
|
if all candidate senders share some user-defined functionality (would be necessary if you want to invoke a method on such sending form), then the solution would be to define an interface, and make all those forms "implement" the interface, which should mean you add ", IMyFunctionality" to the class declaration, as in:
public class MyForm1 : Form, IMyCommonFormFunctionality { ... }
where you need to define the interface, something like (outside all classes!):
public interface IMyCommonFormFunctionality {
void login();
}
Then in your class, do:
IMyCommonFormFunctionality CurrentForm;
...
CurrentForm=sender as IMyCommonFormFunctionality;
BTW: by convention public method names should be CamelCased, i.e. start with an upper-case letter.
[ADDED]
I doubt very much that adding login logic to a bunch of forms is the right way to go. Object orientation dictates to separate concerns, not mix them like that.
[/ADDED]
|
|
|
|
|
For anyone who's familiar with Telerik's RadGrid...
I have placed all rows into EditMode by setting AllowMultiRowEdit = true, then doing this:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
foreach (GridItem item in RadGrid1.MasterTableView.Items)
{
if (item is GridEditableItem)
{
GridEditableItem editableItem = item as GridDataItem;
editableItem.Edit = true;
}
}
RadGrid1.Rebind();
}
The problem now is - I don't see any way to force the grid to save changes. I tried:
protected void cmdSaveChanges_Click(object sender, EventArgs e)
{
SqlDataSource1.Update();
}
But it didn't work. How do I save changes in the grid? I do NOT want Edit or Update button columns in the grid.Everything makes sense in someone's mind
|
|
|
|
|
Hi all.
I have some issue with data encoding.
I have a txt file, which was open like this:
StreamWriter m_ComissionShopWriter = new StreamWriter(Directory.GetCurrentDirectory() + "\\logs\\1.txt", false, Encoding.GetEncoding(1251));
then I user WriteLine method to put there some data, which was taken from some stream:
sr = new StreamReader(stream, Encoding.GetEncoding(1251));
After, I try to load it into table, which has the following collumn:
varchar(100) cp1251_general_ci
Insertion goes great!
But when I run select query on it, I got some junk data instead of readable, 1251 encoded, data.
What is wrong, and how can I fix it?
Thanks!
|
|
|
|
|
When you open a stream with a specific encoding, it applies to the stream, not the data in memory; in .NET strings in memory are using Unicode no matter what. So you are reading/writing Unicode strings from/to the database, which requires nvarchar fields.
If you insist on having a particular encoding in the database, then you must read/write byte arrays, which you convert to/from Unicode strings using Encoding.GetString()/GetBytes().
|
|
|
|
|
Well, I tried it but it didn't work.
Here is a part of my code, can you tell me, please, what I did wrong?
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
try
{
connection.Open();
Console.WriteLine("Connected to DB");
}
catch (Exception e)
{
Console.WriteLine("Failed to connect to DB");
return;
}
command.CommandText = "truncate table test_tb";
command.ExecuteNonQuery();
connection.Close();
StreamReader sr = new StreamReader("somefile.txt", Encoding.GetEncoding(1251));
string line, query;
string[] data;
byte[] temp = new byte[10000];
int j = 0;
while ((line = sr.ReadLine()) != null && j < 10)
{
data = line.Split('~');
query = "insert into test_tb (name, id) values(N'" + data[2] + "'," + j.ToString() + ")";
temp = ASCIIEncoding.GetEncoding(1251).GetBytes(query);
command.CommandText = ASCIIEncoding.GetEncoding(1251).GetString(temp);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
++j;
}
The column in table os varchar(1000) type, with windows-1251 encoding
thanks a lot.
|
|
|
|
|
Hi,
I need to change my COM1 port to COM5. I can easily do it by opening the port advanced properties in the Device Manager and changing it from COM1 to COM5.
However, I searched google all over for a solution to do it from my code, and didn't find anything.
I can read the port settings using the SerialPort class or WMI, for example, I can read the DeviceID property of the Win32_SerialPort class. But I can't write to this property, it's read-only. Is there any other way to accomplish the same thing?
|
|
|
|
|
Hi,
your app should not try and change port names; instead your app should allow you to choose which port is to be used, just like a text editor allows you to choose which file gets read or written.
SerialPort.GetPortNames() could be useful.
And you should consider remembering your last choice, so by default the same port is used again and again.
|
|
|
|
|
It's not actually an app, I'm writing a setup script and I have a requirement to rename COM1 to COM5 during setup.
Because it's a requirement, not doing this is not an option
I was considering writing a small .net exe to do the job for me, but was stuck.
|
|
|
|
|
I'm trying to make my own Custom Control, to be more specific: a Composite Control with various Labels and Progress Bars. However I need the entire Control to act like a button so that No matter which control within the composite that the user clicks, it will still run the Click event I assign to the Control in my program. I've read that this can be done with Bubbling, but I’m having trouble understanding the concept and how it applies to my needs.
I've seen various examples of Bubbling, but I'm still uncertain because I can't see in those examples whether or not the events are "Bubbled" to the overall control's event within a program - they seem to end after the creation of the control.
|
|
|
|
|
Simply - the container type control subscribes to relavent events of it's hosted controls. The event handlers all call a
protected virtual void OnClick(EventArgs e) method that raises the host's Click event.Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
So, are you saying I can have each of my controls inside a container call the OnClick method whenever they're clicked? Then the Container's "Click" event will trigger? I'm not sure I'm understanding this right.
|
|
|
|
|
Yes - a simple experiment would verify this for you.
This is the idea:
public partial class MyUserControl : UserControl
{
public MyUserControl()
{
InitializeComponent();
}
private void textBox_Click(object sender, EventArgs e)
{
OnClick(e);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void myUserControl_Click(object sender, EventArgs e)
{
MessageBox.Show("Click Event");
}
} As you will see, the TextBox 's Click event is now 'bubbled' up to the surface by the MyUserControl .Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello all,
my employer Kryptiva and I have put out a first release of a new plugin for Microsoft Outlook 2003 and 2007 called echotracker.
echotracker is a mail indexer and personnal information aggregator that installs itself as an panel in Microsoft Outlook. The software isn't feature-complete but is already providing useful information about mails in Microsoft Outlook.
This is released under the terms of the LGPL 2.1 license which means it's OPEN-SOURCE! There aren't that many open-source Outlook plugin out there so I think this is interesting stuff for developers.
We need developers and courageous users to build and test first developer preview. We accept bug reports and patch on our mailing lists. I'd be glad to answer any kind of questions on this forum but we would prefer people to use mailing lists.
François-Denis Gonthier
|
|
|
|
|
You would probably be better off posting this in the Catalog.Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|