|
That did it lol. Thanks allot dude!!!!!
|
|
|
|
|
Hey.
I'm trying to create a client which responds to specific packets. The idea is, i'm going to have a large array of struct "packet" which stores information such as, the type of packet, the length of the sent packet, and a corresponding function it should call.
I know in C++ you can parse functions as parameters quite easily, or with some coding. However, in C# you need to use either delegate functions, or use the Reflection.MethodInfo methods.
The delegate functions may work, but the code to setup each row for my array would be extremely long and rather messy. I tried using the MethodInfo method instead, but the functions i'll be calling are marked with unsafe , and so my byte* parameter can't be passed through as an object in the object[] params :\
Is there any other method I could use to automate this system? Here's a snippet of what I mean:
_packetDB[++i] = new Packet() { type = 0x73, len = 11, func = "authok" };
Where "authok" is a function in a class foo . (When the packet is received, it will search for packet 0x73, and send the byte* data, the length into the function func )
Any help would be greatly appreciated.
Thanks
|
|
|
|
|
You should be using delegates. In general, its best to avoid the use of unsafe code or PInvoke, whenever possible. For your scenario, you should only need to do the following:
unsafe delegate void PacketHandler(byte* data, int length);
struct Packet
{
int type;
int len;
PacketHandler func;
}
void CreatePacket()
{
Packet packet = new Packet
{
type = 0x73,
len = 11,
func = AuthOK
};
}
unsafe void PacketProcessor(Packet packet)
{
byte* data = GetPacketData(packet.type);
packet.func(data, packet.len);
}
unsafe void AuthOK(byte* data, int len)
{
}
|
|
|
|
|
Oh! I always thought you had to define delegation functions as new DelegateFunction(FunctionToCall);
Thanks a lot, you're a life-saver. This should make the system work much, much better
|
|
|
|
|
Glad to be of service.
|
|
|
|
|
I have a list box in my app and i want it to autoscrol downward so it would always show the last item added.
Thank you
|
|
|
|
|
I think you have to do it manually. After adding an item to the end, call EnsureVisible[^].
|
|
|
|
|
didn't quite catch that... can u be more specific with the code?
|
|
|
|
|
Something like this:
int index = listBox.Items.Add("New item");
listBox.EnsureVisible(index);
[EDIT: Wait!! I was thinking of ListView instead of ListBox. Sorry! I'm looking into it right now.]
|
|
|
|
|
Found it!! Use the TopIndex[^] property of the ListBox control.
[EDIT: Oops, Luc beat me to it. ]
|
|
|
|
|
Hi,
whenever you change the number of items, do a myLB.TopIndex=myLB.Items.Count-1;
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:31 AM
|
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
After hours of searching I finally got this far and I'm not getting any errors
from this code. However I'm getting a black image. Is there something amiss here. I need to get access to this image regardless of wether it's visible on the physical montior or not and I'm assuming this may be the best way.
IHTMLElement test = (IHTMLElement)webBrowser1.Document.Images[i].DomElement;
IHTMLElementRender testRender = (IHTMLElementRender)test;
int hScreen = GDI.CreateCompatibleDC(this.CreateGraphics().GetHdc());
testRender.DrawToDC((IntPtr)hScreen);
int hCompDC = GDI.CreateCompatibleDC((IntPtr)hScreen);
int nWidth = webBrowser1.Document.Images[i].ClientRectangle.Width;
int nHeight = webBrowser1.Document.Images[i].ClientRectangle.Height;
int hBmp = GDI.CreateCompatibleBitmap((IntPtr)hScreen, nWidth, nHeight);
int hOld = GDI.SelectObject((IntPtr)hCompDC, (IntPtr)hBmp);
GDI.BitBlt((IntPtr)hCompDC, 0, 0, nWidth, nHeight, (IntPtr)hScreen, 0, 0, GDI.SRCCOPY);
GDI.SelectObject((IntPtr)hCompDC, (IntPtr)hOld);
GDI.DeleteDC((IntPtr)hScreen);
GDI.DeleteDC((IntPtr)hCompDC);
Image img;
pictureBox2.Image = Bitmap.FromHbitmap((IntPtr)hBmp);
|
|
|
|
|
Hi again,
I'm trying to add a little fuction to my app. I have a form for navigating through rows in a database table. All fields (textboxes) are readonly except one, which is a field I want the user to use to go directly to a certain row in the db. All this happens when to user presses the tab button and calls the Validated method of the textbox. How would I go about that exactly? textbox name is txtClientCode , the data in the table is loaded in m_dtClientInfo data table, and data adapter is m_daClientInfo. Database is a MS Access OleDB.
Anyone have a link to a good tutorial on querying and stuff in c#? I checked the articles overhere but didn't find anything! Thanks a lot for your patience with a newb
Yup, I'm a NEWB
|
|
|
|
|
So, when your user tabs out of that specific control, you want to fill the other text boxes with the data at that specific row index? Something like this could do it:
private void txtClientCode_Validated(object sender, EventArgs e)
{
int rowIndex = -1;
if(!int.TryParse(txtClientCode.Text, out rowIndex))
return;
DisplayClientInfo(rowIndex);
}
private void DisplayClientInfo(int rowIndex)
{
DataRow row = m_dtClientInfo.Rows[rowIndex];
txtFirstName.Text = (string)row["FirstName"];
} I hope this helps
|
|
|
|
|
I finally tried it out like this and it works:
private void txtClientCode_Validated(object sender, EventArgs e)
{
try
{
OleDbDataAdapter l_daCCSearch = new OleDbDataAdapter(
"SELECT * from ClientFile WHERE ClientCode = '" + txtClientCode.Text + "'", m_connection);
DataTable l_dtCCSearch = new DataTable();
l_daCCSearch.Fill(l_dtCCSearch);
txtClientCode.Text = l_dtCCSearch.Rows[0]["ClientCode"].ToString();
txtAdress.Text = l_dtCCSearch.Rows[0]["Adress"].ToString();
txtCity.Text = l_dtCCSearch.Rows[0]["City"].ToString();
txtCompanyName.Text = l_dtCCSearch.Rows[0]["CompanyName"].ToString();
txtContactName.Text = l_dtCCSearch.Rows[0]["ContactName"].ToString();
txtCountry.Text = l_dtCCSearch.Rows[0]["Country"].ToString();
txtEmail.Text = l_dtCCSearch.Rows[0]["Email"].ToString();
txtFax.Text = l_dtCCSearch.Rows[0]["FaxNumber"].ToString();
txtPhone.Text = l_dtCCSearch.Rows[0]["PhoneNumber"].ToString();
txtPostalCode.Text = l_dtCCSearch.Rows[0]["PostalCode"].ToString();
txtProvince.Text = l_dtCCSearch.Rows[0]["Province"].ToString();
txtTaxCode.Text = l_dtCCSearch.Rows[0]["TaxCode"].ToString();
rtxtNotes.Text = l_dtCCSearch.Rows[0]["Notes"].ToString();
}
catch (IndexOutOfRangeException)
{
DialogResult result;
result = MessageBox.Show("Aucune entrée correspondante à votre requête n'a été trouvée.", "Erreur");
if (result == DialogResult.OK)
{
this.ShowCurrentRecord();
}
}
}
Thanks a lot you pointed me in the right direction
Yup, I'm a NEWB
|
|
|
|
|
Hi
How can i make pdf from text file or put my text in pdf file ?
(in C#)
thank's for any help
|
|
|
|
|
There probably should be some componentes that allow you to do this easily, but since I don't know about any of them, I'll give you two ideas:
1. Install something like PDFCreator or CutePDF, and then from C# print to one of the PDF pseudo-printers as if you were printing to a regular printer. This will generate a prompt for the filename at runtime (and require an installation on the client), but depending on your particular circumstances it might or might not be acceptable.
2. Use fyiReporting[^], which I just learned about it. It's a reporting control that can output to a variety of formats, including PDF.
Both ideas are free.
You could also try Google[^] and find a lot of results
|
|
|
|
|
HI,
I need to control office excel document in run time.
The problem is that i don't know the office version that install on the target machine ( can be office 2007 or office 2003 ) and I don't know if and how to set the iterope to the office object in run time.
Thanks for the help.
|
|
|
|
|
I'm developing a new application C#, before some days i came to know about the reflector tool, so, i download this from http://www.aisto.com/roeder/dotnet/ afterwards i use it, it'll show all the exact class, method and code. But i want to know how to write the secure code against reflector tool. I mean i don't want to show my code in reflector tool, then how to protect my code against reflector too
|
|
|
|
|
That's the way .NET is. Since it is only bytecode and not native, it can be decompiled by Reflector.
Try googling for a code obfusctor[^] to find alternatives that will rename your methods and variables, so at least it is much more difficult to understand. This option might be expensive, tough.
|
|
|
|
|
You probably are looking for an obfuscator. See, for instance, this page [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Code is never secure. But for the best results, try Mono's full static compilation or the Remotesoft obfuscator. I don't know of any obfuscator that actually works, but they may exist.
|
|
|
|
|
Write it in C++
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|