X
xewei
Unregistered / Unconfirmed
GUEST, unregistred user!
我想在我的DLL中使用变参以返回多个变量,可是出错.
我使用了PCHAR类型代替STRING仍然出错
本想用自定义类型实现此功能,但不知道DLL是否支持导出DLL自定义类型,如我自定义的类或记录集
以下是代码
{DLL定义的过程}
procedure GetRegUserInfo(var UserName,SerialNo,UnitName,UserAddr,Email,UserPhonechar);far;
var
reg:TRegistry;
begin
//初始化
UserName := '';
SerialNo := '';
UnitName := '';
UserAddr := '';
Email := '';
UserPhone := '';
reg:=TRegistry.Create;//创建实例
reg.RootKey:=HKEY_CURRENT_USER;//指定需要操作的注册表的主键
if reg.OpenKey(FDRegDirectory,true) then//如果打开成功则进行以下操作
begin
UserName := Pchar(reg.ReadString(FDRegUserName));
SerialNo := Pchar(reg.ReadString(FDRegSerialNo));
UnitName := Pchar(reg.ReadString(FDRegUnitName));
UserAddr := Pchar(reg.ReadString(FDRegUserAddr));
Email := Pchar(reg.ReadString(FDRegEmail));
UserPhone := Pchar(reg.ReadString(FDRegUserPhone));
end;
reg.CloseKey;//关闭注册表
reg.Free;//释放变量所占内存
end;
{调用DLL}
procedure TRegisterForm.FormCreate(Sender: TObject);
type
TProc = Procedure(var UserName,SerialNo,UnitName,UserAddr,Email,UserPhonechar);
var
Th:Thandle;
Tc:TProc;
Tp:TFarProc;
UserName,SerialNo,UnitName,UserAddr,Email,UserPhonechar;
begin
Th:=LoadLibrary('cxw.dll')
{装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('GetRegUserInfo'));
if Tp<>nil
then begin
Tc:=TProc(Tp);
/////////////////////////////////////
//此处出错,一定要帮我解决阿
/////////////////////////////////////
Tc(UserName,SerialNo,UnitName,UserAddr,Email,UserPhone)
{调用过程}
end
else
begin
Application.MessageBox('GetRegUserInfo过程没有找到!','错误',MB_OK+MB_ICONERROR);
application.Terminate;
end;
finally
FreeLibrary(Th)
{释放DLL}
end
else
begin
Application.MessageBox('Cxw.dll没有找到!','错误',MB_OK+MB_ICONERROR);
application.Terminate;
end;
if trim(string(UserName))='' then
begin
Application.MessageBox('您不是本软件注册用户,请注册!','软件注册',MB_OK+MB_ICONINFORMATION);
end
else
begin
edUserName.Text := string(UserName);
edSerialNumber.Text := string(SerialNo);
edUnitName.Text := string(UnitName);
edUserAddr.Text := string(UserAddr);
edEmail.Text := string(Email);
edUserPhone.Text := string(UserPhone);
edUserName.Enabled := false;
edSerialNumber.Enabled := false;
edUnitName.Enabled := false;
edUserAddr.Enabled := false;
edEmail.Enabled := false;
edUserPhone.Enabled := false;
btnRegister.Enabled := false;
end;
end;
我使用了PCHAR类型代替STRING仍然出错
本想用自定义类型实现此功能,但不知道DLL是否支持导出DLL自定义类型,如我自定义的类或记录集
以下是代码
{DLL定义的过程}
procedure GetRegUserInfo(var UserName,SerialNo,UnitName,UserAddr,Email,UserPhonechar);far;
var
reg:TRegistry;
begin
//初始化
UserName := '';
SerialNo := '';
UnitName := '';
UserAddr := '';
Email := '';
UserPhone := '';
reg:=TRegistry.Create;//创建实例
reg.RootKey:=HKEY_CURRENT_USER;//指定需要操作的注册表的主键
if reg.OpenKey(FDRegDirectory,true) then//如果打开成功则进行以下操作
begin
UserName := Pchar(reg.ReadString(FDRegUserName));
SerialNo := Pchar(reg.ReadString(FDRegSerialNo));
UnitName := Pchar(reg.ReadString(FDRegUnitName));
UserAddr := Pchar(reg.ReadString(FDRegUserAddr));
Email := Pchar(reg.ReadString(FDRegEmail));
UserPhone := Pchar(reg.ReadString(FDRegUserPhone));
end;
reg.CloseKey;//关闭注册表
reg.Free;//释放变量所占内存
end;
{调用DLL}
procedure TRegisterForm.FormCreate(Sender: TObject);
type
TProc = Procedure(var UserName,SerialNo,UnitName,UserAddr,Email,UserPhonechar);
var
Th:Thandle;
Tc:TProc;
Tp:TFarProc;
UserName,SerialNo,UnitName,UserAddr,Email,UserPhonechar;
begin
Th:=LoadLibrary('cxw.dll')
{装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('GetRegUserInfo'));
if Tp<>nil
then begin
Tc:=TProc(Tp);
/////////////////////////////////////
//此处出错,一定要帮我解决阿
/////////////////////////////////////
Tc(UserName,SerialNo,UnitName,UserAddr,Email,UserPhone)
{调用过程}
end
else
begin
Application.MessageBox('GetRegUserInfo过程没有找到!','错误',MB_OK+MB_ICONERROR);
application.Terminate;
end;
finally
FreeLibrary(Th)
{释放DLL}
end
else
begin
Application.MessageBox('Cxw.dll没有找到!','错误',MB_OK+MB_ICONERROR);
application.Terminate;
end;
if trim(string(UserName))='' then
begin
Application.MessageBox('您不是本软件注册用户,请注册!','软件注册',MB_OK+MB_ICONINFORMATION);
end
else
begin
edUserName.Text := string(UserName);
edSerialNumber.Text := string(SerialNo);
edUnitName.Text := string(UnitName);
edUserAddr.Text := string(UserAddr);
edEmail.Text := string(Email);
edUserPhone.Text := string(UserPhone);
edUserName.Enabled := false;
edSerialNumber.Enabled := false;
edUnitName.Enabled := false;
edUserAddr.Enabled := false;
edEmail.Enabled := false;
edUserPhone.Enabled := false;
btnRegister.Enabled := false;
end;
end;