Jump to content
Xtreme .Net Talk

jo0ls

Avatar/Signature
  • Posts

    42
  • Joined

  • Last visited

jo0ls's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. To pad the bytes in the hex string you can use: Dim sb As New System.Text.StringBuilder For Each b As Byte In result sb.Append(Convert.ToString(b, 16).PadLeft(2, "0"c).ToUpper) Next
  2. I just thought I'd check my results with a big file. Looks like the code in the link PlausiblyDamp gave chokes with big files. Mine can chug through a 330MB file in 10secs on a slowish laptop, I gave up on the other program after a minute or two. A smaller file took mine 50ms, took the other >6000ms. I guess the difference is that I'm not using arrays (so the UIntegers are all on the stack), calling out to methods, or changing Types. The results tallied. md4.zip
  3. I get the same results as the java code with the following VB.Net code. I had to remove the integer overflow checks in the advanced compile options for the project. Note - you have to cast the bytes to a larger type before shifting them left, hence the CUInt. I'll try and tidy it up some. Public Sub Transform(ByVal bytes() As Byte, ByVal i As Integer) Dim x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 As UInteger x0 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x1 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x2 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x3 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x4 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x5 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x6 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x7 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x8 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x9 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x10 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x11 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x12 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x13 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x14 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 i += 4 x15 = (bytes(i) And &HFFUI) Or (bytes(i + 1) And &HFFUI) << 8 Or (bytes(i + 2) And &HFFUI) << 16 Or CUInt(bytes(i + 3)) << 24 Dim aa, bb, cc, dd As UInteger aa = a bb = b cc = c dd = d aa += ((bb And cc) Or ((Not bb) And dd)) + x0 aa = aa << 3 Or aa >> -3 dd += ((aa And bb) Or ((Not aa) And cc)) + x1 dd = dd << 7 Or dd >> -7 cc += ((dd And aa) Or ((Not dd) And bb)) + x2 cc = cc << 11 Or cc >> -11 bb += ((cc And dd) Or ((Not cc) And aa)) + x3 bb = bb << 19 Or bb >> -19 aa += ((bb And cc) Or ((Not bb) And dd)) + x4 aa = aa << 3 Or aa >> -3 dd += ((aa And bb) Or ((Not aa) And cc)) + x5 dd = dd << 7 Or dd >> -7 cc += ((dd And aa) Or ((Not dd) And bb)) + x6 cc = cc << 11 Or cc >> -11 bb += ((cc And dd) Or ((Not cc) And aa)) + x7 bb = bb << 19 Or bb >> -19 aa += ((bb And cc) Or ((Not bb) And dd)) + x8 aa = aa << 3 Or aa >> -3 dd += ((aa And bb) Or ((Not aa) And cc)) + x9 dd = dd << 7 Or dd >> -7 cc += ((dd And aa) Or ((Not dd) And bb)) + x10 cc = cc << 11 Or cc >> -11 bb += ((cc And dd) Or ((Not cc) And aa)) + x11 bb = bb << 19 Or bb >> -19 aa += ((bb And cc) Or ((Not bb) And dd)) + x12 aa = aa << 3 Or aa >> -3 dd += ((aa And bb) Or ((Not aa) And cc)) + x13 dd = dd << 7 Or dd >> -7 cc += ((dd And aa) Or ((Not dd) And bb)) + x14 cc = cc << 11 Or cc >> -11 bb += ((cc And dd) Or ((Not cc) And aa)) + x15 bb = bb << 19 Or bb >> -19 aa += ((bb And (cc Or dd)) Or (cc And dd)) + x0 + &H5A827999UI aa = aa << 3 Or aa >> -3 dd += ((aa And (bb Or cc)) Or (bb And cc)) + x4 + &H5A827999UI dd = dd << 5 Or dd >> -5 cc += ((dd And (aa Or bb)) Or (aa And bb)) + x8 + &H5A827999UI cc = cc << 9 Or cc >> -9 bb += ((cc And (dd Or aa)) Or (dd And aa)) + x12 + &H5A827999UI bb = bb << 13 Or bb >> -13 aa += ((bb And (cc Or dd)) Or (cc And dd)) + x1 + &H5A827999UI aa = aa << 3 Or aa >> -3 dd += ((aa And (bb Or cc)) Or (bb And cc)) + x5 + &H5A827999UI dd = dd << 5 Or dd >> -5 cc += ((dd And (aa Or bb)) Or (aa And bb)) + x9 + &H5A827999UI cc = cc << 9 Or cc >> -9 bb += ((cc And (dd Or aa)) Or (dd And aa)) + x13 + &H5A827999UI bb = bb << 13 Or bb >> -13 aa += ((bb And (cc Or dd)) Or (cc And dd)) + x2 + &H5A827999UI aa = aa << 3 Or aa >> -3 dd += ((aa And (bb Or cc)) Or (bb And cc)) + x6 + &H5A827999UI dd = dd << 5 Or dd >> -5 cc += ((dd And (aa Or bb)) Or (aa And bb)) + x10 + &H5A827999UI cc = cc << 9 Or cc >> -9 bb += ((cc And (dd Or aa)) Or (dd And aa)) + x14 + &H5A827999UI bb = bb << 13 Or bb >> -13 aa += ((bb And (cc Or dd)) Or (cc And dd)) + x3 + &H5A827999UI aa = aa << 3 Or aa >> -3 dd += ((aa And (bb Or cc)) Or (bb And cc)) + x7 + &H5A827999UI dd = dd << 5 Or dd >> -5 cc += ((dd And (aa Or bb)) Or (aa And bb)) + x11 + &H5A827999UI cc = cc << 9 Or cc >> -9 bb += ((cc And (dd Or aa)) Or (dd And aa)) + x15 + &H5A827999UI bb = bb << 13 Or bb >> -13 aa += (bb Xor cc Xor dd) + x0 + &H6ED9EBA1UI aa = aa << 3 Or aa >> -3 dd += (aa Xor bb Xor cc) + x8 + &H6ED9EBA1UI dd = dd << 9 Or dd >> -9 cc += (dd Xor aa Xor bb) + x4 + &H6ED9EBA1UI cc = cc << 11 Or cc >> -11 bb += (cc Xor dd Xor aa) + x12 + &H6ED9EBA1UI bb = bb << 15 Or bb >> -15 aa += (bb Xor cc Xor dd) + x2 + &H6ED9EBA1UI aa = aa << 3 Or aa >> -3 dd += (aa Xor bb Xor cc) + x10 + &H6ED9EBA1UI dd = dd << 9 Or dd >> -9 cc += (dd Xor aa Xor bb) + x6 + &H6ED9EBA1UI cc = cc << 11 Or cc >> -11 bb += (cc Xor dd Xor aa) + x14 + &H6ED9EBA1UI bb = bb << 15 Or bb >> -15 aa += (bb Xor cc Xor dd) + x1 + &H6ED9EBA1UI aa = aa << 3 Or aa >> -3 dd += (aa Xor bb Xor cc) + x9 + &H6ED9EBA1UI dd = dd << 9 Or dd >> -9 cc += (dd Xor aa Xor bb) + x5 + &H6ED9EBA1UI cc = cc << 11 Or cc >> -11 bb += (cc Xor dd Xor aa) + x13 + &H6ED9EBA1UI bb = bb << 15 Or bb >> -15 aa += (bb Xor cc Xor dd) + x3 + &H6ED9EBA1UI aa = aa << 3 Or aa >> -3 dd += (aa Xor bb Xor cc) + x11 + &H6ED9EBA1UI dd = dd << 9 Or dd >> -9 cc += (dd Xor aa Xor bb) + x7 + &H6ED9EBA1UI cc = cc << 11 Or cc >> -11 bb += (cc Xor dd Xor aa) + x15 + &H6ED9EBA1UI bb = bb << 15 Or bb >> -15 a += aa b += bb c += cc d += dd End Sub
  4. There's a long instead of an integer in one of the api definitions. My version attached. NativeMethods.zip
  5. You didn't create any new structures, and you didn't size the arrays. ' size the array to hold 10 items: struct = New structTest(9) {} ' add ten items For i As Integer = 0 To 9 ' Create a new struct struct(i) = New structTest ' assign some values struct(i).varA = "struct" & i.ToString struct(i).varB = i ' create a new array and put in one short string: item A, B, C etc... struct(i).varC = New String() {"item" & Chr(Asc("A"c) + i)} Next
  6. see the readme (or just read it here ) There's no harm using it, and it wil be more like the XNA than the older directX. But very few people are using it, and the documentation is poor, and microsoft don't recommend using it in the msdn forums - they say just wait for the XNA beta. I don't know the answer to the pointer question.
  7. The Managed DirectX 2.0 stuff is deprecated, it is not going to be released. The work done on it will become part of the XNA framework. Use the older version for now.
  8. Calling invalidate fires the paint event - so you want to do it when you need to redraw the cursor. Calling invalidate(rec) fires the paint event, any drawing in the paint event that is outside the rectangle is just ignored. So: do all painting in the paint event. Note: Each time you draw the cursor you need to invalidate the previous position of the cursor so that the background is refreshed, and invalidate the area for the new position so that it is drawn. So you could invalidate twice, or invalidate a rectangle that encompasses both the old and new cursor bounds. It is simpler code in this case to use a Region instead of a Rectangle, as it has methods to combine areas: Private x, y As Integer Private lastCursorBounds As Rectangle Sub New() InitializeComponent() Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True) Me.UpdateStyles() x = Windows.Forms.Cursor.Position.X y = Windows.Forms.Cursor.Position.Y lastCursorBounds = New Rectangle(x, y, 21, 21) End Sub Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove x = e.X y = e.Y ' So we need to invalidate the previous area: Dim areaToInvalidate As New Region(lastCursorBounds) ' And the new area (not sure why this needs to be 21!) Dim newCursorBounds As New Rectangle(e.X, e.Y, 21, 21) areaToInvalidate.Union(newCursorBounds) Invalidate(areaToInvalidate) lastCursorBounds = newCursorBounds End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawEllipse(Pens.Red, x, y, 20, 20) End Sub
  9. The trackbar has a minimum height that doesn't listen to the minimumSize property - you can't resize height. You could make your own trackbar. The other way is to have some of the trackbar lying outside the groupbox. But the groupbox 3D boundary is drawn inside its bounds, so the trackbar obscures it... So... add a panel to a groupbox, resize it so it just fits, and set it to anchor left, right, top, bottom then add the trackbar to the panel... The panel will clip the trackbar, so the groupbox won't be obscured.
  10. Ho hum, was thinking of this as I was tinkering around with structured storage. The properties for word docs are stored in structured storage and there is one called Security. You can read these properties from word - but you have to open the document first ... catch 22. So, I implemented all the stuff you need to read the properties off without word (IPropertyStorage, IPropertySetStorage), and can now read the security property. Which is great - so long as the user hasn't checked the box to encrypt the document properties !!! arrrgh. Oh well. It is set to 1 when the doc is protected - and you can read it. When the properties are scrambled, it appears as if there are no properties in the summaryInfo and documentInfo property sets. you could use this I suppose - but there is the possiblity of identifying documents as protected that aren't - they just have no properties. Attached is the not so great Property reader (vb2005) (I'm making another one that will read all the properties and let you change them). Here is the trial and error approach - which is far more sensible... Imports System.Runtime.InteropServices Imports Microsoft.Office.Core Imports Word = Microsoft.Office.Interop.Word Public Class Form1 Private Function IsDocProtected(ByVal filename As String) As Boolean Dim wordApp As Word.Application = Nothing Dim doc As Word.Document = Nothing Dim isProtected As Boolean = False Try wordApp = New Word.Application ' open: readonly, open/write password = "Wibble", show word = false doc = wordApp.Documents.Open(filename, True, , , "Wibble", , , "Wibble", , , , False) doc.Close(False) Catch ex As System.Runtime.InteropServices.COMException ' wrong password error: If ex.ErrorCode = &H800A1520 Then isProtected = True Finally GC.Collect() GC.WaitForPendingFinalizers() wordApp.Quit() Dim referenceCount As Integer = 0 Do referenceCount = Marshal.ReleaseComObject(wordApp) Loop Until referenceCount < 1 wordApp = Nothing End Try Return isProtected End Function Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ofd As New OpenFileDialog ofd.Title = "Select office document to open" Dim result As Windows.Forms.DialogResult result = ofd.ShowDialog If result = Windows.Forms.DialogResult.OK Then If ofd.FileName IsNot Nothing Then Me.Text = IsDocProtected(ofd.FileName) End If End If End Sub End Class DocInfo.zip
  11. That requires going via a string, to avoid that step you can just move the high byte into position in a new short, and Or with the low byte: Dim bytes As Byte() = {&H69, &H87} ' little endian conversion, big endian byte order: Console.WriteLine(BitConverter.IsLittleEndian) Console.WriteLine(BitConverter.ToUInt16(bytes, 0)) ' Bitconverter is fine, if you reverse the byte order ' (could use array.reverse) Console.WriteLine(BitConverter.ToUInt16(New Byte() {bytes(1), bytes(0)}, 0)) ' or manipulate the bits. Console.WriteLine((CType((bytes(0)), UInt16) << 8) Or bytes(1)) byte[] bytes = {0x69, 0x87}; Console.WriteLine(BitConverter.IsLittleEndian); Console.WriteLine(BitConverter.ToUInt16(bytes, 0)); Console.WriteLine(BitConverter.ToUInt16(new byte[] {bytes[1], bytes[0]}, 0)); Console.WriteLine(((UInt16)(bytes[0] << 8) | bytes[1])); or you could use: System.Net.IPAddress.NetworkToHostOrder to switch the endian-ness, but only for int16, int32, int64
  12. You could move the code into the Form_Click event: Button Event set the Boolean CountingClicks to true Form_Click Event If CountingClicks if numClicks = 0 get x1, y1 numClicks += 1 elseif numClicks = 1 get x2, y2 grab screen CountingClicks = false numClicks = 0 end if end if But, if you want to allow the user to click somewhere off the form, then it is not going to work (there is no event to catch a mouse click off the form). I think you are then into the realms of p/invoke and mouse hooks.
  13. I'd probably start by looking at the source from opennetcf, to see how they do it: http://www.opennetcf.org/SourceBrowse/browse.aspx?f=C:/sites/OpenNETCF.org/wwwroot/Source/OpenNETCF.Net the adapter class looks interesting.
  14. <DllImport("ole32.dll")> _ Private Shared Function OleSetClipboard(ByVal theDataObject As IDataObject) As Integer End Function and send nothing. Don't know a .Net way...
  15. RegisterDeviceNotification would let you find out when a USB device was plugged in, you send the forms handle and get alerted via WM_DEVICECHANGE messages. You don't need to register for notifications of volume changes or port changes - it happens automatically. So you can actually skip registering. To read the message then: override WndProc, and check for WM_DEVICECHANGE. The Wparam will tell you if it is an arrival or removal. The LParam is a structure that depends on the type of DEVICECHANGE that is occuring. The start of the structure is the same for all device types, DEV_BROADCAST_HDR. The header tells us the device type, so if it is a volume then we can convert Lparam to a DEV_BROADCAST_VOLUME structure. This structure has a field that stores the device(s) drive letter. See attached c#, or bad vb.net. Note, you can use a NativeWindow class and handle its WndProc instead of the form's one. Makes it tidier... If you need to test to see if it is a usb device (just detecting volumes will detect CDs etc...), then it gets complicated. this is a good starting point. I've got some working vb.net code that will identify all usb removable disk drives, and get the "Friendly Name" and path. Vb.net RegisteDeviceNotification example Vol Arrival.zip
×
×
  • Create New...