|
HI folks,
I am trying to use this freakin old dll. I am new to this so i better ask question one by one.
Starting from struct.
the original struct looks like this:
typedef struct rfreaderstruct RFReader;
struct rfreaderstruct {
HANDLE fh;
OVERLAPPED in_ov;
OVERLAPPED out_ov;
unsigned char buffer[BUFSIZ]; /* Read buffer */
int bufferPoint; /* Number of bytes used from inBuf */
int bufferCount; /* The number of bytes in inBuf */
char nonCommandBuffer[BUFSIZ];
int nonCommandBufferPoint;
int nonCommandBufferEnd;
int mode;
int requestInProgress;
int requestOutProgress;
int pendingWrite;
int pendingRead;
RFMessage rfmsg;
int responseState;
unsigned int responseDataCount;
RFReader *next;
};
Overlapped and RFMessage are just plain struct which i am sure i got it right.
I converted it to this:
[StructLayout( LayoutKind.Sequential )]
internal struct RFReader
{
public const int BUFSIZ = 1000;
internal long fh;
internal OVERLAPPED in_ov;
internal OVERLAPPED out_ov;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=BUFSIZ)]
internal string buffer; /* Read buffer */
internal int bufferPoint; /* Number of bytes used from inBuf */
internal int bufferCount; /* The number of bytes in inBuf */
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=BUFSIZ)]
internal string nonCommandBuffer;
internal int nonCommandBufferPoint;
internal int nonCommandBufferEnd;
internal int mode;
internal int requestInProgress;
internal int requestOutProgress;
internal int pendingWrite;
internal int pendingRead;
internal RFMessage rfmsg;
internal int responseState;
internal uint responseDataCount;
[MarshalAs(UnmanagedType.LPStruct)]
internal RFReader next;
}
I got error on the last line, because this struct is like a linked-list node.
How can i get around this problem?
any help would be greatly appreciated.
|
|
|
|
|
Declare next as IntPtr, and use Marshal.PtrToStructure when you need the structure.
<br />
[StructLayout( LayoutKind.Sequential )] <br />
internal struct RFReader<br />
{<br />
...<br />
...<br />
internal IntPtr next;<br />
}<br />
<br />
RFReader reader = (RFReader)Marshal.PtrToStructure(rfreader.next, typeof(RFReader));<br />
<br />
IntPtr unmanagedBlock = Marshal.AllocHGlobal( Marshal.SizeOf(RFReader) );<br />
Marshal.StructureToPtr(nextReader, unmanagedBlock, true);<br />
rfreader.next = unmanagedBlock;<br />
_________________________________
Vote '1' if you're too lazy for a discussion
|
|
|
|
|
Hi Corinna thanks for the response.
The functions typically look like the following:
RFReader *rfOpenReader( const char *dev, int mode );
void rfCloseReader( RFReader *r );
void rfSetPortBaud( RFReader *reader, int setbaud );
can you show me how to declare it under DllImport?
Thanks,
|
|
|
|
|
frOpenReader:
//un-marshal the RFReader from the IntPtr
[DllImport("anything.dll")]
private static extern IntPtr rfOpenReader(String dev, Int32 mode);
rfCloseReader:
//Both declarations are valid.
//You may try the second one, but without any guarantee.
[DllImport("anything.dll")]
private static extern void rfCloseReader(IntPtr r);
[DllImport("anything.dll")]
private static extern void rfCloseReader(RFReader r);
rfSetPortBaud:
[DllImport("anything.dll")]
private static extern void rfSetPortBaud(IntPtr reader, Int32 setbaud);
[DllImport("anything.dll")]
private static extern void rfSetPortBaut(RFReader reader, Int32 setbaud);
_________________________________
Vote '1' if you're too lazy for a discussion
|
|
|
|
|
Hi Corinna,
Thanks for the help.
I am totally new on this one. I cannot make it to work though.
Once I declare the functions, I don't quite know how to call those functions for now
For example to use rfOpen, in my C# function I write it like this:
public void rfOpenReader ()
{
string READER_DEVICE = "COM9";
reader = (RFReader)Marshal.PtrToStructure(rfOpenReader( READER_DEVICE, RF_MODE_NONBLOCKING ), typeof(RFReader));
}
is this the way to do it?
I got null exception.
Thanks,
|
|
|
|
|
Hi guys
I invoke statusbar.Refresh() method. I think it should call statusbar's "DrawItem" event sequently. But it doesn't. Why? By the way, other controls seem to have similar cases.
Thanks a lot.
vigorous
|
|
|
|
|
Hey Guys
Does anyone know how Microsoft come up with the colors they use in Office 2003 that are consistent with the selected color scheme when using the Windows XP Style buttons/windows.
The only way i've been able to mimic them is to take screen shots and work the colors out from that, not very scientific!
Any ideas greatly appreciated.
Thanks
Tom
|
|
|
|
|
|
Yea, I'm using it to determine the actual colour scheme in use, and changes, but it does not contain the colors that Office Uses. I have a feeling they are hard coded into Office but I want to confirm.
Thanks
Tom
|
|
|
|
|
hi all!
I have a problem but i don't know reason why. My datagrid somtimes display an red X shape in my application. I don't know how to fix. Can you help me for this problem?
Thank you very much!
Đào Ngọc Hào! Hi How Are You?
|
|
|
|
|
The red X gives us the clue that your using the ASP.NET version in a webpage. Your question would be better handled in the ASP.NET Forum, not the C# Forum.
In either case, this usually means that there is a problem with the properties your set in the DataGrid or there is a problem with the DataSet you bound the grid to.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
I think I've posted it correctly because my problem happened in window application, not in asp.net. Anyway your anwser is good. Do you know something else about my problem ? Or it's the same answer which you've posted.
Finally, Thank you for your helping!
Nguyen Thanh Tu
Đào Ngọc Hào! Hi How Are You?
|
|
|
|
|
Without seeing your code, there's nothing we can tell you about the problem, other than "there's a problem!"
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It is a memory error. When you do something, For example,
public ArrayList GetResult()
{
ArrayList list = new Arraylist();
list.Add("1");
list.Add("2");
ArrayList list1 = new Arraylist(); list1 = list;
list.Clear();
return list1;
}
In C#, It will tirgger a memory error.
|
|
|
|
|
Another idea:
Are you using custom ColumnStyles? If yes one of those could have errors in its Paint method.
|
|
|
|
|
Hi everyone,
I'm having a strange problem with DES encryption in .NET (DESCryptoServiceProvider). I'm using 3 implementations of DES, one in .NET, another in JavaScript and one in Java.
I'm encrypting the same short string with the same 8-byte key, using ECB mode. ALl implementations will return a 16-byte cipher text (two 64 bit blocks). The problem is that the first 64-bit block of the cipher text is the same for all three implementations, but the second 64-bit block is different in C#. THe same thing happens when using CBC with initialization vector.
I don't think that there is a problem with my C# code, another C# sample I have tried returned the same results, but here is the code I'm using. I have no clue what to do
MemoryStream memStream=new MemoryStream(100);
DES des=new DESCryptoServiceProvider();
des.Mode=CipherMode.ECB;
CryptoStream encStream = new CryptoStream(memStream, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);
encStream.Write(Encoding.UTF8.GetBytes(strMessage), 0, strMessage.Length);
encStream.Close();
byte[] desEncrypted=memStream.GetBuffer();
string strEncrypted=BitConverter.ToString(desEncrypted, 0, i);
memStream.Close();
Thanks for any ideas in advance,
Rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
OK I figured that out. This is so ridiculous, and it happens to me all the time. I spent at least 2 hours with it yesterday in the evening, and now I post a question to the C# forum and voila, in the next 5 minutes I find that it has been caused by a different PaddingMode - .NET uses PKCS7 by default, whereas both JavaScript and Java implementations use zeros.
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
Hi all,
I have this Error message when i try to run debug on my program "The Machine Debug Manager Service is disabled". Is this caused by the program being too big or is there an option to enable the debug. Please help.
|
|
|
|
|
I was added the controls in the DataGrid at the run time using TemplateColumn class. I was added Two Columns, one coloum controls is DropDownList and other one is TextBox. I need , While i am clicking the DropDownList at runtime, the corresponding SelectedItem to be display in TextBox . But i couldn't get it.
how i get the data from DropDownList? if you have send me the sample coding.
|
|
|
|
|
There were many controls in my form. When I clicked one button,then showdialog. The form had flash obviously. How to do it?
Thanks.
|
|
|
|
|
Huh?
Could you please tell us what you want in a different way? I don't think anyone can guess what you want from this question. In case your english is not good enough please try to ask someone for help.
mav
|
|
|
|
|
I put many controls in form. When call showdialog() method, the form flash obviously. the control been show one by one. In VC#.net, has some method that ListBox's redraw method in MFC?
How to do it?
Thanks.
|
|
|
|
|
What has a flashing form to do with ListBox redraw?
If your problem is that a Form's painting gets slow with _many_ controls, well, that's the way it is. For a sane number of controls there's no flashing.
How many controls are on the Form?
I'd suggest you re-design the UI to have less controls. If .NET has problems drawing so many controls your users will have problems handling so many controls.
Or you try to inherit from Form and perform double buffering yourself, but I'm not sure if this will work.
mav
|
|
|
|
|
Perhaps your dynamically adding the controls to the form yourself rather than having used the form designer to place the controls? If so, may sure you call SuspendLayout() before you start adding the controls, and ResumeLayout(false) when you're done.
We have a situation where our form took a long time to 'paint' the controls, even with suspending and resuming the layout. After lots of messing, we found that filling the form with a panel (dock = Fill), making the panel .Visible = false, adding all of the controls into the panel, and then making the panel .Visible = true looked much better for the user - and took less time to execute (essentially a form of the double buffering that mav.northwind mentioned).
|
|
|
|
|
How do u handle export/import features in custom application?
use DTS Packages? How to import Excel Data into my application by using DTS? Any Idea? I'm using C#, SQL Server 2000.
|
|
|
|