|
Y readed and works fine
my C# Code:
public delegate void updatevalores(string dato);<br />
private void actualizarv(string datos) {<br />
if (this.InvokeRequired)<br />
{<br />
this.Invoke(new updatevalores(actualizarv),new object[]{dato});<br />
return;<br />
}<br />
listBox1.Items.Add(dato.ToString());<br />
}
Thanks for all
|
|
|
|
|
I am trying to pass a structure to unmanaged C and the unmangaed C returns an error because it thinks a value within the struture is set to a different value then the c# has set it to prior to passing it to the unmanaged c. I dont't have access to the C code.
[StructLayout(LayoutKind.Sequential)]<br />
public struct PASSTHRU_MSG<br />
{<br />
public UInt32? ProtocolID;<br />
public UInt32? RxStatus;<br />
public UInt32? TxFlags;<br />
public UInt32? Timestamp;<br />
public UInt32? DataSize;<br />
public UInt32? ExtraDataIndex;<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4128)] <br />
public byte[] Data;<br />
}<br />
<br />
[DllImport("CARDA432.DLL", EntryPoint = "PassThruStartMsgFilter", ExactSpelling =true)]<br />
public static extern UInt32 PassThruStartMsgFilter(UInt32 ChannelID, UInt32 FilterType, ref PASSTHRU_MSG pMaskMsg, ref PASSTHRU_MSG pPatternMsg, ref PASSTHRU_MSG pFlowControlMsg,ref UInt32 pMsgID);<br />
<br />
MaskMsg.Data = new byte[4128];<br />
MaskMsg.ProtocolID = 5;<br />
MaskMsg.DataSize = 4;<br />
MaskMsg.Data[0] = 0xff;<br />
MaskMsg.Data[1] = 0xff;<br />
MaskMsg.Data[2] = 0xff;<br />
MaskMsg.Data[3] = 0xff;<br />
PatternMsg.Data = new byte[4128];<br />
PatternMsg.ProtocolID = 5;<br />
PatternMsg.DataSize = 4;<br />
PatternMsg.Data[0] = 0x00;<br />
PatternMsg.Data[1] = 0x00;<br />
PatternMsg.Data[2] = 0x07;<br />
PatternMsg.Data[3] = 0xE8;<br />
<br />
FlowMsg.Data = new byte[4128];<br />
FlowMsg.ProtocolID = 5;<br />
FlowMsg.TxFlags = 0;<br />
FlowMsg.DataSize = 0x04;<br />
FlowMsg.Data[0] = 0x00;<br />
FlowMsg.Data[1] = 0x00;<br />
FlowMsg.Data[2] = 0x07;<br />
FlowMsg.Data[3] = 0xE8;<br />
<br />
if ((status = PassThruStartMsgFilter(ChannelID, FLOW_CONTROL_FILTER, ref MaskMsg, ref PatternMsg, ref FlowMsg, ref FilterID)) != STATUS_NOERROR)<br />
{<br />
status = PassThruGetLastError(serror);<br />
MessageBox.Show(serror.ToString());<br />
}<br />
the function returns an error stating that the MaskMsg.ProtocolID = 1 (the code is expecting 5 as set by the c# code) and I can't figure out why? There must be an issue with the memory getting overwritten or the "pointer" not being referenced properly.
|
|
|
|
|
It doesn't matter what I set the ProtocolID to the code always errors out with ProtocolID =1.
The original C-code
typedef struct<br />
{<br />
unsigned long ProtocolID;<br />
unsigned long RxStatus;<br />
unsigned long TxFlags;<br />
unsigned long Timestamp;<br />
unsigned long DataSize;<br />
unsigned long ExtraDataIndex;<br />
unsigned char Data[4128];<br />
} PASSTHRU_MSG;<br />
<br />
long PassThruStartMsgFilter(unsigned long ChannelID, unsigned long FilterType, PASSTHRU_MSG *pMaskMsg, PASSTHRU_MSG *pPatternMsg, PASSTHRU_MSG *pFlowControlMsg, unsigned long *pMsgID); <br />
<br />
<br />
-- modified at 19:44 Thursday 11th October, 2007
|
|
|
|
|
I have never seen a nullable type being passed to unmanaged code, and I don't expect
it to work like that, so first thing to do is drop all the question marks.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
It doesn't seem to matter if the other variables are null or defined. And other api calls require the PASSTHRU_MSG to be null.
I have had the questions marks there and not and still fail with the same error.
Thanks.
|
|
|
|
|
Hi,
an Uint32 is a value type, taking 4 bytes of memory inside the struct.
an Uint32? is a reference type, taking a 4B (or 8B on Win64) pointer inside the struct
and an object on the heap, quite different from what your C code expects.
So, yes removing the questions marks is a necessary step towards a solution.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Fair enough. I'll give it another shot.
|
|
|
|
|
Thanks. Removing the ? seems to be working now. This is much appreciated. Sorry for doubting you. Nice Job.
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I have a gridview with 2 bound columns and 1 template column(chkSalbud).
The bound columns are the Id and Name.
In the gridView_updating event,
protected void GridView_Updating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView.Rows[e.RowIndex];
if (row != null)
{
int chkSalbud = Convert.ToInt16((((CheckBox)row.FindControl("editchkSalbud")).Checked));
???? [here similarly i need to find the bound columns id and name values. the name field is readonly and the id field is visible=false]
}
}
Am trying to avoid keeping the values in dataset. Should I use template column for id and name or can I do with bound column itself?
Please help me.
Thanks
|
|
|
|
|
Hey!
I need a timer for my program that can start counting when I tell it to and then stop when I tell it to. After it's stopped I want to write the number of seconds counted before it was stopped.
Well, I'll try to explain better what I mean with the following code:
<br />
START COUNTING HERE<br />
<br />
while(whatever)<br />
{<br />
whatever<br />
}<br />
<br />
STOP COUNTING HERE<br />
<br />
WRITE HOW MANY SECONDS IT TOOK<br />
<br />
--
Joplinazz
--
|
|
|
|
|
Well - you could do this without using a timer at all. Have a button on your form, which writes the time that the button was pressed to a member variable of type DateTime. Then have a second button that takes the time that the button was pressed away from DateTime.Now . That's how long it took to run.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Just a standard System.Windows.Forms.Timer sounds like what you need. Set the interval to 1 second, and have an incremental integer adding for every cycle the timer takes.
static System.Windows.Forms.Timer tmr = new System.Windows.Forms.Timer();
int iCurrentSeconds = 0;
private void NotificationConfig_Load(object sender, EventArgs e)
{
tmr.Tick += new EventHandler(TimerEventProcessor);
tmr.Interval = 1000;
tmr.Start();
}
private void TimerEventProcessor(object obj, EventArgs e)
{
iCurrentSeconds++;
Console.Writeline("Timer has been running for {0} seconds!", iCurrentSeconds);
}
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Thank you both for your answers, I think this will solve the problem
--
Joplinazz
--
|
|
|
|
|
You bet, happy to help!
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Why do you actually need to do this? It seems a lot more complicated than getting the difference between two datetime objects. It's certainly a lot more code - which while not always a bad thing, certainly doesn't adhere to the KISS principal.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: Why do you actually need to do this? It seems a lot more complicated than getting the difference between two datetime objects. It's certainly a lot more code - which while not always a bad thing, certainly doesn't adhere to the KISS principal.
I understand what you are saying about the K.I.S.S. principal. From his short explanation he mentioned a while loop. I assumed that he was wanting to preform an operation multiple times within the timer, until a certain condition had been met. The most simple way to do that to me seemed to be a timer preforming the operations, and when the condition was met, do a timer.Stop().
Maybe I am missing something though, is it as efficent to do the above with a TimeSpan object?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Justin Perez wrote: I assumed that he was wanting to preform an operation multiple times within the timer, until a certain condition had been met. The most simple way to do that to me seemed to be a timer preforming the operations, and when the condition was met, do a timer.Stop().
Fair point. I read it as he wanted to get the difference between two points in time (and that was it), but you could well be right. Although my method would still work for that case because the only processing that occurs is at the button presses.
Justin Perez wrote: Maybe I am missing something though, is it as efficent to do the above with a TimeSpan object?
There's a bit of a gotcha with a TimeSpan in that you can't go over a day. Now I know it's unlikely, but it is vaguely possible that he started the process off and then left to go on holiday for a couple of weeks. When he gets back, if he's using the DateTime it will work - a TimeSpan and it'll crash.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: There's a bit of a gotcha with a TimeSpan in that you can't go over a day. Now I know it's unlikely, but it is vaguely possible that he started the process off and then left to go on holiday for a couple of weeks. When he gets back, if he's using the DateTime it will work - a TimeSpan and it'll crash.
That's an interesting point you made. I am doing a couple bug fixes on an application right now. The application is an In/Out status application that keeps track of which employees are in the building. Lets say John Doe comes into the building at 9:45 PM on Monday October 8th. He leaves the building at 3:30 AM on Tuesday October 9th. I have 2 DateTime objects, and I try to do a TimeSpan between the 2. Are you saying that I will get an error when I try to get the span?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
OK - slap me round the head with a wet kipper. I'm just plain wrong here. I've just had a quick look and the TimeSpan class does indeed allow you to use a greater range. So - saying this, I'd go with the TimeSpan object.
Thanks for making me go and have a look again. Worth a 5 for making me look an idiot.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: OK - slap me round the head with a wet kipper. I'm just plain wrong here. I've just had a quick look and the TimeSpan class does indeed allow you to use a greater range. So - saying this, I'd go with the TimeSpan object.
Thanks for making me go and have a look again. Worth a 5 for making me look an idiot.
That's why I love codeproject. Bouncing around ideas with other developers really is great!
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Justin Perez wrote: That's why I love codeproject.
It certainly is. It's the cut and thrust of the intellectual debate that goes on here.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
No kipper around, sorry.
A wet rain cheque will have to do for now.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
You may want to consider using Stopwatch [^] instead. (Requires .NET 3.0).
/ravi
|
|
|
|
|
I understand how to draw, for say a rectangle, but where do I draw it at, as in is there some event? Or...? Thanks to the same 4 or so people that help out. And anyone else, in advance.
|
|
|
|