|
Like most people, I have some bad habits.
I will decorate the fields with MarshalAs even if it is not needed. It is usually an indication that my first attempt failed (i.e. I copied the declaration for PInvoke.com and it was incorrect) and then I checked the un-managed declaration for the expected type or that I wrote the declaration myself based on the specification.
You are correct concerning the U4 usage. It is not needed when using a UInt32 for a dword field.
see: Blittable and Non-Blittable Types
|
|
|
|
|
Got you. Thanks for the learning. I will say that data typing can be pretty difficult. All it takes is screwing up a ByRef for a ByVal and not figuring it out until an hour later. So I can thoroughly understand using marshaling just to be on the safe side. I wish they would simplify the syntax, however. Like, maybe, "U4ToUInt32(parameter name)". That way, a quick marshaling could be done without having to worry about a long verbose syntax, let alone trying to remember the path of the namespace.
|
|
|
|
|
Quote: ... let alone trying to remember the path of the namespace. Organize your code and move all interop to a separate file and set the proper Imports statements at the top of the code.
Then to really mess with those who read your code but never the MSDN language specification , set an alias for the Imports.
Imports sri = System.Runtime.InteropServices
Imports lok = System.Runtime.InteropServices.LayoutKind
Imports umt = System.Runtime.InteropServices.UnmanagedType
<sri.StructLayout(lok.Sequential)> _
Public Class Class1
<sri.MarshalAs(umt.U4)> Public Fred As UInt32
End Class
Just be careful with the aliasing, there is glitch in their implementation that lets you alias all the way to the class/type name. That is just plain wrong as discussed here.[^]
|
|
|
|
|
I certainly would not like to have to go looking for the an alias, except when lines start getting too long and too numerous. That means I have to jump all over the place to find it, and then I might lose my train of thought. That's true of my own code, too, especially after having not looked at it in ages.
That one example reminds me of someone deliberately trying to make their code obscure so that people will have a hard time understanding it. Works fine, unless you forgot you did it and you come back later and say, "What the F!".
I don't understand why the IDE doesn't see something crazy-wrong like using string = int32 .
|
|
|
|
|
Hey, has anyone heard of the Delimon.win32.IO library?
I just ran into it at MS and it it is a direct replacement for the System.IO functions, with same function names, to boot. The great part is that it crosses the MAX_PATH barrier by design. It requires NET Framework 4. So that means VS2010, unless there is a way to get VS2008 to see it.
If someone mentioned this earlier, I apologize. But I did not find anything on it when doing a search here.
I have added a reference to it in my project and am about to test it.
UPDATE: Is NOT a direct replacement! Going through the properties/methods, a lot are simply not there, or stuff has been moved around and called by different names. Not sure if it completely covers all the functionality of System.IO.
Also, since it requires framework 4, I don't think WinXP can use it. Which is a bummer since there are still a lot of XP systems out there.
UPDATE 2: It MAY be a direct replacement after all...I might have attempted to type in methods while the dll reference was not properly set up. At any rate, this is a brand new library apparently, and it IS buggy. For instance, Directory.Exists and File.Exists methods do not filter correctly...Each returns "True" regardless of whether the resource is a folder or a file.
modified 13-Jun-13 14:41pm.
|
|
|
|
|
To CodeProject,
This is regarding a project that I'm trying to implement - quick chronological file opener script with retrieving 'FileDate' and 'ObjFilePath' and sorting its data into application calendar menu with qick links to exisiting files.
Plese give some suggestions on file date and time attributes inserting into form style widget
Regards, Nik
|
|
|
|
|
Ive read this a dozen times and I can't figure out what your'e trying to say. Don't bother repeateding what you've already said. Break the problem down into smaller parts and describe each of them.
If you can't communicate what you what to do with us, you'll find it impossible to describe how to do it to a computer which is far more picky.
|
|
|
|
|
Hello, the script should list files within directory and date file attributes than it should deliver data array into calendar links widget for quick acces to files by creation date and so, here is the working script that need modification
<pre lang="Javascript">
<html>
<Head>
<Title>HTA Script</Title>
<Style>
Body {Background-Color: CornSilk}
/* Sortable tables */
table.sortable thead {
background-color:#eee;
color:#666666;
font-weight: bold;
cursor: pointer;
}
</Style>
<HTA:Application
Caption = Yes
Border = Thick
ShowInTaskBar = No
MaximizeButton = Yes
MinimizeButton = Yes>
<Script Language = VBScript>
Dim Wsh,WScript
Set Wsh = CreateObject("WScript.Shell")
Sub WindowsLoads
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\")
If objFolder Is Nothing Then
Exit Sub
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(objPath)
For each objFile in objFolder.Files
FileDate = FormatDateTime(objFile.DateLastModified,2)
If objFolder.Files.Count > 0 Then
Window.Document.Title = "Information For " & objPath
chbox = objFile.Path
strHtml = strHtml & "<tr><td><a href=" & objFile.Path & " name=chbox target=_blank>" & objFile.Name & "</a></td><td width=30> </td><td>" & FileDate & "</td></tr>"
DataArea.InnerHtml = "<table><tr><td> </td><td> </td><td> </td></tr>" & strHtml & "</table>"
End If
Next
End Sub
</script>
</head>
<Body onLoad = "WindowsLoads">
<p><h3 align = center><font color='Orange'>File List</font></h3>
</p>
<Span Id = "DataArea"></Span></Body><Div Align = "Center">
<P>-File List-</P>
</Body>
</html></pre>
-- modified 4-Jun-13 18:07pm.
|
|
|
|
|
n381 wrote: deliver data array into calendar links widget
What in Hell is a "calendar links widget"?!?! We STILL don't have a clue as to what you're talking about.
|
|
|
|
|
Let's say it is menu created of files date attributes, sorted as calendar (widget) with links to files,
so it can be used for quick access to files selecting creation date link pointers istead of link text.
Nik
|
|
|
|
|
I STILL can't figure out what you're talking about, "sorted as calendar (widget)".
Have a nice life!
|
|
|
|
|
Okay,
here is the snapshot of two applications combined : file list and calendar widget
[url=http://postimage.org/][img=http://s8.postimg.org/rs9zsz3md/vbs_link_calendar_widget.jpg][/url]
[url=http://postimage.org/app.php]windows print screen[/url]
http://s8.postimg.org/rs9zsz3md/vbs_link_calendar_widget.jpg
Regards
|
|
|
|
|
So it searches for files somewhere and places links to them into a calendar-like control(.NET MonthCalendar , perhaps?), so that the date the link is displayed on is the date of the last edit.
At least that was what I understood it as.
|
|
|
|
|
Thank you for replying,
yes it is similar kind of application but simplified and should work with retrieving 'FileDate' and 'ObjFilePath' form file attached and sorting its data into application calendar menu with quick links to exisiting files,
please assist with your suggestions
<pre lang="vb">
<HTA:Application
Caption = Yes
Border = Thick
ShowInTaskBar = No
MaximizeButton = Yes
MinimizeButton = Yes>
<Script Language = VBScript>
Dim Wsh,WScript
Set Wsh = CreateObject("WScript.Shell")
Sub WindowsLoads
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\")
If objFolder Is Nothing Then
Exit Sub
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(objPath)
For each objFile in objFolder.Files
FileDate = FormatDateTime(objFile.DateLastModified,2)
If objFolder.Files.Count > 0 Then
Window.Document.Title = "Information For " & objPath
chbox = objFile.Path
strHtml = strHtml & "<tr><td><a href=" & objFile.Path & " name=chbox target=_blank>" & objFile.Name & "</a></td><td width=30 class=sorttable_nosort> </td><td>" & FileDate & "</td></tr>"
DataArea.InnerHtml = "<table><tr><td> </td><td width=30> </td><td> </td></tr>" & strHtml & "</table>"
//The output string results to be processed into calendar widget with link to files//
End If
Next
End Sub
</script>
</head>
<Body onLoad = "WindowsLoads">
<p><h3 align = center><font color='Orange'>File List</font></h3>
</p>
<Span Id = "DataArea"></Span></Body><Div Align = "Center">
<P>-File List-</P>
</pre>
|
|
|
|
|
hello guys i have doing some project and since i have new for vb.net 2010. my project is coded in vb.net 2010 and ms access 2007 mdb database. i have DocId, description, date and other fileds in the table.. my querry works for all but. i can't add all characters except integers in the database column DocId. it accepts only integer values. so how can i insert characters in the DocId filed. here is the detail
tables: DocId======Textbox name RefferencNoTxt.Text
Table name = EraDms
database name= data
cmd.CommandText = "INSERT INTO EraDms(DocId,Description,Address,NoOfPages, SendOrReceived, SentDate,ReceivedDate,ForwardedWorkingUnit,Attachements,ForwardedDate,ReceivedBy,DocPath) " & _
" VALUES(" & Me.RefferencNoTxt.Text.ToString & ",'" & Me.DescriptionTextBox.Text & "','" & Me.AddressTextBox.Text & "','" & Me.NoOfPagesTextBox.Text & "','" & Me.SendOrReceievedComboBox.Text & "','" & _
Me.SentDateTextBox.Text & "','" & Me.receivedDate.Text & "','" & Me.ForwardedWorkingUnitTextBox.Text & "','" & Me.AttachementsTextBox.Text & "','" & Me.TextBox6.Text & "','" & Me.ReceivedByTextBox.Text & "','" & Me.DocPathTextBox.Text & "')"
cmd.ExecuteNonQuery()
MessageBox.Show("File Upload Successfull", "ERA-DMS-File Uploader", MessageBoxButtons.OK, MessageBoxIcon.Information)
RefreshData()
cnn.Close()
Else
cmd.CommandText = "UPDATE Eradms " & _
" SET DocId=" & Me.RefferencNoTxt.Text.ToString & _
", Description='" & Me.DescriptionTextBox.Text & "'" & _
", Address='" & Me.AddressTextBox.Text & "'" & _
", NoOfPages='" & Me.NoOfPagesTextBox.Text & "'" & _
", SendOrReceived='" & Me.SendOrReceievedComboBox.Text & "'" & _
", SentDate='" & Me.SentDateTextBox.Text & "'" & _
", ReceivedDate='" & Me.TextBox1.Text & "'" & _
", ForwardedWorkingUnit='" & Me.ForwardedWorkingUnitTextBox.Text & "'" & _
", Attachements='" & Me.AttachementsTextBox.Text & "'" & _
",ForwardedDate ='" & Me.TextBox6.Text & "'" & _
",ReceivedBy ='" & Me.ReceivedByTextBox.Text & "'" & _
",DocPath='" & Me.DocPathTextBox.Text & "'" &
" WHERE DocId=" & Me.RefferencNoTxt.Text.ToString
cmd.ExecuteNonQuery()
RefreshData()
Private Sub RefreshData()
Try
If Not cnn.State = ConnectionState.Open Then
'open connection
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM EraDms", cnn)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
'offer data in data table into datagridview
Catch ex As OleDb.OleDbException
End Try
End Sub
best regards
|
|
|
|
|
Change the definition of DocID from Integer to Text in the database.
|
|
|
|
|
DocId data type is text in my database
|
|
|
|
|
What is the actual definition for DocId in your database schema? Also why are you calling ToString on the Me.RefferencNoTxt.Text object; is it not already text?
Use the best guess
|
|
|
|
|
Beiniam wrote: i can't add all characters except integers in the database column DocId. it accepts only integer values. so how can i insert characters in the DocId filed.
From that it makes me ask the question is the column type numeric? (integer, decimal etc.)
you will need to convert RefferencNoTxt.Text to the correct numeric type that your database needs.
i.e.
dim value as integer = Convert.ToInt32(RefferencNoTxt.Text)
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Your code is a classic example of SQL Injection[^]. One mis-placed ' in a text box, and your entire database could be corrupted.
Change the code to use parametereized queries instead:
cmd.CommandText = _
"INSERT INTO EraDms(DocId, Description, Address, NoOfPages, SendOrReceived, SentDate, ReceivedDate, ForwardedWorkingUnit, Attachements, ForwardedDate, ReceivedBy, DocPath) " & _
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
cmd.Parameters.AddWithValue("@p0", Me.RefferencNoTxt.Text)
cmd.Parameters.AddWithValue("@p1", Me.DescriptionTextBox.Text)
cmd.Parameters.AddWithValue("@p2", Me.AddressTextBox.Text)
cmd.Parameters.AddWithValue("@p3", Me.NoOfPagesTextBox.Text)
cmd.Parameters.AddWithValue("@p4", Me.SendOrReceievedComboBox.Text)
cmd.Parameters.AddWithValue("@p5", Me.SentDateTextBox.Text)
cmd.Parameters.AddWithValue("@p6", Me.receivedDate.Text)
cmd.Parameters.AddWithValue("@p7", Me.ForwardedWorkingUnitTextBox.Text)
cmd.Parameters.AddWithValue("@p8", Me.AttachementsTextBox.Text)
cmd.Parameters.AddWithValue("@p9", Me.TextBox6.Text)
cmd.Parameters.AddWithValue("@p10", Me.ReceivedByTextBox.Text)
cmd.Parameters.AddWithValue("@p11", Me.DocPathTextBox.Text)
And:
cmd.CommandText = _
"UPDATE Eradms " & _
" SET Description = ?, " & _
" Address = ?, " & _
" NoOfPages = ?, " & _
" SendOrReceived = ?, " & _
" SentDate = ?, " & _
" ReceivedDate = ?, " & _
" ForwardedWorkingUnit = ?, " & _
" Attachements = ?, " & _
" ForwardedDate = ?, " & _
" ReceivedBy = ?, " & _
" DocPath = ? " & _
" WHERE DocId = ?"
cmd.Parameters.AddWithValue("@p0", Me.DescriptionTextBox.Text)
cmd.Parameters.AddWithValue("@p1", Me.AddressTextBox.Text)
cmd.Parameters.AddWithValue("@p2", Me.NoOfPagesTextBox.Text)
cmd.Parameters.AddWithValue("@p3", Me.SendOrReceievedComboBox.Text)
cmd.Parameters.AddWithValue("@p4", Me.SentDateTextBox.Text)
cmd.Parameters.AddWithValue("@p5", Me.receivedDate.Text)
cmd.Parameters.AddWithValue("@p6", Me.ForwardedWorkingUnitTextBox.Text)
cmd.Parameters.AddWithValue("@p7", Me.AttachementsTextBox.Text)
cmd.Parameters.AddWithValue("@p8", Me.TextBox6.Text)
cmd.Parameters.AddWithValue("@p9", Me.ReceivedByTextBox.Text)
cmd.Parameters.AddWithValue("@p10", Me.DocPathTextBox.Text)
cmd.Parameters.AddWithValue("@p11", Me.RefferencNoTxt.Text)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank you a lot
Richard Deeming eming for your help. it works
|
|
|
|
|
I'm trying to create a utility to perform a mass update of our Active Directory and all I get is the error, "Server is unwilling to process request."
Below is my code:
Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
Dim ds As New DirectorySearcher(de)
ds.PropertiesToLoad.Add("department")
ds.SearchScope = SearchScope.Subtree
Dim ue As New DirectoryEntry
ds.Filter = String.Format("(SAMAccountName={0})", Me.tboxUserName.Text)
Try
ue = ds.FindOne.GetDirectoryEntry
For Each sproperty As String In ue.Properties.PropertyNames
debug.print(String.Format("{0}{1} : {2} ", System.Environment.NewLine, sproperty, ue.Properties(sproperty)(0)))
Next
If (ue.Properties.Contains("department")) Then
ue.Properties("department").Value = "IT"
Else
ue.Properties("department").Add("IT")
End If
ue.CommitChanges()
ue.RefreshCache()
ue.Close()
Catch ex As Exception
debug.print (ex.Message)
End Try
The code seems to connect to the LDAP server and retrieve the correct user because I can see valid data being displayed from the ue.Properties.PropertyNames collection.
The error is thrown on the "CommitChanges()" line.
BTW: This demo program is a WinForms .NET 4.0 applicaiton
I have tried it passing no credentials and passing valid domain credentials and I get the same " ... unwilling to process request." error.
What am I doing wrong?
|
|
|
|
|
According to http://forums.asp.net/t/1809557.aspx/1[^], the problem arises by using the wrong protocol:
Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
replace that with
Dim de As New DirectoryEntry(@"LDAP:\\DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
|
|
|
|
|
Thank you so much. My program is now working.
I've been trying so many combinations that I must have overlooked the obvious.
|
|
|
|
|
This question is a new post prompted by my other thread, "The old DoEvents and UserControls". I created a separate thread here, since it is branching off from the old discussion.
In the other thread, it was looking like converting code from supporting DoEvents, to supporting threading might be a big rewrite. But now I am not so sure. I downloaded an example Pause/Resume Thread program from online and that program had a separate class that was threaded. It then communicated to the main form via a delegate.
But I wanted to find out if it was possible to do threading of a procedure that was NOT in a separate class...But one residing in the main form's class, like any other sub. The reason this was important to me, was to cut down on the amount of code rewriting by keeping my existing code in place, and merely adding on additional code to thread one of those main form procedures. My revision to that original threading example seems to say, "yes", to that question. Here is my version of that little demo. It simply runs a counter that counts from 1 to whatever, and when the thread is suspended, the counter halts, until resumed. Since I am new to threading, is there anything wrong with this idea that could end up biting me in the rear?
Here is the code:
Imports System.Threading
Imports System
Public Class Form1
Private Delegate Sub DisplayValueDelegateType(ByVal txt _
As String)
Private m_DisplayValueDelegate As DisplayValueDelegateType
Private m_Thread As Thread
Public Value As Integer = 0
Public Sub DisplayValue(ByVal txt As String)
txtResults.Text = txt
End Sub
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim new_counter As New Counter(Me, my_number:=1)
m_Thread = New Thread(AddressOf new_counter.Runno)
m_Thread.IsBackground = True
m_Thread.Start()
Button1.Enabled = False
Button2.Enabled = True
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
If (m_Thread.ThreadState And ThreadState.Unstarted) _
<> 0 Then
m_Thread.Start()
Else
m_Thread.Resume()
End If
Button1.Enabled = False
Button2.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button2.Click
Debug.WriteLine("Suspending thread")
m_Thread.Suspend()
Button1.Enabled = True
Button2.Enabled = False
End Sub
Public Sub DoSomething(ByVal m_MyForm As Form1, _
ByVal m_DisplayValueDelegate _
As Object)
For loopo = 1 To 10000000
Thread.Sleep(3000)
SyncLock m_MyForm
m_MyForm.Value = m_MyForm.Value + 1
If m_MyForm.InvokeRequired() Then
m_MyForm.Invoke(m_DisplayValueDelegate, _
Str(m_MyForm.Value))
End If
End SyncLock
Next loopo
End Sub
Private Sub Quit_cmd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Quit_cmd.Click
End
End Sub
End Class
Public Class Counter
Private m_MyForm As Form1
Private Delegate Sub DisplayValueDelegateType( _
ByVal txt As String)
Private m_DisplayValueDelegate As DisplayValueDelegateType
Private m_Number As Integer
Public Sub New(ByVal my_form As Form1, _
ByVal my_number As Integer)
m_MyForm = my_form
m_Number = my_number
m_DisplayValueDelegate = AddressOf _
m_MyForm.DisplayValue
End Sub
Public Sub Runno()
Try
Call Form1.DoSomething(m_MyForm, m_DisplayValueDelegate)
Catch ex As Exception
Debug.WriteLine("Unexpected error in thread " & _
m_Number & vbCrLf & ex.Message)
End Try
End Sub
End Class
|
|
|
|
|