Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A simple Firefox Addon with XP-COM Component

, 2 Jul 2010
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)

Share

About the Author

KarstenK
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.

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 2 Jul 2010
Article Copyright 2009 by KarstenK
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid