Create a DLL to be used by Mozilla js-ctypes
Regarding my first post: Mozilla uses a C DLL with js-ctypes
I am trying to create a DLL for use with the Mozilla Firefox extension. I created a little C code and compiled it with GCC.
Here is the C code:
#include<stdio.h>
int add(int a,int b)
{
return(a+b);
}
Here are the compilation lines:
gcc -c library.c
gcc -shared -o library.dll library.o -Wl
The DLL compiled well, I can open it with dllexp and see the add () method open.
The problem is that when I try to use it from my extension, I always get the message: Error: Could not open library
Here is my Javascript call:
var libc = ctypes.open("C:\\WINDOWS\\system32\\user32.dll"); //OK
var libc2 = ctypes.open("C:\\WINDOWS\\system32\\library.dll"); //KO
The DLL doesn't seem to open Firefox, but I'm wondering why. I don't see anything about creating a DLL for a Firefox extension, it looks like we can use every classic DLL.
Any idea? Thanks to
source to share
If you compile a library like this you end up with a dependency on msvcrt.dll
which probably cannot be resolved on your system ( redistributable package required), it works fine in my opinion. You can compile your library without CRT dependency, you just need to define DllMain
yourself:
#include<windows.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
return TRUE;
}
int add(int a,int b)
{
return(a+b);
}
And the link step looks like this:
gcc -shared -nostdlib -o library.dll library.o -Wl,-e_DllMain@12
You can't use the CRT functionality back then - I couldn't find a way to statically put a static environment with GCC on Windows (Visual C ++, on the other hand, is just fine).
source to share