Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load DLL from a XPcom DLL

Status
Not open for further replies.

simoryl

Programmer
Mar 23, 2005
5
Hi,

I try to make a Firefox extension which can use a dll of another program of mine. My extension is only for windows platform for the moment.

So I made an extension with a vc++ xpcom dll in the directory "components". The xpcom dll must bridge my extension with the dll of my other program (I hope that I'm clear in my explanation coz it's not easy to explain in my natural language too…).
I based my xpcom on this documentation :
Because I need to load another dll from my xpcom, I create a MFC dll project in vc++ not a simple dll for to make my xpcom.
My xpcom works well, load the external dll, call the needed function and unload the dll. But (there's always a @#!& "but"…), after returning the result, Firefox crash and I don't know why. I put a lot of message box for detecting where.
There is my code :
------------------------------------------------------------------------------------------
NS_IMETHODIMP CSpecialThing::Add(PRInt32 a, PRInt32 b, PRInt32 *_retval)
{

typedef char* (_stdcall *ProcDllPtr)(char* monString);
HMODULE hinstDLL=LoadLibrary((LPCSTR)"C:\\_project\\Dll\\DLMDLL.dll");
if (hinstDLL) {
AfxMessageBox((LPCTSTR)"XPCOM : DLL load",MB_OK,-2);
ProcDllPtr ProcExportDll = (ProcDllPtr) GetProcAddress(hinstDLL, "Ajouter_article");
AfxMessageBox((LPCTSTR)"XPCOM : before function calling",MB_OK,-2);
char* reponseDLL=ProcExportDll("sanctification personnel");
AfxMessageBox((LPCTSTR)"XPCOM : after function calling",MB_OK,-2);
AfxMessageBox((LPCTSTR)reponseDLL,MB_OK,-2);
AfxMessageBox((LPCTSTR)"XPCOM : after DLL response",MB_OK,-2);

AfxMessageBox((LPCTSTR)"XPCOM : DLL free",MB_OK,-2);
} else {
AfxMessageBox((LPCTSTR)"grrr...",MB_OK,-2);
}
FreeLibrary((HINSTANCE)hinstDLL);

AfxMessageBox((LPCTSTR)"before retval",MB_OK,-2);
*_retval = a + b;
AfxMessageBox((LPCTSTR)"after retval",MB_OK,-2);
return NS_OK;
AfxMessageBox((LPCTSTR)"never show",MB_OK,-2);
}

------------------------------------------------------------------------------------------
The "never show" message doesn't appear, Firefox crash before.

Do you have an idea about this bug? I read that use MFC in xpcom is not a good idea, do you know how I can load my dll in my xpcom without MFC?

Thanks in advance.

Simo'
 
How about placing

return NS_OK;

after AfxMessageBox((LPCTSTR)"never show",MB_OK,-2);

gr. Pjotr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top