Hi all,
It turned out the problem was a corrupt VS.NET project. If I remember correctly what MS said is that sometimes the debug info, symbol info, etc. can become corrupt. If this happens then you won't be able to hit breakpoints in your code when debugging. One way to solve the problem is to create a new project for your source code.
Once I did this I was able to debug fine.
Damien
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Damien O'Brien
Sent: 06 April 2005 18:57
To: [email protected]
Subject: XPCOM component (dll) being opened by mozilla but not loaded...Hi,
I've written a pretty simple XPCOM component that does "stuff" when a new page is loaded. I've used ContentPolicy ShouldLoad to detect new page loads. My component seems to be registered correctly with mozilla - I used Component Viewer to determine this - also, I had a look in compreg.dat and xpti.dat and they seem to be updated correctly (I think). However when mozilla starts my dll is not being loaded. I checked this by putting a breakpoint at the start of DllMain and running the dll (with mozilla as the startup app) in the VS.Net debugger. The breakpoint was not hit, indicating that the dll was not being loaded. I then used a combination of Process Explorer and FileMon to see if my dll was being touched by mozilla. Using these utilities I determined that mozilla was accessing my dll i.e. it was opening it, but the dll was NOT being loaded i.e. as mentioned above DllMain was not being called.The only conclusion I can come to is that I must be missing something in my dll code. Possibly something's meant to happen at registration time that I'm not doing. I'm using mozilla 1.7.6.
Anyone got any suggestions?
I've included the IDL file I use to generate my .xpt and the my C++ code below, it's pretty short as all I want to do is do "stuff" when ShouldLoad is called. I have a feeling the problem is somewhere here. BTW, most of the code is taken from the "Creating XPCOM Components" tutorial.
Thanks,
Damien======== IDL =========
#include "nsISupports.idl"
[nonscriptable, uuid(82B9AB1D-7169-43b6-B6BB-9870ED36F7C7)]
interface TestPageLoad : nsISupports
{
};===== source code =====
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>#include "nsIGenericFactory.h"
#include "nsCOMPtr.h"
#include "nsXPCOM.h"
#include "nsIServiceManager.h"
#include "nsICategoryManager.h"#include "nsIObserver.h"
#include "nsEmbedString.h"
#include "nsIContentPolicy.h"
#include "nsMemory.h"#define TestPageLoad_CID \
{ 0x82b9ab1d, 0x7169, 0x43b6, \
{ 0xb6, 0xbb, 0x98, 0x70, 0xed, 0x36, 0xf7, 0xc7 }}#define TestPageLoad_ContractID "@dobrien/testpageload"
class TestPageLoad: public nsIObserver, public nsIContentPolicy {
public:
TestPageLoad();
virtual ~TestPageLoad();NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSICONTENTPOLICY
};TestPageLoad::TestPageLoad()
{
NS_INIT_ISUPPORTS();
}TestPageLoad::~TestPageLoad()
{
}NS_IMPL_ISUPPORTS2(TestPageLoad, nsIObserver, nsIContentPolicy);
NS_IMETHODIMPTestPageLoad::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
return NS_OK;
}
static NS_METHOD TestPageLoadRegistration( nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info){
nsresult rv;nsCOMPtr<nsIServiceManager> servman = do_QueryInterface((nsISupports*)aCompMgr, &rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsICategoryManager> catman;
servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
NS_GET_IID(nsICategoryManager),
getter_AddRefs(catman));
if (NS_FAILED(rv))
return rv;
char* previous = nsnull;
rv = catman->AddCategoryEntry("xpcom-startup",
"TestPageLoad",
TestPageLoad_ContractID,
PR_TRUE,
PR_TRUE,
&previous);
printf("previous was %s %d", previous, rv);
if (previous)
nsMemory::Free(previous);rv = catman->AddCategoryEntry("content-policy",
"TestPageLoad",
TestPageLoad_ContractID,
PR_TRUE,
PR_TRUE,
&previous);printf("previous2 was %s, %d", previous, rv);
if (previous)
nsMemory::Free(previous);printf("Hello there, I'm registered!!\n");
return rv;
}NS_IMETHODIMP TestPageLoad::ShouldProcess(PRUint32 aContentType, nsIURI *aContentLocation,
nsIURI *aRequestOrigin, nsISupports *aContext,
const nsACString & aMimeType, nsISupports *aExtra, PRInt16 *_retval){
return NS_OK;
}
NS_IMETHODIMP TestPageLoad::ShouldLoad(PRUint32 aContentType, nsIURI *contentLocation,
nsIURI *aRequestOrigin, nsISupports *aContext,
const nsACString & aMimeTypeGuess, nsISupports *aExtra, PRInt16 *_retval){
// DO STUFF IN HERE
return NS_OK;
}
static NS_METHOD TestPageLoadUnregistration(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation, const nsModuleComponentInfo *info){
nsresult rv;printf("Hello there, starting to unregister!!\n");
nsCOMPtr<nsIServiceManager> servman = do_QueryInterface((nsISupports*)aCompMgr, &rv);
if (NS_FAILED(rv))
return rv;nsCOMPtr<nsICategoryManager> catman;
servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
NS_GET_IID(nsICategoryManager), getter_AddRefs(catman));if (NS_FAILED(rv))
return rv;rv = catman->DeleteCategoryEntry("xpcom-startup",
"TestPageLoad", PR_TRUE);if (NS_FAILED(rv))
return rv;rv = catman->DeleteCategoryEntry("content-policy",
"TestPageLoad", PR_TRUE);printf("Hello there, I'm finally unregistered!!\n");
return rv;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(TestPageLoad)
static const nsModuleComponentInfo components[] =
{
{ "TestPageLoad",
TestPageLoad_CID,
TestPageLoad_ContractID,
TestPageLoadConstructor,
TestPageLoadRegistration,
TestPageLoadUnregistration
}
};NS_IMPL_NSGETMODULE(TestPageLoadModule, components)
