?
Solved

Using C# dll in Delphi 7

Posted on 2009-05-18
9
Medium Priority
?
4,332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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