-
Sep 18th, 2017, 04:17 PM
#1
Thread Starter
New Member
Problem with Shell32 when moving from VB.net to VS 2017 (IDE)
Dear Visual Basic programmers,
in the past (with VB-net [2003]), I have used forms with buttons on which the user could drag-and-drop files or desktop shortcuts, through use of shell32.dll, and it worked smoothly.
I have very recently upgraded to Visual Studio IDE 2017 and developed similar forms which also worked fine.
However, when I load an *old* project (developed with VB.net) in VS 2017, this drag-and-drop feature does not work --- it does not crash or issue any error message, but the shortcut is not read.
In my old project, if I add as an *existing item* the form developed in VS 2017, it does not work either.
But if I add the *old form* to my newly developed project (that is, in VS 2017), then that form is working as expected!
That makes me think that the code in the old form is correct, but that the old project, once translated to VS 2017, contains some embedded instructions/code that is incorrect.
I have no clue how to solve that, though. Is there anything in the translated code that I should erase? Or do you have other ideas/suggestions?
Hope my question is clear. Thanks in advance for any help,
PatrickB
-
Sep 18th, 2017, 04:30 PM
#2
Re: Problem with Shell32 when moving from VB.net to VS 2017 (IDE)
Just for your information, every VB since 2002 has been VB.NET. The .NET name was dropped starting with 2005, but the language is still the same up through 2017. More features have been added, that's all. So, both old and new were written in VB.NET, just in different versions.
My usual boring signature: Nothing
-
Sep 18th, 2017, 04:37 PM
#3
Re: Problem with Shell32 when moving from VB.net to VS 2017 (IDE)
I think it's more likely some aspect of the shell has changed since 2003. That was Windows XP, well before Windows Vista. Since then we've seen:
- XP SP2/SP3
- Vista
- Windows 7
- Windows 8
- Windows 10
Also, in that timeframe x64 computers were still a rarity. We were laughing at Windows Longhorn for requiring a dual-core x64 CPU in early specs. Now you have to go out of your way to buy x86.
Now, we've also seen .NET go through several different versions: current (I think) is 4.6 and I can't really keep track of what happened past 4.0 anymore. But here's why I'm suspicious it's the shell32 code.
.NET is meant to abstract Windows away. If you use .NET APIs they are supposed to handle the dirty work of making your code do the same thing no matter which version of Windows you use. So if we were talking strictly .NET APIs, if you were having a problem lots of people would be having a problem. The concept of "embedded instructions/code" isn't one that exists, there's no lingering VS 2003 artifacts from your old project. Just your code.
shell32.dll isn't meant to abstract Windows away. If you're using it, you're using a pretty specific version. It contains API, but sometimes MS has had to change/break the API. So while it's still likely a lot of simple API code from Win95 will still execute fine on Windows 10, it's not likely every bit of code works as it did.
But we can't see the code, so we can't help you. It's on you to read the documentation and decide if you're using it correctly. If you show us the code, we can help with that. But if you just say "some shell32.dll code to drag and drop shortcuts", we'd have to go look at documentation and guess what code you have. That won't get us anywhere.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Sep 18th, 2017, 04:51 PM
#4
Thread Starter
New Member
Re: Problem with Shell32 when moving from VB.net to VS 2017 (IDE)
Originally Posted by Sitten Spynne
I think it's more likely some aspect of the shell has changed since 2003. That was Windows XP, well before Windows Vista. Since then we've seen:
- XP SP2/SP3
- Vista
- Windows 7
- Windows 8
- Windows 10
Also, in that timeframe x64 computers were still a rarity. We were laughing at Windows Longhorn for requiring a dual-core x64 CPU in early specs. Now you have to go out of your way to buy x86.
Now, we've also seen .NET go through several different versions: current (I think) is 4.6 and I can't really keep track of what happened past 4.0 anymore. But here's why I'm suspicious it's the shell32 code.
.NET is meant to abstract Windows away. If you use .NET APIs they are supposed to handle the dirty work of making your code do the same thing no matter which version of Windows you use. So if we were talking strictly .NET APIs, if you were having a problem lots of people would be having a problem. The concept of "embedded instructions/code" isn't one that exists, there's no lingering VS 2003 artifacts from your old project. Just your code.
shell32.dll isn't meant to abstract Windows away. If you're using it, you're using a pretty specific version. It contains API, but sometimes MS has had to change/break the API. So while it's still likely a lot of simple API code from Win95 will still execute fine on Windows 10, it's not likely every bit of code works as it did.
But we can't see the code, so we can't help you. It's on you to read the documentation and decide if you're using it correctly. If you show us the code, we can help with that. But if you just say "some shell32.dll code to drag and drop shortcuts", we'd have to go look at documentation and guess what code you have. That won't get us anywhere.
Sorry. Here is my code.
Code:
Private Sub MyLabel_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles WinBugsBrowse.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
Private Sub WinBUGSBrowse_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles WinBugsBrowse.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim MyFiles() As String
' Assign the files to an array.
MyFiles = e.Data.GetData(DataFormats.FileDrop)
' Note that "WinBUGS" is a form label where the program will display the path read form drag-and-dropped desktop shortcut or file
If (IsShortcut(MyFiles(0))) Then
Dim tmp As String = ResolveShortcut(MyFiles(0))
If (Regex.Match(tmp, "winbugs", RegexOptions.IgnoreCase).Success) Then WinBugs.Text = tmp
Else
WinBugs.Text = MyFiles(0)
End If
End If
End Sub
Private Function IsShortcut(ByVal strPath As String) As Boolean
If Not File.Exists(strPath) Then
Return False
End If
Dim directory As String = Path.GetDirectoryName(strPath)
Dim strFile As String = Path.GetFileName(strPath)
Dim shell As Shell32.Shell = New Shell32.Shell
Dim folder As Shell32.Folder = shell.NameSpace(directory)
Dim folderItem As Shell32.FolderItem = folder.ParseName(strFile)
IsShortcut = folderItem.IsLink
End Function
Private Function ResolveShortcut(ByVal strPath As String) As String
If IsShortcut(strPath) Then
Dim directory As String = Path.GetDirectoryName(strPath)
Dim strFile As String = Path.GetFileName(strPath)
Dim shell As Shell32.Shell = New Shell32.Shell
Dim folder As Shell32.Folder = shell.NameSpace(directory)
Dim folderItem As Shell32.FolderItem = folder.ParseName(strFile)
Dim link As Shell32.ShellLinkObject = folderItem.GetLink
ResolveShortcut = link.Path
Else
ResolveShortcut = String.Empty
End If
End Function
Again, this code works just fine in both VB-net 2003 or in the the new VS-2017 flavor. However, when I load (and let Vs-2017 translate it) a old program in VS-2017, it does not work.
Thanks again for your help.
Last edited by Shaggy Hiker; Sep 18th, 2017 at 05:27 PM.
Reason: Added CODE tags
-
Sep 18th, 2017, 05:28 PM
#5
Re: Problem with Shell32 when moving from VB.net to VS 2017 (IDE)
I edited the post to add [CODE][/CODE] tags. You can do this by highlighting the code and pressing the # button. Otherwise, you can press the button first and paste the code between the tags.
My usual boring signature: Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|