Re: How to PR_LoadLibray
Wan-Teh Chang <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.nspr |
|---|---|
| Message-ID | <[email protected]> |
shellon wrote:
> Hi all:
> I want to control system volume in the xpcom, after research, I
> find PR_LoadLibrary or PR_LoadLibraryWithFlag can help me. So I write
> a test code piece as following:
>
> NS_IMETHODIMP VolumeController::Load(PRInt32 *_retval)
> {
> PRLibrary* lib = PR_LoadLibrary("USER32.dll");
> PRErrorCode errCode;
> if(lib == NULL)
> errCode = PR_GetError();
> *_retval = errCode;
> return NS_OK;
> }
>
> when I run the program, the errCode is a -8108273..., How can I load
> the library correctly? Could you give me a code snippit? Appriciate
> your help!
Hi shellon,
You should only call PR_GetError() after an NSPR function failed.
If an NSPR function succeeded, the return value of PR_GetError()
is garbage and should not be used.
So your code also forgets to initialize errCode, as Christian
Biesinger pointed out, so that if lib is not NULL, errCode contains
garbage. Since -8108273 looks like garbage, this means most likely
you successfully loaded USER32.dll.
The fix is to initialize errCode to 0 as Christian suggested, or
return an NS_xxx error code if lib is NULL.
Wan-Teh
_______________________________________________
dev-tech-nspr mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-nspr