Solved

Using C# dll in Delphi 7

Posted on 2009-05-18
9
4,091 Views
Last Modified: 2012-05-07
I have been supplied with a dll and tlb written in C# called comwrapper

I registered the dll using

regasm  comwrapper

I opened a new project and used the import type library option to import this and create a comwrapper_tlb.bas file. IT has 2 compnents - Twrapper and Tchannel

This has been added to my project and  my test program has the following code

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,comwrapper_tlb;

.
.
.
implementation

{$R *.dfm}

var
  ocwrap: Twrapper;
.
.
    ocwrap:=twrapper.create(self);
.
.

However whenever I try to access functions or procedures in the tlb I get a compile error

eg

   ocwrap.inittimechannel(s);

Gives "Undeclared Identifier: 'inittimechannel'"

 The comwrapper_tlb.bas has this function declared
.
.
// *********************************************************************//
// Interface: Dispatch_OcWrapper
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {80C594DF-DC34-3C8C-AB52-C1FD15BA1361}
// *********************************************************************//
  Dispatch_OcWrapper = interface(IDispatch)
    ['{80C594DF-DC34-3C8C-AB52-C1FD15BA1361}']
    function InitTimeChannel(const sChannelName: WideString): WordBool; safecall;
    procedure Connect; safecall;
    procedure Disconnect; safecall;
    function GetData: WideString; safecall;
    function SetStartTimeIndex(startTime: Double): WordBool; safecall;
  end;

// *********************************************************************//
// DispIntf:  Dispatch_OcWrapperDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {80C594DF-DC34-3C8C-AB52-C1FD15BA1361}
// *********************************************************************//
  Dispatch_OcWrapperDisp = dispinterface
    ['{80C594DF-DC34-3C8C-AB52-C1FD15BA1361}']
    function InitTimeChannel(const sChannelName: WideString): WordBool; dispid 1;
    procedure Connect; dispid 2;
    procedure Disconnect; dispid 3;
    function GetData: WideString; dispid 4;
    function SetStartTimeIndex(startTime: Double): WordBool; dispid 5;
  end;
.
.

Other factors.

We have a VB6 running using the same TLB, although it won't run in the IDE only as an exe.
When the objectname is typed the popup completion list includes the functions as listed above.

The tlb file is described as

C:\Program Files\Borland\Delphi7\Imports\COMWrapper_TLB.pas

in the title of the code list. However I can not see that file in windows explorer.
Show hidden files is on, hide protected operating system files is off.

The dpk file itself is supposed to be in C:\Program Files\Borland\Delphi7\lib but again is not visible in Explorer.

Any help would really be appreciated.
0
Comment
Question by:Kymberley
9 Comments
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 24413441
0
 

Author Comment

by:Kymberley
ID: 24413703
Nothing really helpful there.

I did try tlibimport.exe to recreate the _tlb.pas file.  I then replace the original file with the new one.

This caused the error to occur on the declaration of the Twrapper type
0
 

Author Comment

by:Kymberley
ID: 24413784
When I switched back to the _tlb.pas in the delphi 7 subdirectory  that error goes away but I can't reference  the functions.

Interesting sideline. If I try to add the comwrapper.bpl or the compwrapper_tlb to pas files to the project, they do appear in the open file dialog, but not in explorer itself.
0
 
LVL 6

Expert Comment

by:House_of_Dexter
ID: 24454706
First Make sure there's no problems with your com object...import it into a new C# project and try to call it...
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Kymberley
ID: 24464140
The dll/tlb work with VB6 on my PC and i was supplied with a C# exe that was the original demo.

THe problem seems to be setting up the references in Delphi 7, assuming that this is possible in the first place.
0
 
LVL 6

Expert Comment

by:House_of_Dexter
ID: 24466855
Calling it through VB6 tells us nothing...I don't know if your calling it through a variant using the IDispatch...You need to import into a highly typed language like Delphi or C#...or a .Net language...if all else fails do it like VB6 and use a variant and call it through the IDispatch...
0
 

Author Comment

by:Kymberley
ID: 24542754
Sorry for the apparent lack of interest but I have left the US and am now back home in Australia and finally getting back on to this problem.

the VB code starts like this

Public ocWrap As Dispatch_OcWrapper
.
    Set ocWrap = New Wrapper
.
   ocWrap.InitTimeChannel("DMEA")
.
   ocWrap.Connect

The connect command then brings up a dialog that is embedded in the dll.


0
 

Accepted Solution

by:
Kymberley earned 0 total points
ID: 24666636
It seems the answer to my problem was to use Managed VCL.  I found this out myself and was helped by the developer of that product.
0
 

Expert Comment

by:charleslogan
ID: 25307564
You can use Cross-Talk Project here

http://www.atozed.com/CrossTalk/Blog/20090503.en.aspx

CrossTalk is a project for Delphi that allows native Delphi code to consume .NET code in a very transparent way, very much like referencing a package. Select .NET classes you want to use from Delphi, and that's it. Very much like in C#, or VB.NET. Or at least as close as possible without Delphi being managed code.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now