The problem is not here for me, i declare a satic attribute in one of my
classes, and when i wan to make operation on it, just like acces to it, my
component is not registered with regxpcom. If i on't access to my static
attribute, regxpcom can register my component in the file compreg.dat.
You can see here a part of the code and the makefile :


//class declaration :
class MyInterface : public nsIMyInterface
{
public:
    NS_DECL_ISUPPORTS
    NS_DECL_NSIMYINTERFACE
    static MyInterface* coucou();
    static MyInterface* titi;
    MyInterface();

    virtual ~MyInterface();
};

//class implementation
NS_IMPL_ISUPPORTS1(MyInterface, nsIMyInterface)

MyInterface::MyInterface()
{
    PR_fprintf(PR_STDOUT, "--------- Component C++ constructor\n");
}

MyInterface::~MyInterface()
{
    PR_fprintf(PR_STDOUT, "---------- Component C++  destructor\n");
    static eDataDacsInterface* titi = 0;
}

NS_IMETHODIMP MyInterface::About()
{
    PR_fprintf(PR_STDOUT, "--------- Component C++;");
    eDataDacsInterface::coucou();
    return NS_OK;
}

NS_IMETHODIMP MyInterface::Init()
{
    PR_fprintf(PR_STDOUT, "In component initialisation\n");
    return NS_OK;
}

NS_IMETHODIMP_(void) MyInterface::Start(void* aPointer)
{
    PR_fprintf(PR_STDOUT, "In  Start\n");
    return;
}

MyInterface* MyInterface::coucou()
{
    PR_fprintf(PR_STDOUT, "coucou\n");
    MyInterface::titi = NULL;         //if i comment this line, the
compoennet is registered by regxpcom
    return NULL;
}

//Makefile

CXX = g++

GECKO_SDK_PATH = /home/stef/devmilddleware/gecko-sdk

GECKO_INCLUDES = -I$(GECKO_SDK_PATH)/include

#GECKO_LDFLAGS =  -L/home/stef/devmilddleware/mozilla/dist/lib -lplds4
-lplc4 -lnspr4 -lpthread -ldl -lm

GECKO_LDFLAGS =  -L$(GECKO_SDK_PATH)/lib -lplds4 -lplc4 -lnspr4 -lpthread
-ldl -lm

FILES = MyInterface.cpp MyModule.cpp

TARGET = libmyComponent.so

all: MyInterface.o MyModule.o
    $(CXX) -Wall -shared -DMOZILLA_STRICT_API -o $(TARGET) $^
$(GECKO_INCLUDES) $(GECKO_LDFLAGS) $(GECKO_SDK_PATH)/lib/libxpcomglue.a


MyInterface.o: MyInterface.cpp
    g++ -c -I/home/stef/devmilddleware/gecko-sdk/include/ $<

MyModule.o : MyModule.cpp
    g++ -c -I/home/stef/devmilddleware/gecko-sdk/include/ $<


clean:
    rm -f *.o *.so


I really don't anderstand why i can't use a simple static attribute in my
class, i can't use one of another class ( i have tested this too).
Thank you for your help.....

>Stephen Kinger wrote:
>> Hi,
>>  I am coding XPCOM components with the Gecko-sdk-1.7. I have wrote main
>> classes for that and i verify that the component is well registered by
>> parsing the file compreg.dat after i run regxpcom program.
>> Everything work well if I don't use static functions and attributes. I
>> haven't find something about it on the net, so i ask the question if i
can
>> declare and use statics functions and variables in my own classes, if
>> somebody has already meet this problem and if he had found a solution.
>
>The problem is not with static variables in general, but with static
objects
>that have destructors. Static nsCOMPtrs are particularly bad: you aren't
>notification, so if you forget to assign null to the static comptr sometime
>during the shutdown process, you'll end up with an object that is released
>when the app process is being finished by the OS, which is way too late.
>
>So, the general rule of Mozilla development is not to use static class
>objects with destructors: this includes nsCOMPtrs and the various nsString
>objects.
>
>--BDS


------------------------------

--
Stephen Kinger
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to