关于Delphi调用C++Builder编写的DLL中的类的问题! ( 积分: 200 )

  • 主题发起人 主题发起人 ydy
  • 开始时间 开始时间
Y

ydy

Unregistered / Unconfirmed
GUEST, unregistred user!
源代码如下:
C++Builder动态链接库实现:
class __declspec(dllexport) ExampleClass{
public
int x;
virtual int _stdcall getX();
}
extern "C"
{
ExampleCalss* __stdcall __declspec(dllexport) CreateExampleCalss(void)
{
return new ExampleCalss();
}
void __stdcall __declspec(dllexport) FreeExampleCalss(ExampleCalss* Example)
{
delete Example;
}
};
int _stdcall ExampleClass::GetX{
return x;
}
delphi测试
//接口定义
type
ExampleClass = class
public
x: integer;
function GetX: integer;
virtural;
stdcall;
abstract;
end;

procdure CreateExampleCalss: ExampleCalss;
stdcall;
external 'Example.dll';
function FreeExampleCalss(Example: ExampleCalss);
stdcall;
external 'Example';
//测试函数
function GetDllX: integer;
var
MyExample: ExampleClass;
begin
MyExample := CreateExampleCalss;
MyExample.x := 100;
result := MyExample.GetX;
FreeExampleCalss(MyExample);
end;

目前问题是GetDllX总是返回不了值,不知道问题出在那里,各位大老帮忙看看!
 
源代码如下:
C++Builder动态链接库实现:
class __declspec(dllexport) ExampleClass{
public
int x;
virtual int _stdcall getX();
}
extern "C"
{
ExampleCalss* __stdcall __declspec(dllexport) CreateExampleCalss(void)
{
return new ExampleCalss();
}
void __stdcall __declspec(dllexport) FreeExampleCalss(ExampleCalss* Example)
{
delete Example;
}
};
int _stdcall ExampleClass::GetX{
return x;
}
delphi测试
//接口定义
type
ExampleClass = class
public
x: integer;
function GetX: integer;
virtural;
stdcall;
abstract;
end;

procdure CreateExampleCalss: ExampleCalss;
stdcall;
external 'Example.dll';
function FreeExampleCalss(Example: ExampleCalss);
stdcall;
external 'Example';
//测试函数
function GetDllX: integer;
var
MyExample: ExampleClass;
begin
MyExample := CreateExampleCalss;
MyExample.x := 100;
result := MyExample.GetX;
FreeExampleCalss(MyExample);
end;

目前问题是GetDllX总是返回不了值,不知道问题出在那里,各位大老帮忙看看!
 
问题已经找到,结束!
 
后退
顶部