在Visual Studio中制作一个C DLL,适用于Mozilla中的js-ctypes [英] Making a C DLL in Visual Studio suitable for use by js-ctypes in Mozilla

查看:168
本文介绍了在Visual Studio中制作一个C DLL,适用于Mozilla中的js-ctypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如主题所说,我要做的是类似于这个,但是使用Visual Studio 2012。

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

我可以构建和生成一个DLL,我可以在javascript中加载该DLL,但是我无法访问该DLL中的函数。看看DllExp中的DLL没有显示任何功能,表明DLL有问题。

I can build and produce a DLL, and I can load that DLL in javascript, but I cannot access the function in that DLL. Looking at the DLL in DllExp shows no functions, suggesting something's wrong with the DLL.

DLL是使用Empty Project模板创建的一个新的C ++项目。值得注意的设置是:

The DLL is a new C++ project created using the "Empty Project" template. Notable settings are;

通用 - >配置类型设置为DLL

无优化。

无预编译头。 >
编译为C代码

调用约定__cdecl

General->Configuration Type set to DLL
No optimization.
No precompiled headers.
Compile as C code
Calling convention __cdecl

编译和链接的命令行,如果有一个设置我没有认为重要,是

The commandlines for compilation and linking, in case there's a setting I've not thought significant, are

 /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" 

对于链接器

 /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

该项目包含一个单独的C源文件,main.c,包含

The project contains a single C source file, main.c, containing

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

鉴于这是所有在之前的帖子中需要的,在我看来该问题必须在编译器或链接器开关中。任何人都可以看到我缺少的东西?

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

推荐答案

在使用Visual Studio的Windows上,要从DLL导出函数,请使用:

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

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

作为附注,不要选择空项目,因此Visual Studio将生成一些示例代码。

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

这篇关于在Visual Studio中制作一个C DLL,适用于Mozilla中的js-ctypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆