Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've created a pretty simple dll in vb.net. I successfully registered it (as administrator) and can call it from a button in a simple vb.net WinForms app I created. It works. It does what I expect. However, I tried using it in a simple Delphi app I also created and it says it can't find it.

Thanks,

Avian

- Windows 10 Pro 64 bit
- VS 2017
- Delphi Tokyo 10.2.3

What I have tried:

My Delphi code is:

Delphi
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxLookAndFeels, cxLookAndFeelPainters,
  Vcl.Menus, Vcl.StdCtrls, cxButtons;

  Function CreateExcelWorkbook: boolean; STDCALL; EXTERNAL 'KTExternalFunctions.dll';

type
  TForm1 = class(TForm)
    cxButton1: TcxButton;
    procedure cxButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.cxButton1Click(Sender: TObject);
begin
  CreateExcelWorkbook;
end;

end.

The Delphi code compiles but when I try to run it I get this error message:

"The code execution cannot proceed because KTExternalFunctions.dll was not found. Reinstalling the program may fix this problem."

Everything I've read about this says that I'm referring to it correctly in my uses clause.

The only difference I can see is that when I call the DLL in my vb.net application I have to qualify it with the class that the function is contained within like this (where KTFunctions is the name of the class):

VB
Imports System.Drawing
Imports DevExpress.Spreadsheet
Imports KTExternalFunctions


Public Class XtraForm1
    Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click

        KTFunctions.CreateExcelWorkbook()


I can't find any examples of this for Delphi and am not sure how to do that or if that's even the entire problem.
Posted
Updated 24-Jun-18 15:45pm
Comments
[no name] 15-Jun-18 15:36pm    
Did you try putting your "new" dll in the same folder from which you are running your Delphi exe?
avianrand 16-Jun-18 13:17pm    
Yes. I did try that. I tried adding the path to the release folder of the dll into the function declaration in Delphi as well. Neither of those worked. I'm sure I'm mucking up something with how I'm creating the dll or how I'm registering it. I tried it as com too, that did nothing. I registered it with RegAsm.exe but even if it's not registered it still works when I call it from my test vb.net app so I'm not sure what's up. I'm not a dll expert by any means. I need to do something in .net that I can run from Delphi because it can't be done in Delphi.

Okay, I know this isn't a solution but there's no good place to put this. I don't want to put it in the O.P. as an "improvement" because it might not get noticed. And if I post it as a comment it doesn't let me create code tags. So it's here.

Earlier I said I was going to handle this with a console application. Although that works, it's not really the way I want to go. I can't return anything of value from a console application and calling it is not elegant at all. I really need this to be a dll.

So I created an even simpler one. I didn't register it. I can use it in another vb.net forms application just fine because it's easy to create a reference to it.

Here's my dll code (there are no special references, just the default ones for a .net dll):

VB
Public Class Class1
    Public Shared Function returnJunk(inputParam As Int16)
        Select Case inputParam
            Case 1
                Return "one"
            Case 2
                Return "two"
            Case 3
                Return "three"
            Case 4
                Return "four"
            Case 5
                Return "five"
            Case Else
                Return "nothing"
        End Select
    End Function
End Class

Here's my call to it from vb.net
VB
Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles SimpleButton2.Click
    MessageBox.Show(TestDLLJunk.Class1.returnJunk(14))
End Sub

In the calling application, I just right clicked references and browsed to where the compiled dll is. It shows the full path to it in the properties of the dll's reference.

So then I did the same as before in Delphi. This is in my interface uses:

Delphi
Function returnJunk(inputParam: Byte): string; STDCALL; EXTERNAL 'TestJunk.dll';


Compiling my dll code creates 3 files. I put them ALL in the source folder of my Delphi project and also in the Win32\debug folder just for grins.

And this is my calling code:
Delphi
procedure TForm1.Button2Click(Sender: TObject);
var
  rj: string;
begin
  rj := returnJunk(4);
end;


Same as before. It compiles but doesn't run. I get the same message as in my O.P.

Then, for the heck of it, I registered it:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe D:\Data\1Work\KT\DelphiTokyoVersion\TokyoConversionTestProjects\TestDLLJunk\bin\Release\TestDLLJunk.dll /tlb /codebase

Same results as before.
 
Share this answer
 
v2
Comments
avianrand 18-Jun-18 20:42pm    
I had an email conversation with a tech support person at Embarcadero. I'm fairly certain that my issue has nothing to do with Delphi. I think it's the way I'm creating the DLL. I created a new question focusing exclusively on that issue:

https://www.codeproject.com/Questions/1248969/My-registered-DLL-doesnt-show-up-in-assemblies-ext

Once that's solved, I'll repost here whatever ends up working.
Never mind on this. I gave up and found an easier more productive way. I'm using AtoZed's CrossTalk to use .net DLL's in Delphi. And I'm using EPPlus in .net to create the Excel files I need. It's all working quite nicely.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900