问题不好问:C++写的dll,用Delphi或Kylix调用,如何才使得dll中类的成员变量可用(100分)

  • 主题发起人 linxiaovoc
  • 开始时间
L

linxiaovoc

Unregistered / Unconfirmed
GUEST, unregistred user!
我还是用例子来说明:
我用C++写了一个dll(linux下即为so),源码如下:
upper.h:
#include <stdio.h>
class CUpper
{
public:
int m_nValue ;
int printUPPERCASE(char inLine[]);
int printLOWER(char inLine[]);
};
upper.cpp:
#include "upper.h"
int CUpper:: printUPPERCASE(char inLine[])
{
m_nValue = 222 ;
return m_nValue ;
}
int CUpper::printLOWER(char inLine[])
{
m_nValue += 333 ;
return m_nValue;
}
编译后,产生dll文件
在C++中调用的时候,我可以实现先调printUPPERCASE后,m_nValue值为222,
然后调用printLOWER,m_nValue值为555。
我想这是因为我用C++调用的话,该类的实例只运行一次,这样类的成员变量就可以很好的
保留下来。
现在我想将该dll用于Delphi(Kylix),那么我该如何使用才可以达到上述的效果呢?
如果单纯采用
function printUPPERCASE(buf:pchar):interger;cdecl;external "/mypath/upper.so"
function printLOWER(buf:pchar):integer:cdecl;external "/mypath/upper.so"
我就没有办法在调用printUPPERCASE,再调printLOWER,m_nValue的值为555了,因为此时
m_nValue的值为333。
哪位帮帮忙,解决这个问题。
 
我对这个问题的理解是因为Delphi(Kylix) 在调用这个DLL时,CUpper类的实例在每一个函数调用的时候
都开启了一个,所以在系统中无法保留一个CUpper的类实例,这样就不能正确的使用属性了,
所以要想正确地使用该类属性,必须使得该类在DELPHI程序调用该DLL时,只能运行一次,这样就可以保证类成员变量正确使用。
但怎样才可以使得该类实例只装载一次呢,我总不在DELPHI中这样写吧:
#include "upper.h"
up:CUpper;
up......
 
我也想知道 以前听说 c++写的类不能做成dll被别的调用啊
因为无法实例化.看到的方法是将 c++ 变为c [:D}
 
顶部