|
Have you read this article[^]? It talks about how to make a client and server communicate via sockets.
If you need help with a specific problem, be more specific.
|
|
|
|
|
Hi All,
I have been making a user control. (VS 2003)
I wish to handle its mouse events.. something like, the control background should turn red on MouseDown, and become white again on MouseUp.
I added the MouseDown and MouseUp event handlers and tried changing its BackColor on MouseDown and MouseUp events. After building and adding this control to another application, i found that the color does not change.
Do i have to create my own events for this. I am not able to understand why this is not working.
Can anyone help me out with this. I am new to C#.
Thanks in advance.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
Did you call this.Invalidate(); after you changed the BackColor of your control?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello
1- Make a break point in your code to see if the events are really excuted or not. You could also do something else like showing a MessageBox, or sending a trace, or anything as an evidence of the excution of the handlers.
2- Please post the code that you change the background with. This also might help.
Regards
|
|
|
|
|
I am trying to use a C++ dll designed in VS 6.0 with C# .net. The problem is with passing a pointer into the dll that expects a char* (not unicode). I have tried passing a IntPtr, a StringBuilder, and a Byte[], but I get the same results "AccessViolationException was unhandled" "Atempted to read or write protected memory. Any help would be appreciated.
Heres the C++ dll code:
extern "C" __declspec(dllexport) BOOL ExGetDeviceSerialNumber(DWORD nDevice, char *pSerialNum)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
TRACE(_T("Entering LogiComm2GD ExGetDeviceSerialNumber\n"));
return DllGetApp()->GetDeviceSerialNumber(nDevice, pSerialNum);
}
BOOL CLogiComm2GDApp::GetDeviceSerialNumber(DWORD nDevice, char *pSerialNum)
{
if(nDevice >= m_NumL2GDDevices)
return FALSE;
strcpy(pSerialNum, &m_USBSerialNumbers[nDevice][0]); // exception here
return TRUE;
}
and here's the C# code:
// dllImport declaration
// get the device serial numbers
[DllImport(@"C:\Documents and Settings\jbroderick\My Documents\Visual Studio 2005\Projects\\USB_D2XX_App\LogiComm2GD.dll",
EntryPoint = "ExGetDeviceSerialNumber",
ExactSpelling = false,
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe bool ExGetDeviceSerialNumber(long nDevice, IntPtr ptr);
// access the dll
IntPtr ptrSN = IntPtr.Zero;
ExGetDeviceSerialNumber(Device, ptrSN); // exception here
|
|
|
|
|
JohnnyB717 wrote: strcpy(pSerialNum, &m_USBSerialNumbers[nDevice][0]); // exception here
I would think so since pSerialNum has never been allocated.
"strcpy" is deprecated... see the safe string function reference[^]
Also the design seems flawed. Basically the whole thing is a mess, whoever wrote that C++ should not be writing production code.
led mike
|
|
|
|
|
Thanks Led mike for your reply.
I have also tried using a byte[] with the same result as below. Any suggestions would be appreciated.
// get the device serial numbers
[DllImport(@"C:\Documents and Settings\jbroderick\My Documents\Visual Studio 2005\Projects\\USB_D2XX_App\LogiComm2GD.dll",
EntryPoint = "ExGetDeviceSerialNumber",
ExactSpelling = false,
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool ExGetDeviceSerialNumber(long nDevice,
[MarshalAs(UnmanagedType.LPArray)] ref byte[] SerialNumber);
byte[] serByte = new byte[500];
ExGetDeviceSerialNumber(Device, ref serByte);
|
|
|
|
|
Hello
I'm not sure if this is the problem, but if I were you I'd give these points attention in this particular order:
1- Your nDevice parameter is a DWORD which is 32bits long, while in your C# code you pass a long which is 64bits long. You should try passing an int32 instead.
2- The second parameter is char* while you pass it IntPtr .. I suggest you pass a StringBuilder class instead. If you do you'd have to remove the unsafe keyword.
3- You are making your C# declaration a bit complex. Why?? Try this P/Invoke:
[DllImport(@"C:\Documents and Settings\jbroderick\My Documents\Visual Studio 2005\Projects\\USB_D2XX_App\LogiComm2GD.dll",
ExactSpelling = true,
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool ExGetDeviceSerialNumber(long nDevice, IntPtr ptr);
Notice that IMO the unsafe keyword is not necessary.
4- Calling another function from the exported function? I have doubts about this part.Try copy/paste the code in the second function into the first.
5- Comment these line for the sake of debugging, if they are not necessary:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
TRACE(_T("Entering LogiComm2GD ExGetDeviceSerialNumber\n"));
Also elaborate what does this macro do.
I hope this helps.
Regards
|
|
|
|
|
Thanks Nader,
I changed the declaration to:
// get the device serial numbers
[DllImport(@"C:\Documents and Settings\jbroderick\My Documents\Visual Studio 2005\Projects\USB_D2XX_App\LogiComm2GD.dll",
EntryPoint = "ExGetDeviceSerialNumber",
ExactSpelling = false,
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool ExGetDeviceSerialNumber(Int32 nDevice, StringBuilder sn);
Apparently passing in the Int32 instead of long fixed the problem. I was so focused on the char* conversion that I didn't pay attention to the long. Also, I was able to pass in the long as a ref and get back the number of devices without issue. So, I thought that was OK.
Thanks again!
|
|
|
|
|
Hi all,
I would like to add a control like a button to a form of another program.
i allready have the handle to that form.
how can i create a button and know when it is pushed and how do i add it to the other form.
can it be done with sendmessage?
Thanks,
Ran.
R.Z
|
|
|
|
|
You can create a window and set it's parent window, I'm not sure if it will work for another process, but it's worth a try.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I need to find out if the anti-virus software is running on my local machine.
Is there an API I can use to get the current state?
|
|
|
|
|
hi.i need to export data from datagrid to excel.can you please help me or give me link that i can refer from it
|
|
|
|
|
public string Convert(DataTable oDataTable, string directoryPath, string fileName)
{
string fullpath = "";
if (directoryPath.Substring(directoryPath.Length - 1,1) == @"\" ||directoryPath.Substring(directoryPath.Length - 1,1) == "/")
{
fullpath = directoryPath + fileName;
}
else
{
fullpath = directoryPath + @"\" + fileName;
}
StreamWriter SW;
SW=File.CreateText(fullpath);
StringBuilder oStringBuilder = new StringBuilder();
/*******************************************************************
* Start, Creating column header
* *****************************************************************/
foreach(DataColumn oDataColumn in oDataTable.Columns)
{
oStringBuilder.Append(oDataColumn.ColumnName + ",");
}
SW.WriteLine(oStringBuilder.ToString().Substring(0,oStringBuilder.ToString().Length - 1));
oStringBuilder.Length = 0;
/*******************************************************************
* End, Creating column header
* *****************************************************************/
/*******************************************************************
* Start, Creating rows
* *****************************************************************/
foreach(DataRow oDataRow in oDataTable.Rows)
{
foreach(DataColumn oDataColumn in oDataTable.Columns)
{
oStringBuilder.Append(oDataRow[oDataColumn.ColumnName] + ",");
}
SW.WriteLine(oStringBuilder.ToString().Substring(0,oStringBuilder.ToString().Length - 1));
oStringBuilder.Length = 0;
}
/*******************************************************************
* End, Creating rows
* *****************************************************************/
SW.Close();
return fullpath;
}
write the above code in a class file.
and write the below code in your button click event
string fileName = System.Guid.NewGuid().ToString().Replace("-","") + ".xls";
(new BLC.CSVConvertor()).Convert(Generatexlsheet() ,Server.MapPath("."),fileName);
Response.Redirect(fileName);
end of button click event
//below is the code for Generatexlsheet :
private DataTable Generatexlsheet()
{
String dbstr = BLC.Class1.Constring();
SqlConnection objconn = new SqlConnection(dbstr);
objconn.Open();
// SqlDataReader sqldr = null;
//
//
//
SqlCommand cmd = new SqlCommand("select * from employees",objconn);
// sqldr = cmd.ExecuteReader();
// int numbercols = sqldr.FieldCount;
SqlDataAdapter sqlda = new SqlDataAdapter(cmd) ;
DataTable dt = new DataTable();
sqlda.Fill(dt);
return dt;
|
|
|
|
|
I have drawn an ellipse without problem.
Now i want to fill the top part with a red color and the bottom part with a blue color and i have no clue how to do it. Can anyone help me?
|
|
|
|
|
u can try out
Graphics.FillPie() method
in this by specifying start ange and sweep angle u can fill pie in multicolors
rahul
|
|
|
|
|
Tnx for the reply but what i actualy need is a kind of elipse health meter (like in diablo if u know it)
|
|
|
|
|
I guess you could use a LinearGradientBrush for this.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I already posted this message but I can't see it anywhere. Hope this time will work.
I need to receive a message from a message queue within MSMQ. I open the que
ue with a VBA code and set the "body" of the msgqueue. From a C# i access th
e queue and get the body but an exception occur:
Data at the root level is invalid. Line 1, position 1.
What can I do? Here follows the sw:
vba
Sub write_a_message_()
Dim strFormatName As String
Dim qinfo As New MSMQQueueInfo
Dim qDest As MSMQQueue
Dim msg As New MSMQMessage
strFormatName = ".\private$\test_per_coda_1"
On Error GoTo ErrorHandler
qinfo.PathName = strFormatName
Set qDest = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
msg.Label = "Test Message"
msg.Body = "mickey goofy and donald"
msg.Send DestinationQueue:=qDest
qDest.Close
Exit Sub
ErrorHandler:
MsgBox "Error " + Hex(err.Number) + " was returned." _
+ Chr(13) + err.Description
end subthis works correctly
C# (where the problem occurs)
Message msg;
MessageQueue msgQ = new MessageQueue(@".\private$\test_per_coda_1");
msgQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
msg = msgQ.Receive();
System.Console.WriteLine("massaggio ricevuto :: {0}", msg.Id);
System.Console.WriteLine("massaggio ricevuto :: " + msg.Body.ToString());
the exception occurring at the very last instruction is ::
Data at the root level is invalid. Line 1, position 1.
Then I have used another VBA code that receive the message, I had no problem
with manipulation of the "body".
Many thanks in advance and best regards
rodrigo
|
|
|
|
|
I have C# Component say "SMSSender" and i setup a job in my sql server which call a DTS say "RecordFetcherAndSMS". This DTS fetch data from tables and create a message and want to call SMSSender.Send(string), a c# component. how i can do this.
Thanks
Zeeshan
|
|
|
|
|
Hello all, I have run into a problem... I am trying to call a method from a thread but it is throwing an exception...
System.NullReferenceException was unhandled<br />
Message="Object reference not set to an instance of an object."<br />
Source="System.Windows.Forms"
Here is the code:
public void zap_publish_listview(zap item)<br />
{<br />
if (listView_main.InvokeRequired)<br />
{<br />
SetZapPublishListview s = new SetZapPublishListview(zap_publish_listview);<br />
Invoke(s, new object[] { item });<br />
}<br />
else<br />
{<br />
int icon = getStatusIconNumber(item.zap_state.ToString());<br />
string name = item.zap_channel.ToString();<br />
string data = item.zap_state.ToString();<br />
<br />
ListViewItem lvItem = new ListViewItem("", icon);<br />
lvItem.SubItems.Add("ZAP: " + name);<br />
lvItem.SubItems.Add(data);<br />
lvItem.ToolTipText = item.ToString();<br />
lvItem.Group = listView_main.Groups[2];
<br />
ListViewItem old_item = listView_main.FindItemWithText("ZAP: " + name, true, 0);<br />
<br />
if (old_item.Index >= 0)<br />
{<br />
listView_main.Items.Insert(old_item.Index, lvItem);<br />
<br />
listView_main.Items.RemoveAt(old_item.Index);<br />
}<br />
else<br />
{<br />
listView_main.Items.AddRange(new ListViewItem[] { lvItem });<br />
}<br />
}<br />
}<br />
I have a similar method that updates a debug window... And that works fine... Can anyone help???
Thanks in advance,
Phil
"Rules are for the obedience of fools and the guidance of wise men"
|
|
|
|
|
Have you set a breakpoint to work out exactly which line throws the error ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello,
I would like to "display" a Word document in a winform.
I can access a word document via Microsoft.Office.Word but I could not find how
to put the word document in a WinForm.
I have managed to do it through IE but is there no way through ActiveX or anything?
What is the right way to do this ?
Thanks for your help
Robert
|
|
|
|
|
Dear friends,
My research is into 'Programmer's mood and their performance'. For my experiment I need your kind help. I need people who know any of the programming languages from C/C++, C#, java and VB.NET. This is an online experiment. The URL of the page is http://uxisfyp1.brunel.ac.uk/cspgiak . This experiment will only take 15 minutes of your precious time. Please also refer to as many people as you can who know computer languages. If you also want to be a part of a lucky draw at the end of experiment please enter you email at the results page. The prize is £20 Amazon vouchers or some programming book within that limit. We will send this book to ur address wherever you are.
Please follow the instructions carefully on the start page so that we can have accurate results. Please see the url again.
http://uxisfyp1.brunel.ac.uk/cspgiak
Copy or paste this URL in your browser address bar or click the link. Please Don't forget to refer it to others.
Thank you in advance.
Regards,
-- modified at 9:42 Friday 13th October, 2006
Iftikhar Ahmed Khan
Researcher,
School of Information Systems, Computing and Mathematics
Brunel University, Uxbridge, Middlesex UB8 3PH, UK
|
|
|
|
|
I was thinking of IP address, but people can change those easily.
What else is there that can't be changed? And where do i access it?
|
|
|
|