J
jchrubbish
Unregistered / Unconfirmed
GUEST, unregistred user!
我用VC++6.0创建的DLL,代码大概如下:
class MyClass
{
public:
virtual char* test(char* str);
}
extern "C" _spedecl(dllport) MyClass* ClassFatory();
extern "C" _spedecl(dllport) void ClassKill(Myclass* my);
char* MyClass::test(char* str);
{
return str;
}
MyClass* ClassFatory()
{
MyClass* my;
my = new MyClass
return my;
}
void ClassKill(MyClass* my)
{
delete my;
}
//上面的代码在VC中顺利编译成DLL
//在Delphi中的引用DLL的代码大概如下:
Type
TMyClass - class(TObject)
public:
virtual function test(str: PChar): PChar;virtual;cdecl;abstract;
end;
function ClassFactory: TMyClass;cdecl;extern 'mydll' name 'ClassFactory';
procedure ClassKill(TMyClass my);;cdecl;extern 'mydll' name 'ClassKill';
procedure TFrom1.btn1Click(Sender: TObject)
var
my: TMyClass
begin
my := ClassFactory;
ShowMessage(string(my.test));
ClassKill(my);
end;
//上面的代码编译都能通过,在点btn1后报错:access violation,就是在my.test处报错,我如果把test中的参数去掉将test返回一个常量字符串,则不会报错!错误原因我想可能是参数传递的问题!
class MyClass
{
public:
virtual char* test(char* str);
}
extern "C" _spedecl(dllport) MyClass* ClassFatory();
extern "C" _spedecl(dllport) void ClassKill(Myclass* my);
char* MyClass::test(char* str);
{
return str;
}
MyClass* ClassFatory()
{
MyClass* my;
my = new MyClass
return my;
}
void ClassKill(MyClass* my)
{
delete my;
}
//上面的代码在VC中顺利编译成DLL
//在Delphi中的引用DLL的代码大概如下:
Type
TMyClass - class(TObject)
public:
virtual function test(str: PChar): PChar;virtual;cdecl;abstract;
end;
function ClassFactory: TMyClass;cdecl;extern 'mydll' name 'ClassFactory';
procedure ClassKill(TMyClass my);;cdecl;extern 'mydll' name 'ClassKill';
procedure TFrom1.btn1Click(Sender: TObject)
var
my: TMyClass
begin
my := ClassFactory;
ShowMessage(string(my.test));
ClassKill(my);
end;
//上面的代码编译都能通过,在点btn1后报错:access violation,就是在my.test处报错,我如果把test中的参数去掉将test返回一个常量字符串,则不会报错!错误原因我想可能是参数传递的问题!