|
Hi all,
I have developed a dll in Win32. That dll finds the updated regions
of the desktop and then post these regions data to a C# application
using PostThreadMessage(). But problem is here i m not so much use to
with C# so i havent any idea how can i get it from the Application
message queue of my C# application.
Thanx
|
|
|
|
|
In C#, you typically don't deal with the Win32 message queue. The .NET framework is designed to abstract away the underlying operating system & hardware. So, if you're listening for when a user moves his mouse over your System.Windows.Forms.Form, just setup an event handler for the MouseMove event.
Form myForm = new Form();
myForm.MouseMove += new MouseEventHandler(MyMouseMoveFunction);
...
void MyMouseMoveFunction(object sender, MouseEventArgs arguments)
{
}
That said, if you want to get low level, past the abstractions, you can create a class that inherits from System.Windows.Forms.Form, then override the WndProc virtual method; that method is called every time your form receives a windows message.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
|
Dear u r quite right that i can track mouse movements. But here is the
different case my dll is a hooking dll and is responsible for getting
screen display updates. So here i m restricted to use that unmanaged
dll.
I have passed dll the managed thread id so that dll can post messages
of screen updates to my C# application.
Is it right to pass a managed thread id in PostThreadMessage()?
Thanx for ur response.
|
|
|
|
|
Does the WebBrowser control introduced in .NET 2.0 work fine with console applications? I'm facing problems doing something like
string x = "<HTML>abc</HTML>";
browser.DocumentText = x;
Unfortunately, x never gets set, browser.DocumentText always remains as <HTML> </HTML>
On a hunch, I tried doing an Application.DoEvents right after setting the DocumentText property and it worked. Does that mean there is no *easy* way to use the WebBrowser just for inspecting and manipulating the DOM tree?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
We've had trouble with WebBrowser controls without a parent; you may end up having to create an invisible form and add the browser to that form before you can do things with the document.
|
|
|
|
|
That did the trick, thank you. I dearly wish .NET 2.0 provided a class to do nothing else but parse HTML.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote: I dearly wish .NET 2.0 provided a class to do nothing else but parse HTML.
I agree.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
Yeah, the WebBrowser control won't work properly without a parent form, which you don't have in a Console app. You'll have to create a form to put the control on, but just never show the form.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Hi, I have a problem with the functions SetCommTimeouts and GetCommTimeouts of the Win32 API.
First of all, I want to make a synchronous read on a USB device with a timeout of 250 ms, that is, the ReadFiule function returns after 250 ms if no data is received.
This is the COMMTIMEOUTS Structure
<code>
[StructLayout(LayoutKind.Sequential)]
public struct COMMTIMEOUTS
{
public int ReadIntervalTimeout;
public int ReadTotalTimeoutMultiplier;
public int ReadTotalTimeoutConstant;
public int WriteTotalTimeoutMultiplier;
public int WriteTotalTimeoutConstant;
}
</code>
These are the 2 functions: GetCommTimeouts and SetCommTimeouts
<code>
[DllImport("kernel32.dll")]
public static extern bool GetCommTimeouts(IntPtr hFile, out COMMTIMEOUTS lpCommTimeouts);
[DllImport("kernel32.dll")]
public static extern bool SetCommTimeouts(IntPtr hFile, ref COMMTIMEOUTS lpCommTimeouts);
</code>
And finally, here is how I try to adjust the timeouts
<code>
FileIO.COMMTIMEOUTS timeouts;
// Create handle
hidHandle = unchecked( FileIO.CreateFile(path,
(uint)(FileIO.GENERIC_READ | FileIO.GENERIC_WRITE),
FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE,
ref security,
FileIO.OPEN_EXISTING,
0,
IntPtr.Zero));
if(hidHandle == FileIO.INVALID_HANDLE_VALUE)
{
success = false;
}
else
{
// Read timeouts
if(FileIO.GetCommTimeouts(hidHandle, out timeouts))
{
timeouts.ReadIntervalTimeout = 0;
timeouts.ReadTotalTimeoutConstant = 0;
timeouts.ReadTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;
timeouts.WriteTotalTimeoutMultiplier = 0;
// Set them
if(FileIO.SetCommTimeouts(hidHandle, ref timeouts))
{
// I READ THEM AGAIN AND THEY HAVE NOT CHANGED!!!
FileIO.GetCommTimeouts(hidHandle, out timeouts);
success = true;
}
}
else
{
int lastError = FileIO.GetLastError();
}
}
</code>
I create a handle successfully, I call GetCommTimeouts, it returns true, I modify the timeouts and apply them by calling SetCommTimeouts, it returns true. But then, when I call GetCommTimeouts again, the timeouts are just like before! They haven't changed!
Where's my mistake?
Thank you!
|
|
|
|
|
is it possible to add an app.config in a class library project and use that to retrieve the appsettings?
from within a class in the same project?
If so then I can not see why mine does not retrieve the appsettings?
Thanks
|
|
|
|
|
.config files work per AppDomain. Class libraries do not get an AppDomain, so they will use the .config files of the loading applications.
However, Mike Woodring has an interesting solution with per-Assembly configuration files. You may want to take a look at his Per-Assembly Configuration Files.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
so do you mean that I can not add an app.config in my class library project ?
|
|
|
|
|
Correct. If you have the class library goo.dll, then it will not use the goo.dll.config file for its appSettings.
I haven't used .NET 2.0 and do not know if they have expanded support for this to Class Libraries. Maybe someone else on the board can answer that.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I am using 1.1 and it allows me to add app.config
On the other hand, how can i pick up the connectionstring from a datalayer?
Thanks
|
|
|
|
|
I apologize. I don't understand what you mean by it "allows [you] to add app.config" and "pick up the connection string from a data layer."
If you need a configuration string that exists outside your application, you can always just roll your own config file, open it, parse it, and use the values that you find inside it. Or, you could store it in the registry. Or, use the AssemblySettings class to which I linked a couple of posts ago. You don't have to use the .config framework here. I think it would be great if you could....
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
In the class library project, I can go to add new item and add an app.config file.
|
|
|
|
|
Just because you can add it to the project does not mean that your code can use it automatically. Sorry that you got misdirected by the IDE.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
ok, so let me get this correct.
I should not be adding a app.config in my class library project, because even if i do, it will not work.
Is this correct?
Thanks
|
|
|
|
|
Yes.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
ok, now I understand this one.
I am used to using web.config in asp.net
Now i am using windows forms on the client and a datalayer as another project. How can I get the connection string in the datalayer?
Is there a similar method to that in the web.config and using system.configuratioin.appsettinigs, etc...?
Thanks
|
|
|
|
|
If I understand this correctly, you have the following:
Client Application: Windows Forms Application
Data Layer Library: Class Library
If you use the classes from the Data Layer Application in the Client Application, then you can use the .config file distributed with the Client Application. For example, your Client Application's executable is aCoolClientApp.exe. You have a .config file distributed with it named aCoolClientApp.exe.config. Your Data Layer Library will read its appSettings from aCoolClientApp.exe.config.
For example, I have an Windows Forms solution named WindowsApplication4 and a Class Library named ClassLibrary1. They contain the following, respectively:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication4
{
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
DataLayer.Data data = new DataLayer.Data();
Text = data.GetMySetting();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
using System;
namespace DataLayer
{
public class Data
{
public Data() {}
public string GetMySetting()
{
return System.Configuration.ConfigurationSettings.AppSettings[ "MySetting" ];
}
}
}
And, finally, I create the WindowsApplication4.exe.config file with the following contents.
<configuration>
<appSettings>
<add key="MySetting" value="I love C#" />
</appSettings>
</configuration> Now, the call in DataLayer.Data.GetMySetting() will read the setting in WindowsApplication4.exe.config and return it.
Does that help?
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
When you refer to WindowsApplication4.exe.config
Is that the app.config ?
If so then where is it located?
On the client?
Thanks
|
|
|
|
|
Yes, WindowsApplication4.exe.config is the .config file for the Windows Forms application because the name of the application is WindowsApplication4.exe.
It is located in the same directory as WindowsApplication4.exe.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|