关于在vc中调用delphi中制作的dll的问题(20分)

  • 主题发起人 主题发起人 huanzhugege
  • 开始时间 开始时间
H

huanzhugege

Unregistered / Unconfirmed
GUEST, unregistred user!
这是delphi中的定义
function SincoGetDriveType(ADriveName: PChar)
: PChar
stdcall;
var
x: integer;
begin
x := GetDriveType(ADriveName);
case x of
1: result := 'UnExist Drive';
DRIVE_REMOVABLE: result := 'Movable Drive';
DRIVE_FIXED: result := 'Fixed Drive';
DRIVE_REMOTE: result := 'Network Drive';
DRIVE_CDROM: result := 'CDRom Drive';
DRIVE_RAMDISK: result := 'RAM Drive';
else
result := 'Unknown Type';
end;

end;
这是在vc中调用:

HINSTANCE gMyDll = NULL;
typedef char*(*SINCOGEtDRVIETYPE)(char*);
SINCOGEtDRVIETYPE SincoGetDriveType;
char disk[]="c://";
char* str;
gMyDll = LoadLibrary("drivetype.dll");
SincoGetDriveType = (SINCOGEtDRVIETYPE)GetProcAddress(gMyDll,"SincoGetDriveType");
str=SincoGetDriveType(disk);
FreeLibrary(gMyDll);

为什么会出错呢?
 
type DriveInfoType=array[0..30] of char;

const DriveInfo:array[0..6] of DriveInfoType=('Unknown Type','DRIVE_NO_ROOT_DIR','DRIVE_REMOVABLE'
,'Fixed Drive','Network Drive','CDRom Drive','RAM Drive');
function SincoGetDriveType(ADriveName: PChar)
: PChar
stdcall;
var
x: integer;
begin
x := GetDriveType(ADriveName);
result := DriveInfo[x];

end;
 
后退
顶部