Click here to Skip to main content
15,389,584 members
Articles / Desktop Programming / MFC
Posted 18 Feb 2012

Tagged as


49 bookmarked

Custom URL Protocol for Invoking Application

Rate me:
Please Sign up or sign in to vote.
5.00/5 (18 votes)
6 Mar 2012CPOL3 min read
Registering a custom URL protocol for invoking an application
Image 1


While working, I came across a problem which required to invoke a Windows application (present in a local machine) from my web application. After some Google search, I came to know that by using custom URL protocol, we can invoke a Windows application. I found that there is a lot of information present related to custom URL protocol. I also found some sample applications on the internet. But all the sample applications seem to be made in C# or some other language. But as per the project requirement, I needed to write code in C++\Win32 for registering custom URL protocol handler. I have written a C++\Win32 class which registers the custom URL protocol handler.

This article provides information for registering a client side Custom URL protocol handler for invoking windows application from web based applications. I have attached the "" file which contains a cpp and header file. This files can be added in the application for creating a custom URL protocol. I have also attached a demo application along with its source which uses this Custom URL protocol files.

Custom URL protocol can also be used for passing content between applications.

Example: Application A wants to pass some data after its processing to application B. For achieving this, application A can register a protocol handler and can call application B with processed data as parameter. In this way, one application can pass data to another application.

Using the Code

Zip file "" contains a cpp file and a header file which should be included in your project. This file contains a class named "class CustomURLProtocol".This class contains setter and getter function for protocol name, company name and application path which needs to be launched.

std::wstring getProtocolName() {return wszProtocolName;}
std::wstring getCompanyName() {return wszCompanyName;}
std::wstring getAppPath() {return wszAppPath;}

void setProtocolName(std::wstring pwProtocolName){wszProtocolName = pwProtocolName;}
void setCompanyName(std::wstring pwCompanyName){wszCompanyName = pwCompanyName;}
void setAppPath(std::wstring pwAppPath){wszAppPath = pwAppPath;}

Calling code has to create an object of the CustomURLProtocol class. With the help of setter function, calling application has to set required parameters like protocol name, company name and application path. Once this parameter is set, calling application can call CreateCustomProtocol function. This function will create a custom URL protocol for the application.

In my demo, the application calls initializeParameter function which calls the setter function of CustomURLProtocol class. It calls DeleteCustomProtocol function which will delete the custom protocol which is already present. Finally, it calls CreateCustomProtocol function which will create a custom protocol for launching the application.

void CCustomURLProtocolDlg::OnBnClickedOk()
  DWORD errorCode = 0;

  // Initialize Custom Protocol Class Parameter

  // Delete Custom Protocol if already present

  // Create new Custom protocol
	if(m_CustomURLProtocol.CreateCustomProtocol() != ERROR_SUCCESS)
		MessageBox(L"Successfully Created Custom Protocol.");

CreateCustomProtocol function registers the custom protocol by entering the below keys in the registry.

CustomURLProtocol class also handles error conditions. The above code snippets show that if some error happens, then the application can get error description by calling m_CustomURLProtocol.getErrorMsg().c_str()

  [< ProtocolName >]
      (Default) = "URL:< ProtocolName > Protocol Handler"
      URL Protocol = ""
       (Default) = "< Application Path >"
           (Default) = "< Application Path> "%1""

For deleting custom protocol, we just need to call DeleteCustomProtocol function as called in the demo function below. First, we need to initialize the parameter of CustomURLProtocol class and then call DeleteCustomProtocol function.

void CCustomURLProtocolDlg::OnBnClickedBtnDelete()
    DWORD errorCode = 0;
	if(m_CustomURLProtocol.DeleteCustomProtocol() != ERROR_SUCCESS)
		MessageBox(L"Successfully Deleted Custom Protocol.");

Registry key creation and deletion needs admin privileges in some Windows OS. This will need your app to run in admin privileges. My demo application contains a manifest file which is used to launch demo application with admin privileges. If there is any error, then demo application provides description of error along with error code.

In the demo app, I have also provided a way to test the registered custom URL protocol handler. When user clicks Test button, demo application generates an HTML file which launches the registered application. This test app can be used as a sample for invoking the application.

The provided class for creating a custom protocol can be updated according to the need of the project. I will update the code as I come to know about issues in it.


  • 17th February, 2012: Initial version
  • 27th February, 2012: Added Error Handling code in CustomURLProtocol class
  • 06th March, 2012: Solved issue related to chrome browser in test application source code


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead
India India
No Biography provided

Comments and Discussions

QuestionDidn't work for me either no errors Pin
Alistair Rigney 202121-Oct-21 18:56
MemberAlistair Rigney 202121-Oct-21 18:56 
Questionplease source code not open Pin
Member 1060694310-Dec-19 19:15
MemberMember 1060694310-Dec-19 19:15 
QuestionDo not run on windows 10 Pin
Member 1013238726-Jul-19 5:54
MemberMember 1013238726-Jul-19 5:54 
QuestionSource code doesn't exist Pin
SAlvador.ta26-Jul-17 7:21
MemberSAlvador.ta26-Jul-17 7:21 
QuestionI don't see notepad Pin
Sam Hobbs13-Apr-16 9:38
MemberSam Hobbs13-Apr-16 9:38 
Question"Index was outside the bounds of the array" Pin
Member 1239976018-Mar-16 10:33
MemberMember 1239976018-Mar-16 10:33 
AnswerRe: "Index was outside the bounds of the array" Pin
Chandrakantt14-Jun-16 2:34
MemberChandrakantt14-Jun-16 2:34 
Questionvb compatability Pin
chabad36522-Jun-14 12:44
Memberchabad36522-Jun-14 12:44 
AnswerRe: vb compatability Pin
Mr.ExA-MaN19-Apr-15 14:42
MemberMr.ExA-MaN19-Apr-15 14:42 
Questionnot working Pin
Alexandre GRANVAUD1-Mar-12 20:59
MemberAlexandre GRANVAUD1-Mar-12 20:59 
AnswerRe: not working Pin
Chandrakantt1-Mar-12 22:19
MemberChandrakantt1-Mar-12 22:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.