在 delphi 中使用 COM DLL - MSVCR80D.dll 错误中的访问冲突

发布于 2024-07-13 17:59:57 字数 1165 浏览 9 评论 0原文

我需要使用使用 .NET 框架创建的 DLL。 该 DLL 使 COM 可见。

我想在使用 Delphi 2006 创建的应用程序中使用此 DLL。我已执行以下步骤:

  1. 使用 regscr32 注册 DLL。
  2. 使用导入类型库 德尔福集成开发环境。 它创造了 _TLB.pas 文件。 TLB 文件中创建了以下签名。

    函数 TValidationRequest.Process(varmeterBSN: WideString; var NICSerial: WideString;  
                                          var 零件编号:WideString;   var otherConfig: WideString;  
                                          out returnMessage: WideString): Smallint; 
      开始 
        结果:= DefaultInterface.Process(meterBSN,NICSerial,partNumber,otherConfig,returnMessage); 
      结尾; 
      
  3. 我尝试使用调用该方法 以下代码片段。

procedure TForm1.buttonClick(Sender: TObject);
var
  valReq: TValidationRequest;
  s1, s2, s3, s4, s5: WideString;
  o: WideString;
begin
  valReq := TValidationRequest.Create (Self);
  try
    valReq.Process (s1, s2, s3, s4, o);
    MessageDlg(o, mtInformation, [mbOK], 0);
  finally
    valReq := nil;
  end;
end;

但是当调用 Process 方法时出现以下错误。 替代文本

请问您能提出任何解决方案吗?

I need to use a DLL created using .NET framework. This DLL is made COM visible.

I want to use this DLL in an application created using Delphi 2006. I have followed following steps:

  1. Registered the DLL using regscr32.
  2. Imported the type library using
    Delphi IDE. It created
    _TLB.pas file. Following signature was created in TLB file.

    function TValidationRequest.Process(var meterBSN: WideString; var NICSerial: WideString; 
                                        var partNumber: WideString; var otherConfig: WideString; 
                                        out returnMessage: WideString): Smallint;
    begin
      Result := DefaultInterface.Process(meterBSN, NICSerial, partNumber, otherConfig, returnMessage);
    end;
    
  3. I tried to call the method using
    following code snippet.

procedure TForm1.buttonClick(Sender: TObject);
var
  valReq: TValidationRequest;
  s1, s2, s3, s4, s5: WideString;
  o: WideString;
begin
  valReq := TValidationRequest.Create (Self);
  try
    valReq.Process (s1, s2, s3, s4, o);
    MessageDlg(o, mtInformation, [mbOK], 0);
  finally
    valReq := nil;
  end;
end;

But I get following error when Process method is called.
alt text

Please can you suggest any solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第几種人 2024-07-20 17:59:57

尝试初始化 WideStringss1s2s3s4,也许甚至o)。 如果我没记错的话,在设置​​它们之前,它们在 Delphi 中是动态的并且为零(000000000)。

Try initializing the WideStrings (s1,s2,s3,s4, and maybe even o). If I recall correctly, they are dynamic in Delphi and nil (000000000) before you set them up.

飘逸的'云 2024-07-20 17:59:57

除了 MarkusQ 所说的之外,请注意您对 TValidationRequest 对象的内存管理不是很好。 使用Create(nil)然后在finally块中写入FreeAndNil(valReq)会更干净。 现在的方式是,每次单击按钮时都会创建一个 TValidationRequest 对象,并且它们都将保留在内存中,直到您销毁表单。 至少您不会出现内存泄漏,因为您将 Self 传递给了构造函数,因此至少表单会负责销毁这些对象。 在您的示例中,在 TForm1.buttonClick 方法结束后确实不需要保持对象处于活动状态。

In addition to what MarkusQ said, note that your memory management of the TValidationRequest object is not so good. It would be cleaner to use Create(nil) and then in the finally-block write FreeAndNil(valReq). The way it is now you create one TValidationRequest object every time you click the button and they will all stay in memory until you destroy the form. At least you won't get memory leaks because you passed Self to the constructor so at least the form will take care of destroying those objects. In your example there is really no need to keep the object alive after the TForm1.buttonClick method has ended.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文