Saturday, September 19, 2009

NPAPI

I always start blogging but then stop it after a while!
This time I plan to continue blogging by including a genre which I never included before, Tech.
I had to develop an NPRuntime based plugin for windows to work across all non-IE browsers. This is my first stint at such tasks and needless to say I faced a real tough time.
But then, there are always life lines lying on the internet to help the dummies like me and one such lifeline I found was The Mozilla site . Without this, I could may be never have completed this task.
NPRuntime library is provided by Gecko. Based on my requirements I had to use Gecko 1.8 version only and nothing higher than that.
The incompatibility between the samples provided at Mozilla site and the Gecko version also proved to be smaller nightmare.
But finally I overcome all that and the plugin loads. But when I invoke a string returning function, browser hangs! Works fine for int returning functions, but hangs for string returning functions! Irony, this is the plugin sample code provided by Mozilla :(
I fought for 2 days on this single issue and finally I found the reason.
You should not allocate the "string to return" using our normal strdup() or malloc(). The correct way is here:


std::stringstream sm;
sm << "foo return val";
std::string wstr = sm.str();
char * val = (char*)NPN_MemAlloc(1 + wstr.length());
strcpy(val, sm.str().c_str());
STRINGZ_TO_NPVARIANT(val, *result);


Man! I dunno the difference between our malloc() and NPN_MemAlloc() but this being the reason for failure was something I did not expect.
So, I say, my happiest techie times are when I am submerged in a pure c/c++ code.

2 comments:

vkrishna said...

welcome to the library hell..:)

Python said...

so you have previous experience on web vamsi? using this NPAPI and stuff??