|
Sure, the following is a quick example, you have to P/Invoke the call to GetKeyState . Give this a try:
[DllImport("user32.dll")]
static extern short GetKeyState(int nVirtKey);
public bool IsCapsLockOn()
{
short keyState = 0;
keyState = GetKeyState((int)Keys.CapsLock);
return(keyState == 1 || keyState == -127);
}
private void button1_Click(object sender, System.EventArgs e)
{
if(IsCapsLockOn())
{
MessageBox.Show("Caps Lock is on");
}
else
{
MessageBox.Show("Caps Lock is off");
}
}
|
|
|
|
|
|
I am trying to find out what is inside my dataset. I have inserted a break in the program and right click on the dataset when it is highlighted and open the quickwatch. I have searched the heirarchy inside the quick watch but to no avail. I am looking for some guidance on how to navigate the dataset to find out what is inside of it. I keep getting an error,"A field property with the name 'stopnum' was not found on the selected datasource." I am using a stored procedure to populate the dataset and the first field of the stored procedure I use as and name it stopnum. Any guidance would be appreciated.
Scott Moore
|
|
|
|
|
There are several techniques you could try.
* Write a little routine that can output the desired information to a file or other debug information destination. Then, comment out or otherwise remove the code when it has finished being useful.
* Use the watch window to actually call a function that can display the information you desire. With VS 2003, this is often much easier to read than running through the object's properties. But, be warned that the method will be called each time you break at a new location in the code, so pay attention to performance if that could be a problem.
* Try out the beta of VS 2005, since it is supposed to have much improved debug displays for this sort of thing.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
One way could be to add a datagrid and set its datasource to be the dataset you are debugging.
|
|
|
|
|
|
I have read that article and am not sure where to put the code to get that to work. I am new to C#, have only been using it for about three or four months. If you can give me some guidance as to where to put the code I would appreciate it!
Scott Moore
|
|
|
|
|
How do find the user's application folder name? If I wanted to create a folder to store certain data and place it in a folder like this "C:\Documents and Settings\UserName\Local Settings\Application Data\ApplicationFolder" how can I check to see if the folder exists? Can this be done with the "Environment" or "Directory" class?
|
|
|
|
|
Use Environment.GetFolderPath with enumerated parameter SpecialFolder.ApplicationData or use Application.UserAppDataPath .
|
|
|
|
|
Hi,
Read up on System.Environment.GetFolderPath[^], and you'll have the answer you need!
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
|
All pactual paths for the various special folders are cataloged in
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
Anger is the most impotent of passions. It effects nothing it goes about, and hurts the one who is possessed by it more than the one against whom it is directed.
Carl Sandburg
|
|
|
|
|
I built a class library in C#. It consists of one public method as shown below.
public int calculate(int x,int y)
{
return x+y;
}
And I built the .tlb file using Regasm.exe for using it in VC++ 6.0.
I created the object for the interface also.
but, I can't call the methods in the class. I instatiated in the the interface as follows.
void CDialogDlg::OnButton4()
{
MYSampleLib::_SampleClassPtr ptr;//(__uuidof(MYSampleLib::_SampleClass));
ptr.CreateInstance(__uuidof(MYSampleLib::_SampleClass));
int i = ptr.calculate(90,80);
}
I got the following error.
error C2039: 'calculate' : is not a member of '_com_ptr_t<class _com_IIID<struct MYSampleLib::_SampleClass,&struct __s_GUID _GUID_3ec86308_ba43_3a5e_936f_5fd96c29c651> >'
what's the Chaos here???????
I'm not sure, this is the correct question in this thread or not ........
Thanks,
Zxczc
|
|
|
|
|
You should probably ask this in the VC++ forum, not C#. However, even though it's been a while since I did this sort of thing in VC++, I believe you will first need to change ptr.calculate to ptr->calculate .
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
|
You k'now, you log on, the program starts, no clicking required
|
|
|
|
|
Put a link to it in your Startup folder...
|
|
|
|
|
And that would be where exactly
|
|
|
|
|
Using your Windows start menu, go to Start->All Programs->Startup !
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
It a registry entry under the user. If you look up registry programing you can have a program call a .reg file and add a prog to startup automatically.
|
|
|
|
|
HKEY_LOCAL_MACHINE > SOFTWARE > MICROSOFT > WINDOWS > CURRENT VERSION > RUN.
If you only want to run the program once on start up (e.g not run on next startup), add the entry in HKEY_LOCAL_MACHINE > SOFTWARE > MICROSOFT > WINDOWS > CURRENT VERSION > RUNONCE
|
|
|
|
|
Hello,
I have a problem with asynchronous sockets communication. I try to send an object from the server to the client by using the send method. In the client's ReceiveCallback I have put two breakpoints, one at line "if (bytesRead > 0) " which is hit, and one at line " bgForm.ReceiveObject(state.gameDataStream);" which never gets hit. What could be the reason? Thanks in advance.
The client code:
public static void StartClient(string ServerIPAddress, int port)
{
// Connect to a remote device.
try
{
IPAddress ipAddress = IPAddress.Parse(ServerIPAddress);
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
connectDone.Reset();
// Connect to the remote endpoint.
client.BeginConnect( remoteEP,
new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
Receive(client);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private static void ConnectCallback(IAsyncResult ar)
{
try
{
// Retrieve the socket from the state object.
Socket client = (Socket) ar.AsyncState;
// Complete the connection.
client.EndConnect(ar);
// Signal that the connection has been made.
state.workSocket = client;
connectDone.Set();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public static void Receive(Socket client)
{
try
{
// Begin receiving the data from the remote device.
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private static void ReceiveCallback( IAsyncResult ar )
{
try
{
// Retrieve the state object and the client socket
// from the asynchronous state object.
StateObject state = (StateObject) ar.AsyncState;
Socket client = state.workSocket;
// Read data from the remote device.
int bytesRead = client.EndReceive(ar);
if (bytesRead > 0)
{
// There might be more data, so store the data received so far.
state.gameDataStream.Write(state.buffer,0,bytesRead);
receiveDone.Reset();
// Get the rest of the data.
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,
new AsyncCallback(ReceiveCallback), state);
receiveDone.WaitOne();
}
else
{
// All the data has arrived; put it in response.
// Signal that all bytes have been received.
receiveDone.Set();
}
bgForm.ReceiveObject(state.gameDataStream);
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,
new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
|
|
|
|
|
Unless I'm making a horrible mistake in reading your code, the flow goes something like this:
ReceiveCallback is hit, and proceeds through the following lines, in order:
<br />
if (bytesRead > 0)<br />
<br />
state.gameDataStream.Write(state.buffer, 0, bytesRead);<br />
receiveDone.Reset();<br />
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,<br />
new AsyncCallback(RecieveCallback), state);<br />
receiveDone.WaitOne();<br />
The result is that inside your read you start waiting for the next read to finish. So, at least until something triggers receiveDone , the code will not reach your bgForm.RecieveObject(state.gameDataStream) function.
You will need to rework the flow logic, so you can handle the data you just received before waiting for the next read, or triggere then next read and handle your data without waiting for the next read to finish.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Hi John,
thanks for the reply. I'm not quite sure how EndReceive() works and when it returns 0 bytes read. I was hoping that it reads the chunks of the data and when finishes and 0 bytes are read performs receiveDone.Set() and than I get the full data and deserialize the stream. If I remove WaitOne() from the code I get an error "Failed to deserialize. Reason: end of stream encountered before parsing was complete." I guess it is a synchronization issue but can't find the solution by myself, so any advices are appreciated.
Regards
|
|
|
|
|
Well, your code doesn't show the attempt to actually read from the socket. So, I assume that you have dropped the information in bytesRead by the time you get to the routine that actually reads the data. If that is correct, you are simply trying to read more than there is available to be read.
It also sounds as if you are using serialization, which I haven't worked with. Much of my socket work has been with manual code to interpret what is being sent.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|