谢谢各位的指教,以下列出代码:#ifndef PHONEDRIVER_H #define PHONEDRIVER_H// The following ifdef block is the standard way of creating macros which make exporting from a DLL simpler. All files within this DLL are compiled with the PHONEDRIVER_EXPORTS symbol defined on the command line. this symbol should not be defined on any project that uses this DLL. This way any other project whose source files include this file see PHONEDRIVER_API functions as being imported from a DLL, wheras this DLL sees symbols defined with this macro as being exported.#ifdef PHONEDRIVER_EXPORTS #define PHONEDRIVER_API __declspec(dllexport) #else #define PHONEDRIVER_API __declspec(dllimport) #endif// This class is exported from the phoneDriver.dllclass PHONEDRIVER_API CDevDriv{ private: CDevDriv(); static CDevDriv devDriv; public: ~CDevDriv(); static CDevDriv * getInstance(); ...... };class PHONEDRIVER_API CTelDriv{ ...... }出厂DLL是用VC写的,可以被VC调用,现在我们想用其他语言调用,请问这样的方式能否给其他语言调用吗?
int fun(int x, int y)上面的int x, int y即为签名,返回值(上面是int),可以不知道,这不影响函数调用,也就是说,你按void返回类型去调用int返回类型的函数,不会出任何问题。但签名必须要知道,比如上面的函数,你这样调用fun(1);或fun(1,2,3);肯定程序崩溃!
... 和它是用什么语言写的无关 .============================
好像不对吧! 大部分正确,我相信那位兄弟看成COM了,比如在VC中的MFC扩展DLL就只能被VC使用,道理简单,VB、DELPHI读不懂MFC。 但是若该DLL能被C语言调用,被VC调用是肯定没问题的,如果在Dll的接口中不涉及其它复杂的类型当然也能被其它语言调用。 LZ不把DLL的接口列部分出来,我们如何给你示范,相信LoadLibrary、GetProccAddress这类型的调用你应该会。
#define PHONEDRIVER_H// The following ifdef block is the standard way of creating macros which make exporting from a DLL simpler. All files within this DLL are compiled with the PHONEDRIVER_EXPORTS symbol defined on the command line. this symbol should not be defined on any project that uses this DLL. This way any other project whose source files include this file see PHONEDRIVER_API functions as being imported from a DLL, wheras this DLL sees symbols defined with this macro as being exported.#ifdef PHONEDRIVER_EXPORTS
#define PHONEDRIVER_API __declspec(dllexport)
#else
#define PHONEDRIVER_API __declspec(dllimport)
#endif// This class is exported from the phoneDriver.dllclass PHONEDRIVER_API CDevDriv{
private:
CDevDriv();
static CDevDriv devDriv;
public:
~CDevDriv();
static CDevDriv * getInstance();
......
};class PHONEDRIVER_API CTelDriv{
......
}出厂DLL是用VC写的,可以被VC调用,现在我们想用其他语言调用,请问这样的方式能否给其他语言调用吗?
“如果通过VC++编写的DLL欲被其他语言编写的程序调用,应将函数的调用方式声明为__stdcall方式,WINAPI都采用这种方式”
该资料给出的stdcall例子使用动态的。那stdcall能不能静态调用?假如不能的话,我拿来提问的出厂程序又是静态的,那是不是就代表这个出厂程序的DLL不能给非C的语言调用?十分感谢大家的帮忙!
相反,如果不知道函数名字,但知道签名,是可以使用的,用depends工具,就可看到函数的入口地址,直接对这个地址调用即可。
该类提供了对设备的初始化工作,主要函数如下:1.1. static CDevDriv * getInstance();
描述:获得该类的实例
输入参数:无
输出参数:无
返回值:获取该类实例,初始化设备失败或者查无设备返回值为NULL。1.2. bool getInitState();
描述:获取设备初始化状态,如果设备未初始化,需要调用reInit()函数再做一次初始化。1.3. void disable();
描述:关闭设备。............这些算不算是程序的签名呢?能不能用的上?
另外可用:tlib xxx.lib,xxx.lst 产生DLL的内部函数列表,许多Windows的未公开技术就是用这种方法发现的。 也许你需要上面说的这两个,我觉的 implib tlib很好用,最近我写,用DLL 都用的上上面的这两个 没用的话 我mail给你
我邮箱是[email protected]。
这个DLL输出的是一个类,如果想从其它语言调用:1。手工进行构造函数的调用,以及以后析构函数的调用。2.每个函数都包函了一个THIS指针,记得要在参数中输入。3.函数参数的调用次序。4.其它,以我的知识想不到了:)笨哈......
dumpbin /exports yourdll.dll > yourdll.def2、编辑 yourdll.def 文件,使之格式与.def文件格式一致。比如:EXPORTS;
fn1;
fn2;3、在命令行执行:
lib /def:yourdll.def /machine:i386 /out:yourdll.lib