On Wednesday 2003-12-10 14:02 -0800, Mike Muldoon wrote:
> Compiling this chunk of code (from the tutuorial) within
> myEnumerator::GetNext:
> 
>     nsCOMPtr<nsIComponentManager> mCompMgr; 
>     NS_GetComponentManager(getter_AddRefs(mCompMgr));
> 
>     nsISupportsCString* stringSupports; 
>     mCompMgr->CreateInstance(kSupportsCStringCID,  
>                              nsnull,  
>                              NS_GET_IID(nsISupportsCString),  
>                              (void**)&stringSupports); 
> 
> ..results with this compile error:
> 
> WebLock.cpp(88) : error C2065: 'kSupportsCStringCID' : undeclared
> identifier

If you want to call CreateInstance with a CID you need to declare a
variable holding the CID, e.g., by doing:

static NS_DEFINE_CID(kSupportsCStringCID, NS_SUPPORTS_CSTRING_CID);

which is generally done near the top of the file.  kSupportsCStringCID
is just a typical name you might choose for a local variable that you
need to declare -- it was never something that was defined for you.

Alternatively (and perhaps preferably), you could use a Contract ID, as
you did below.

> Question 1) Is there a mechanism that details the history of obsoleted
> code, and possibly what it was obsoleted by? It would be helpful to
> find out what happened to kSupportsCStringCID. I have looked through
> every repository exposed by LXR, and found nothing.

There never was any kSupportsCStringCID.  It's the name that you might
be likely to use for a local variable that you need to declare.

> Moving on to try another tack:
> 
>     nsISupportsCString* stringSupports; 
>    mCompMgr->CreateInstanceByContractID(NS_SUPPORTS_STRING_CONTRACTID,
>                                    nsnull,  
>                                    NS_GET_IID(nsISupportsCString),  
>                                    (void**)&stringSupports); 
> 
> ..this compiles, but fails to link:
> 
> Linking...
>    Creating library Debug/WebLock.lib and object Debug/WebLock.exp
> embedstring.lib(nsDependentSubstring.obj) : fatal error LNK1103:
> debugging information corrupt; recompile module Error executing
> link.exe.

I'm not sure about this one.

> nsCOMPtr<nsISupportsString> \
> stringSupports(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
> 
> ..results with this compile error:
> 
> error C2065: 'do_CreateInstance' : undeclared identifier
> 
> Question 4) What does an object need in order to call
> do_CreateInstance()? I have reviewed a dozen intances of its use, but
> can't determine what the prerequisites or dependancies are to call it.

#include "nsComponentManagerUtils.h"

-David

-- 
L. David Baron                                <URL: http://dbaron.org/ >
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to