|
How to read the address of LPT (parallel port) and the COM port (RS232) by the code in C#
|
|
|
|
|
Im thinking of a way to input text into a textbox of another application. Supposing that I have the handle to that textbox.
Right now the only way of doing something like that, that I can think of, involves breaking up the needed string input into characters. Then posting a WM_KEYDOWN message or something for each character to the textbox. I'm not even sure if thats possible. Anybody has an idea?
I tried to find something that would allow me to change the text property of the textbox or WM_SOMEMESSAGE that would allow me to do what I want, as well as various API functions etc., but I had no luck. Can anybody point me in the right (some) direction. I'm running out of ideas. The method I mentioned above seems unnecesarily complicated, but I might be forced to do it that way. Well I'm gonna go look for some api functions again. I hope someone has an idea.
Thank you.
|
|
|
|
|
If you have the handle to the textbox you want to set the text of, you can simply P/Invoke SendMessage and pass the handle with the corresponding WM_SETTEXT message.
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
int WM_SETTEXT = 0x000C;
string text = "Hello";
SendMessage(YourHandle, WM_SETTEXT, null, text);
- Nick Parker My Blog | My Articles
|
|
|
|
|
I sent EM_SETSEL and then EM_REPLACESEL, but SETTEXT seems easier. Plus one less overload of SendMessage() to have. I have about 4 sending different messages with different parameter types.
Thanks.
|
|
|
|
|
I tried to add a <myapp>.exe.config in the bin\debug folder in my C# console application, even added it in the project, but it still doesn't work. Here's the code in the config:
<configuration>
<appsettings>
<add key="constring"
="" value="server=localhost;database=Northwind;uid=sa;pwd=;">
I acccess it in the console as :
con = new SqlConnection(ConfigurationSettings.AppSettings["constring"]);
but it won't work, always issued a connection string not set error.
If I don't use any config file, it works fine:
con = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=;");
Please help.
|
|
|
|
|
Your original post has not come out very well - part of the XML has been lost. If you replace the < with < we can see what you are trying to do.
As a general rule, it can be good to populate a string first, then pass the string as a parameter, when extracting a string like this.
string theConnectionString = ConfigurationSettings.AppSettings["constring"];
con = new SqlConnection(theConnectionString);
This way you can set a breakpoint and see exactly what the connection string is.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Hello.
I've got the following problem:
I created a windows installer project that installs my application.
The application works with some files. I want to include some
example files with the installation package.
These files by no means are critical for the application itself.
They are included only to help application user to get aquaintanced
with the app.
The problem occurs when the example files are deleted after
installation: When user clicks on the shortcut to the application
(on his desktop) the application installer is started instead
of the application itself. The installation process restores
the "missing" files, and the applcation is allowed to start normally
afterwards. But this is greatly annoying (!), that every application
launch involves reinstallation (that lasts 2-3 min).
How to designate some files, that the installer should not care for them _afterwards_ installation process ??
I found "vital" property of file, but this (as documentation
confirms) specifies whether a file is vital or not, during installation (i.e. the installation fails if the file cannot be properly installed). I set this to false but in vain. Still deleting example files causes the problem.
I want a file to be deletable [i.e. not causing reinstallation]
Is it possible ?
Thank You
Michał
|
|
|
|
|
Since windows installer seems to behave strangely sometimes you could write your own Installer class to copy the files yourself and then include it as a custom action into your setup project.
Might be worth a try...
|
|
|
|
|
Hi,
I'm looking for a database that will have all provinces, towns for each country
and translated in spanish and english.
Does anyone have such a database ? where can i find this ?
thanks for any help on the subjet
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
That could be a tall order. Not all countries are made up in this manner.
For example, England is made up of 47 boroughs, 36 counties, 29 London boroughs, 12 cities and boroughs, 10 districts, 12 cities, and 3 royal boroughs.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Hi,
Using Albert Pascual's article as a starting point, I have created a Windows Service. However, I can't get it to run. After building it, I opened the command window and ran the InstallUtil.EXE on it successfully, but it never shows up in the MMC/Services window and it never writes to the event log. What should my next step be to get this thing going?
Thx,
RFickling
|
|
|
|
|
I suggest using the /logFile option to InstallUtil. If you didn't, it still writes logs: see the documentation for InstallUtil.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi!
this is my first post here, so bear with me . I'm currently trying to convert my C++ source to C#. I have now the problem that in my C++ code I'm passing a already existing object (wich is living in another class) in the constructor to yet another class. Ths happens as a pointer. But when I'm trying to do this in C# I'm getting the error CS0236: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cscomp/html/vcerrCompilerErrorCS0236.asp
How would I do this in C#? I've already tried to pass it as reference, but I'm getting the same error then.
Thanks in advance
|
|
|
|
|
Ah I forgot to say I'm using SharpDevelop, just incase this helps
|
|
|
|
|
If you'd post some code, that would help.
You can pass C# objects as regular objects, and not use pointers.
Since in c# you always have to use "new" to construct object and they are always passed by reference. It seems you're looking for a copy constructor construct in C#, which can't be done without cloning the object.
Just give us some small code example.
|
|
|
|
|
Classes are passed by reference. The following works. Please post your code so we can see what the problem is.
using System;
public class test
{
class one
{
public one()
{
Console.WriteLine("one's constructor");
}
}
class two
{
public two()
{
Console.WriteLine("two's constructor");
}
public two(one o)
{
Console.WriteLine("two's constructor");
}
}
public test()
{
one o = new one();
two t = new two(o);
}
[STAThread]
public static void Main()
{
test t = new test();
Console.Read();
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Ok then heres the code. At least a part of it.
http://www.nomorepasting.com/paste.php?pasteID=16138
|
|
|
|
|
Hello Pps
I implemented a serial communication on a Pocket Pc. I used code out of a msdn article (http://support.microsoft.com/default.aspx?scid=kb;en-us;823179)
to reach my goal........
The target is to send a special bytecode to a microprocessor, which should look like this:
Code + carrige return + checkbyte
ASCII: z004\r<
Byte: 7A 30 30 34 0D 60
Now the program actually runs. BUT the COM don't send exactlly what
the program is telling it. So the microprocessor always receive an additional line feed and the data look like this:
7A 30 30 34 0D 0A 60
**
I tried many differently DCB attitudes, but it didn't work.
The DCB struct i used look like this:
public struct DCB <br />
{<br />
<br />
public int DCBlength;<br />
public int BaudRate;<br />
public int fBitField;<br />
public Int16 wReserved;<br />
public Int16 XonLim;<br />
public Int16 XoffLim;<br />
public byte ByteSize;<br />
public byte Parity;<br />
public byte StopBits;<br />
public byte XonChar;<br />
public byte XoffChar;<br />
public byte ErrorChar;<br />
public byte EofChar;<br />
public byte EvtChar;<br />
public Int16 wReserved2;<br />
}
And the settings
intResult = GetCommState(intHandle, ref lpDCB);<br />
<br />
lpDCB.BaudRate = 1200;<br />
lpDCB.fBitField = 0x0803;<br />
lpDCB.XonLim = 0;<br />
lpDCB.XoffLim = 0;<br />
lpDCB.ByteSize = 7;<br />
lpDCB.Parity = 2;<br />
lpDCB.StopBits = 0;<br />
lpDCB.XonChar = 48; <br />
<br />
intResult = SetCommState(intHandle, ref lpDCB);
So I don't know how to continue..??????????
Thanks for help and excuse my bad english
Andreas
|
|
|
|
|
The example code you linked to uses an Encoding object to turn a string into an array of byte . I suggest using a byte array directly.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanx for answering...
So i've already checked the converting part by debugging. But the program writes exact what i want to the "File" (WriteFile WinAPI function).
I think it has something to do with the COM settings. There is a binary mode flag in the
DCB structure, which i set to true, but it had no infuence.
Greets
Andreas
|
|
|
|
|
After much research i finally managed to find how to change to wave out volume, however i am still unable to find a way to mute/change the volume of the line in line. I believe that it has to do with MIXERLINE_COMPONENTTYPE_SRC_LINE. If anyone knows how to achieve this it would be greatly appreciated.
|
|
|
|
|
hi
i dont how to write visual c# code for login users
please help me
thank u
|
|
|
|
|
lolo82 wrote:
i dont how to write visual c# code for login users
Your question is a little vague.
Login user to what? A database? Windows?
Michael
CP Blog [^]
|
|
|
|
|
|
lolo82 wrote:
to database
Again it depends on the database and what security methods it uses.
I personally prefer writing my database connection strings to the App.Config file when Windows authentication is being used.
Or are you trying to lookup a user in a database?
Michael
CP Blog [^]
|
|
|
|