Creating a C DLL in Visual Studio suitable for using js-ctypes in Mozilla

As the subject says, what I am trying to do is similar to this one , but using Visual Studio 2012.

I can create and create a DLL and I can load this DLL in javascript, but I cannot access the function in this DLL. Looking at the DLL in DllExp, there are no functions suggesting anything is wrong with the DLL.

DLL is a new C ++ project created using the Empty Project template. Known settings:

General -> Configuration type set to DLL
No optimization.
There are no precompiled headers.
Compile as C Code
__cdecl Calling Convention

Command lines for compilation and linking, if there is a parameter that I did not consider to be significant,

 /GS /TC /analyze- /W3 /Zc:wchar_t /ZI /Gm /Od /sdl /Fd"Debug\vc110.pdb" /fp:precise /D "_WINDLL" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\StreamInterop.pch" 

      

And for the linker

 /OUT:"C:\Work\VehicleTracker-DotNet\StreamInterop\Debug\StreamInterop.dll" /MANIFEST /NXCOMPAT /PDB:"C:\Work\VehicleTracker-DotNet\StreamInterop\Debug\StreamInterop.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"C:\Work\VehicleTracker-DotNet\StreamInterop\Debug\StreamInterop.lib" /DEBUG /DLL /MACHINE:X86 /INCREMENTAL /PGD:"C:\Work\VehicleTracker-DotNet\StreamInterop\Debug\StreamInterop.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\StreamInterop.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBI

      

The project contains one C source file, main.c, containing

 #include<stdio.h>
 int add(int a,int b)
 {
     return(a+b);
 }

      

Considering this is all that was needed in the previous post, it seems to me that the problem must be in the compiler or linker switches. Can anyone see what I am missing?

+1


source to share


1 answer


On Windows with Visual Studio, to export a function from a DLL, use:

 #include<stdio.h>
 __declspec(dllexport) int add(int a,int b)
 {
     return(a+b);
 }

      



As a side note, don't select Empty Project, so Visual Studio will generate some sample code for you.

+1


source







All Articles