Google Answers Logo
View Question
 
Q: Parsing DLL in VB.Net ( Answered,   2 Comments )
Question  
Subject: Parsing DLL in VB.Net
Category: Computers > Programming
Asked by: bacteriaa-ga
List Price: $5.00
Posted: 25 Aug 2003 08:11 PDT
Expires: 24 Sep 2003 08:11 PDT
Question ID: 248513
I am trying to "Register an Application to a URL Protocol" (Refer to:
http://msdn.microsoft.com/workshop/networking/pluggable/overview/appendix_a.asp?frame=true
)

I ran the registry script (provided in the article):
[HKEY_CLASSES_ROOT]
    [note]
        (Default) = "URL:Note Protocol"
        URL Protocol = ""
        [DefaultIcon]
            (Default) = "notepad.exe"
        [shell]
            [open]
                [command]
                    (Default) = "c:\windows\notepad.exe %1"


However, this code does not work as quoted. Everytime I execute the
command "note:c:\myfile.txt", the notepad application opens up but an
error message pops up saying "Could not find the file
note:c:\myfile.txt ".

The registry code here actually takes the complete command as an
argument for itself.

I looked into some examples in the registry if they share this
problem. And they seem to. However to counter this, they have an
additional dll (usually url.dll) which strips off the 'note:' (or
whatever the command is) in the total command and sends the rest as an
parameter.

My question is how can I write such a DLL which will take an input
string and return its substring (Need code). For e.g. If I execute

> notepad MyStripper.dll note:c:\note.txt

the dll should strip "note:c:\note.txt" and just send "c:\note.txt" as
an argument to the notepad application.

Thank u in advance.

Would prefer code solution in VB.Net
Answer  
Subject: Re: Parsing DLL in VB.Net
Answered By: mmastrac-ga on 26 Aug 2003 06:40 PDT
 
Hi.  This is a pretty straightforward question.  The following snippet
of VB.NET code will compile and perform the task you're looking for. 
Compile this to "stripprotocol.exe" and place it in C:\WINDOWS:

stripprotocol.vb:

Imports System.Windows.Forms
Imports Microsoft.VisualBasic

Public Module Test
	Public Sub Main( args as String() )
		If args.Length <> 1 Then
			MessageBox.Show( "Need exactly one argument" )
			Return
		End If
		If Not args( 0 ).StartsWith( "note:" )
			MessageBox.Show( "Argument must start with 'note:'" )
			Return
		End If

		' 5 is the length of the string "note:"
		args( 0 ) = args( 0 ).Substring( 5 )

		' Uncomment to see what gets passed to the program
		' MessageBox.Show( args( 0 ) )

		System.Diagnostics.Process.Start( "notepad.exe", args( 0 ) )
	End Sub
End Module

Use the following registry settings to run it:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\note]
@="URL:Note Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\note\DefaultIcon]
@="notepad.exe"

[HKEY_CLASSES_ROOT\note\shell]

[HKEY_CLASSES_ROOT\note\shell\open]

[HKEY_CLASSES_ROOT\note\shell\open\command]
@="C:\\windows\\stripprotocol.exe \"%1\""

^-- Note that if you are entering this in the registry by hand, this
should be: C:\windows\stripprotocol.exe "%1"

If you have any questions, feel free to ask.

Request for Answer Clarification by bacteriaa-ga on 26 Aug 2003 11:19 PDT
Thanks for your quick response.

However I tried to compile the code and I get the following error

<b> 'Process' is not a member of 'Diagnostics' </b>

I have all of these in the Imports:
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports System
Imports System.Diagnostics
Imports System.ComponentModel

But still doesnt help.

Clarification of Answer by mmastrac-ga on 28 Aug 2003 08:47 PDT
Do you have a reference to the "System" and "System.Windows.Forms"
dlls in your project?  From your message, it sounds like you might
not.

If you are compiling from the command line, this would be the command:

C:\>vbc stripprotocol.vb /r:System.Windows.Forms.dll /r:System.dll

Let me know if you need any additional help.

Request for Answer Clarification by bacteriaa-ga on 28 Aug 2003 09:14 PDT
I created a new project in VS.Net and entered the code.

Gives me the same error message.

I have included the System.Windows.Forms namespace.

Request for Answer Clarification by bacteriaa-ga on 28 Aug 2003 09:45 PDT
I compiled through the cmd prompt and it worked. Sorry abt that. I
dont know why VS.Net wouldnt do it. But anyway, as long as it works.

But when run the command 
note: c:\test.txt

It opens the file fine but gives another error message box saying the
file 'note: c:\test.txt' could not be found.

Clarification of Answer by mmastrac-ga on 29 Aug 2003 11:34 PDT
Odd.  I tested exactly what I've posted here and it seems to work
fine.  Can you verify that your registry settings are correct?  The
most important item would be that the command looks like this in
REGEDIT (including the quotes):

C:\somepath\stripprotocol.exe "%1"

Are you entering the URL as "note:C:\test.txt" or "note: C:\text.txt"?
 Note the extra space.  I tried both and they seem to work here,
however.  It could possibly be a windows version issue, though.

Where is the error message coming from?  Is it from the code I've
given you, or is notepad saying that it can't find the file?
Comments  
Subject: Re: Parsing DLL in VB.Net
From: vaneetpasricha-ga on 26 Aug 2003 01:24 PDT
 
Hello bacteriaa,

I seen the registery entries you are trying

please change the
(Default) = "c:\windows\notepad.exe %1"
to
(Default) = "c:\windows\notepad.exe" "%1"
You problme will be resolved. You are trying to execute the program
"c:\windows\notepad.exe %1" in this %1 is the file name which you are
opening. that is why it was givving error ""Could not find the file
notepad:c:\myfile.txt".

Vaneet Pasricha
Subject: Re: Parsing DLL in VB.Net
From: bacteriaa-ga on 26 Aug 2003 11:25 PDT
 
I tried implementing your suggestion but in vain.

I changed [HKEY_CLASSES_ROOT\note\shell\open\command] key to 
"c:\windows\notepad.exe" "%1" .

Still keep getting the same error message.

Any suggestions

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy