Click here to Skip to main content
15,891,687 members
Articles / Desktop Programming / Win32

A simple Firefox Addon with XP-COM Component

Rate me:
Please Sign up or sign in to vote.
2.87/5 (8 votes)
2 Jul 2010CPOL2 min read 63.9K   1.6K   28  
Beginning a Firefox Addon with the power of XP-COM
//in this file you got to write the implementation code
#include "stdafx.h"
#include "CodeprojectXPCOMImpl.h"

#include <nsStringApi.h>
#include <WINUSER.h>
#include <ShellApi.h>
#pragma comment( lib, "shell32.lib")

////////////////////////////////////////////////
//the implementation which will do the work
NS_IMPL_ISUPPORTS1(CCodeprojectXPCOM, ICodeprojectXPCOM)

CCodeprojectXPCOM::CCodeprojectXPCOM()
{
	wcscpy( m_szHomepage, TEXT("www.codeproject.com") );
}

CCodeprojectXPCOM::~CCodeprojectXPCOM()
{
}
NS_IMETHODIMP CCodeprojectXPCOM::Action(int cmd,const nsAString &nsString, int *_retval)
{
	*_retval = 0;//everything is fine
	switch( cmd )
	{
	case 0:
		MessageBox( 0, TEXT("Running operation 0"), TEXT("XP-COM"), MB_OK );
		break;
	case 1:
		{
			const PRUnichar* data = 0;
			PRUint32 len = NS_StringGetData(nsString, &data);

			TCHAR szBuffer[200];
			memset( szBuffer, 0, sizeof(szBuffer) /sizeof(TCHAR) );
			wcsncpy( szBuffer, data, len );

			HINSTANCE result = ::ShellExecute( NULL, TEXT( "explore" ), szBuffer, NULL,NULL, SW_SHOW );
		}
		break;
	}
	return NS_OK;
}
NS_IMETHODIMP CCodeprojectXPCOM::GetAboutText(class nsAString &nsString)
{
	TCHAR szBuffer[200];
	wcscpy( szBuffer, TEXT("XP-COM dll from Codeproject") );
	nsString.Assign( szBuffer );

	return NS_OK;
}
NS_IMETHODIMP CCodeprojectXPCOM::GetHomepage(class nsAString &nsString)
{
	nsString.Assign( m_szHomepage );
	return NS_OK;
}
NS_IMETHODIMP CCodeprojectXPCOM::SetHomepage(class nsAString const &nsString)
{
	const PRUnichar* data = 0;
    PRUint32 len = NS_StringGetData(nsString, &data);

	memset( m_szHomepage, 0, sizeof(m_szHomepage) /sizeof(TCHAR) );
	wcsncpy( m_szHomepage, data, len );

	TCHAR szBuffer[400];
	_swprintf( szBuffer, TEXT("The new homepage is '%s' now."), m_szHomepage );

	MessageBox( 0, szBuffer, TEXT("XP-COM"), MB_OK );

	return NS_OK;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer
Germany Germany
I am living in germany and now living from programming for some Years. In my spare time I like sports as jogging, playing football (soccer) and basketball.

We must take care for our planet, because we and our family has no other. And everybody has to do something for it.

Comments and Discussions