Solved

Using C# dll in Delphi 7

Posted on 2009-05-18
9
4,224 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed 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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

737 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