views:

212

answers:

1

I want to create a thread from XPCOM Component ... Here is a code for that

nsresult rv = NS_OK;
    nsCOMPtr<Callback> obj = do_CreateInstance("@jscallback.p2psearch.com/f2f;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);
    char* str="Hello from C++";
    obj->Status(str);
    _beginthread( (void(*)(void* ))&(P2P::test), 0,obj);

    return NS_OK;//obj->Status(str);

And here is a thread function

When I call function before calling thread It works But As soon as I write something like obj->Status(temp); Firefox crashes on function this call

class P2P{
    static char RecvBuf[1024];
public:
    static void test(Callback* obj){
    // char* temp="Hellllllooo";
    // obj->Status(temp);
  return;
}

};
+1  A: 

When your code that begins the thread falls out of scope, the nsCOMPtr will release the object, putting its refcount to zero. At this point, the object will be deleted. You'll need call NS_ADDREF before you fall out of scope (and be sure to call NS_RELEASE when you are done with it so you don't leak!).

sdwilsh
but its giving me error as: error C2248: 'nsDerivedSafe<T>::AddRef' : cannot access private member declared in class 'nsDerivedSafe<T>'
Xinus
I suspect this is a compiler issue or you are not publicly inheriting from nsISupports.
sdwilsh