|
If you want too hook your windows messages of your own application implement IMessageFilter interface and inheit your form from it then use Application.AddMessageFilter to add it to your application and do whatever you want with it.
Mazy
"I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein
|
|
|
|
|
no not my own app but an outside app that i have its handle
|
|
|
|
|
You'll need to use a system hook, if nothing more than to inject your code into the other application's process space (since an application doesn't dispatch messages to other processes). See Using Hooks from C#[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi all,
i am writing a program in c#, and i have run into a MAJOR problem.
i have a 'frmMain' class which contains the GUI, and a 'database' class which handles the connection to the database. the GUI class creates an instance of the database class and calls the 'searchdatabase' method, which in turn wants to add items to a list box in frmMain. however, when i try to do this it tells me that an object reference is required . help is very much needed on this topic,
thanks in advance,
thewebmonster
|
|
|
|
|
Okay. It looks like one of your variables is not initialised properly. First you need to determine what is null (in other words what doesn't have an object reference).
A quick tour of some of the debugging features in VS.NET: The watch window and the call stack will come in useful. Re-run your program and wait for it to crash, then you can see from the call stack where the program crashed (you can also navigate up and down the call stack to see what was calling what at the time). In the watch window you can see the values of your variables and objects. Does any of these look like is should contain a value but doesn't. You can also hover over variables and properties in the code window to see their value at the point the program stopped.
If this doesn't work. The next thing you can try is setting breakpoints prior to the fault and stepping slowly through the code watching the variables change and the program execute at a speed you can comprehend. Does anything look like it should happen but doesn't - Like if statements that don't quite work they way you expect etc.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
it doesn't even compile.
i am using c# builder if that helps in any way possible...
|
|
|
|
|
Did it compile before? From your description it sounded like a runtime error.
If it is C# Builder that is causing this error then I'm not sure I can help as it sounds like the IDE is broken.
However, it may be the C# builder is giving a slightly different error message than VS.NET. What line of code does it give this error for? Have you tried to use a variable before it is initialised?
e.g.
SqlConnection conn;
conn.ConnectionString = myConnectionString; Could bring up an error like this because you create a reference to a SqlConnection object, but you don't actual creat an instance of it. You would need to insert the line
conn = new SqlConnection(); in between the two I've given above for it to work.
Watch out for things like this also:
SomeObject someObject;
foreach(SomeObject currentObject in someObjectCollection)
{
someObject = currentObject;
} because if there is nothing in the collection, someObject could possibly never be initialised and the compiler doesn't like that. The same goes initialisation within any conditional statements. Although it is clever enough if you have construct like if(){...}else{...} with initialisation in both
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
it is something like this...
frmMain.listSearchResults.Items.Add(id + " - " + Convert.ToString(myDataRow["name"]));<br />
<br />
and it returns the error<br />
<br />
database.cs(78): An object reference is required for the nonstatic field, method or propert 'VideoLibrary1.frmMain.listSearchResults'
i appreciate your quick replies
|
|
|
|
|
Is frmMain the name of your Form class, or the name of the variable that refers to an instance of the class?
From the error message, it looks like it is the name of the class. And what you need is an actual instance of the class.
You can do this by passing this from the main form class to the database class (I am assuming that the Database class is being instantiated from the form class). Although, from a design perspective, I don't think it is a good idea for a class that deals with the database to get involved with GUI code. (But that distracting from the current problem - So 'nuff said!)
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
frmMain is the name of the main class. could you expand on the passing of this because i don't quite understand what you mean.
Also, when you say about the database being involved in the GUI, i don't know any other way because of this problem at the moment. Once this problem is out of the way, there will be a fuctions class or something created with handlers for all the GUI elements.
|
|
|
|
|
this is the implicit object, or the instance of the class from which your code is currently executing. It's, "this" object. This is prevalent in C++, Java, C#, and several other languages. In VB and VB.NET, it's called "Me".
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i know that much , just what does it mean by passing it to the database class?;P
|
|
|
|
|
If the database class needs an instance of whatever this represents in your context, then you simply pass this to the database class so that it has a reference to that dependent object, something like this:
public class A
{
public A()
{
B b = new B(this);
}
public void SomeMethod()
{
}
}
public class B
{
public B(A a)
{
if (a != null) a.SomeMethod();
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
cheers, i'll try that.
|
|
|
|
|
thewebmonster wrote:
the GUI class creates an instance of the database class and calls the 'searchdatabase' method
How are you creating an instance of the DB class?
I assume you are doing myDatabaseClass = new DatabaseClass();
Is it the SearchDatabase method that is throwing the exception or is it code inside the method?
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
// in the database class
frmMain.listSearchResults.Items.Add(id + " - " + Convert.ToString(myDataRow["name"]));
and it returns the error
database.cs(78): An object reference is required for the nonstatic field, method or propert 'VideoLibrary1.frmMain.listSearchResults'
|
|
|
|
|
hiiiii....all
Assume you have a lan in your office,,,,All the computers there are clients ....and i wanna to develop a software for communuication between clients...the appliaction will have array of the ips of the network,the user selects a specific ip,,,and press (send button) to transfer any file to the Computer with the specific id(Communication may be files or text)
the Communication is two way to,,,as computer A can sends to Computer B and vice versa
i think that UDP is good,,,but i cannot understand it,,
please any one who have developed a software close to that,,Send me Anotification
Thanks,,,,all
|
|
|
|
|
peter micheal wrote:
i think that UDP is good,,,but i cannot understand it
I've never used UDP, but if you're going to be using sockets I think that TCP is a better option.
A good book on Sockets is C# Network Programming by Richard Blum. It describes UDP as a connectionless protocol. A quote from the book: "Connectionless sockets allow the sending of messages in self-contained packets. A single read method reads the entire message sent by a single send method... Unfortunately, UDP packets are not guaranteed to arrive at their desitnation" (pp210)
So, what I understand from this is that something sent via UPD must fit in one packet (typically 1500 bytes, which includes the space reserved for the IP headers) AND if you send a file this way it may not reach its destination. Certainly the books example code for using UDP never sends anything greater that 1kb.
If you are going to do network programming then I do recommend a good book on the subject. The one I mentioned above is an excellent book for use with C#. That way, if you do still have problems then you can be more specific in posting a question.
Back to your problem: You will need to have a process running on each of the clients that is acting as a server (it is able to receive incomming communications). If you say they are all clients you will go round in circles trying to figure out get them to communicate with each other. Always you need a client process (which initiates the request) and a server process (which responds to the request). In your cast a request is sending the file from one computer to another.
Next, you will need some protocol of your own to permit the transfer. You will need to tell the receiving computer (the server) how much data you are going to send at the very least so that it knows when to stop looking for more data. (You may also like to add in things like filename, timestamps, usernames and other relevant metadata) Now, there are off-the-shelf protocols already available in the .NET Framework that will assist you in this, but if you want to use Sockets you will have to do all the hard work yourself.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
I got a text file that i exported from SQL Wizard and i named bank.txt.
i want to write out a program that allow to import bank.txt file to SQL Server but i do not know how to do it.
So can anyone help me or show me where to get the source code.
Thank a lots.
Mr Duc Linh Nguyen
|
|
|
|
|
quocbao wrote:
I don't know import data into Sql server from file text, when user give a file text.
Your question is a little vague as you don't define the contents of the text-file.
Do you want to do this programmatically?
You could use the DTS wizard that comes with SQL Server (Import and Export Data) as this app will pretty much do the job for you.
If you want to interact with the DTS via C# then have a read of HOW TO: Create a Data Transformation Services Custom Task by Using Visual C# .NET[^]
Alternatively, you could read the text file, parse the contents and then squirt the data into SQL using ADO.NET.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
My job requires me to write a an application that will collect data from a Web Form and then dump it into MS Message Queue. May I reqoest help from you experts to show me, after collecting the data from the form, how I could achive that within C# .NET. Do any of you folks have any code snippets?
I am doing C# for only few months and love it but I got stuck here.
Regards,
Login
|
|
|
|
|
Have you look at MessageQueue class?
Mazy
"I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein
|
|
|
|
|
I'm using VS .NET and in the solution Explorer i can see a .exe file but i can't find a .dll for the same file. I need the .dll for assembly referencing. Is there a way of creating the .dll when i only have a .exe
|
|
|
|
|
Not unless you rewrite the code to be in a .DLL. The two files have very different entry points and startup routines.
Visual Studio wont let you set a reference to an .EXE, but the commandline compiler, csc, will let you reference an .exe. There was another thread in this forum that spelled this out earlier this week.
RageInTheMachine9532
|
|
|
|
|
Just try renaming it from exe -> dll should be ok dll -> exe will obviously not.
top secret
|
|
|
|
|