|
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 [^]
|
|
|
|
|
Ive been battling with this prob for a LONG time now..
Using Threads and remote retrieval: i get a rpc error or COm exception sometimes? Like it's retrieving the values, and then it says rpc server unavailable and then if u carry on it will retrieve the next value.. happens with different values..
maybe deadlock occurs?
Basically- i use: private ManagementObjectSearcher m_MOSearcher;
private ManagementScope m_ManScope;
private ConnectionOptions m_ConnectOptions;
m_ConnectOptions = new ConnectionOptions ();
m_ConnectOptions.Username = "user";
m_ConnectOptions.Password = "pass";
m_ConnectOptions.Authentication = AuthenticationLevel.Call;
m_ConnectOptions.Impersonation = ImpersonationLevel.Impersonate;
m_ConnectOptions.EnablePrivileges = true;
m_ConnectOptions.Locale = "MS_409";
m_ConnectOptions.Timeout = new TimeSpan (0,0,0,0,5);
string strConnection = "\\\\"+ "192.168.0.88" + "\\root\\cimv2";
m_ManScope = new ManagementScope(strConnection, m_ConnectOptions);
ObjectQuery Temp = new ObjectQuery("SELECT " + "Size" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Size: " +mo["Size"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "Model" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Model: " +mo["Model"].ToString ());
}
And thread it with:
for (int i=0; i< 250; i++)
{
Thread a = new Thread(new ThreadStart(Function));
a.Start();
}
|
|
|
|
|
(Type your message here)
richTextBox rtb = new richTextBox();<br />
StringBuilder stb = new StringBuilder();<br />
stb.Append(rtb.Text);
In a foreach(char ch in stb.ToString()) statement I want to know if we have find end of line.
Any fast way to do this?
Could this be done without converting .ToString() by someway?
|
|
|
|
|
Does it have to be a StringBuilder and then running through all characters separately?
I guess using IndexOf() on rtb.Text might be faster...
mav
|
|
|
|
|
It's important for me to read the characters separately and insert or remove a specific number of continous spaces(not all) at the start of any line, rapidly.
|
|
|
|
|
Ok, in that case I'd second the String.Split/String.Merge suggestion, because if you insert characters in your string, the system has to move the rest of the string. So creating an array of lines, modifying each line separately and then combining them again should perform much better.
|
|
|
|
|
|
A newline is not just one character for windows, it's string representation = "\r\n", which can be found in System.Environment.NewLine.
You could try comparing the current Char ch to: Char newline = '\n';, but I'm not sure that'll work. Or make a variable that holds the last char compared like so:
<br />
Char last = '';<br />
<br />
foreach(char ch in stb.ToString())<br />
{<br />
if(ch == '\n' && last == '\r')<br />
{<br />
}<br />
last = ch;<br />
}<br />
|
|
|
|
|
I was thinking break will take me out of if() which was in the foreach() .
But it was taking me out of the foreach() .
So some parts of code was not executed. Instead of break I used continue .
So my problem was solved by this way:
foreach(char ch in <code>stb.ToString())
{
......................
if(ch.ToString()=="\n")
......................
}
The "\r" doesn't appear anywhere.
Performance is low for other reasons. I should think other solutions.
Thanks.
|
|
|
|
|
Hi
i am trying to make an formula on date
my problem is this .... i give a date like this = 2-4-2004
and i give another date that is 2-6-2005 and i want to get the difference between them .... it will count days, months, and years.... and one more thing that if you are giving solution of this put this in your mind that days may be 28, 31, and 30 .... ok TC.
bye
Mazhar Hussain.;)
|
|
|
|
|
Just look up the DateTime and TimeSpan classes in the framework.
They hold everything you need.
Regards,
mav
|
|
|
|
|
DateTime d1 = ...;
DateTime d2 = ...;
TimeSpan diff = d2 - d1;
now diff will give you hours, months, days... whatever you need.
|
|
|
|
|
Hi all:
I am recently thinking is it possible to serialize an assembly (I descover it in run-time) and transfer it to the remote client. Thus, the client can execute it? Bellow are more on my idea
Server:
Discover some assembly that the client may need the function that I already pre-compiled as a .dll file in server, then the server load it and send the assembly to the remote client.
Client:
This is a generic client it doesn't have much functionality by itself, but it can discover what assembly have on the server. If the function the client is needed, server will load the assembly dynamically and transfer to the client. So the client have the function to use.
By implementing this, the client can be compact and dynamic in the function.
The client even can write the source code and compile the source into an assembly which will be stored in the server. And let other client to discover and use this assembly too.
Regards,
Joel
|
|
|
|
|
Im not sure if I understand what you mean. Why dont you just send the assembly as binary data, save it on the client machine and load and execute it via reflection?
|
|
|
|
|
joelwu wrote:
By implementing this, the client can be compact and dynamic in the function.
The client even can write the source code and compile the source into an assembly which will be stored in the server. And let other client to discover and use this assembly too.
Your best bet might be to go with .NET Remoting. Read the following article : Microsoft .NET Remoting: A Technical Overview[^]
- Nick Parker My Blog | My Articles
|
|
|
|
|
I created a thread a little bit ago that has some code that demonstrates a problem that I have. Basicaly I'm trying to do double buffering and I "trick" windows.forms into painting the control onto a buffer, the problem is, is it also paints a black rectangle where the control is(I know it is also painting my control because I can scale the window and the control will go while the black box doesn't)... I also know it is the parent that is doing this and not the control since I have completely disabled the control's painting functions and still have the problem... It seems that either the form is excluding the region from being updated for painting by the form's OnPaint/OnPaintBackground("no need to paint behind a control") and painting it black, or that its trying to paint the control but there is some kinda "bug"...
I've overriden the forms wndproc and took out the WM_PAINT and it doesn't draw the black box, but does not render that area at all(which makes me believe that the form has excluded the controls region from being painted at all, I put painting the background on a timer, so the background is showing up... just not anything where that square is...)...
since I don't know much about how windows handles the control, I'm wondering if someone can help me out... I'm sure theres somethere where I can tell windows not to exclude region behind the controls from being updated... not sure if its in my PaintEventArgs or somewhere in the WinProc...
Anyways, thanks for any advice/help...
BTW, I do not have WS_CLIPCHILDREN set in my styles(override CreateParams)... which would seem to be the cause if I did.
|
|
|
|