• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 995
  • Last Modified:

Using a COM DLL in C++ Builder

I have been provided with a few DLLs which are COM servers, which were produced in Visual C++.  I can open these with Builder's TLB editor, and see all of their properties and methods, but I have no idea how to access them from the IDL file which I can produce there.  The TLB editor doesn't create a header file.  How am I to inform my program about the information in the DLL, in a way that I can create an instance and use the objects provided?

0
sburck
Asked:
sburck
  • 3
  • 3
1 Solution
 
edd13579Commented:
The only way i know is to write your own.
0
 
BorlandManCommented:

Hi,
You might try using 'Import Type Library' under the project menu in the IDE (Integrated Development Environment)

If you don't mind me asking: why do you want to export to IDL?

Your COM objects are OLE/ActiveX Servers?  That is no visual display? Or are they active x controls?

I'm not sure how COM savvy you are, I'll assume your relatively new to it ok?

You said you are viewing the properties and methods in the typelib editor - good this is providing to you what you can call in the Interface.

If you import a type library into your project (there's some information in C++ Builder Help on this), c++ builder will create a .h file which contains information which will allow your application to connect to the dlls(com servers).

You then need to get an interface to the com object and can call the methods in that object.

check out the sample in C++ Builder
-> Examples\Doc\AutoProj\autocInt

this should give you a start or at least an idea of how to go about doing this.

take special note of the autocInt_tlb.h
it has a lot more than what you would typically expect for simple decls in a header file.

hth,
J
0
 
sburckAuthor Commented:
1)  You're correct, I'm generally an embedded developer, COM is relatively new to me.  

2) Import type library does seem to be the way to go.  There are 6 DLLs supplied, and most of them are importing, and I get the classes available.  

3)  There was a problem which I patched, I don't know how well - in each install, I got one compile error.  This function was created:

BSTR __fastcall get_DllName(BSTR* pVal/*[out,retval]*/)
  {
    return GetDefaultInterface()->get_DllName(pVal/*[out,retval]*/);
  }


and I had to add this cast

BSTR __fastcall get_DllName(BSTR* pVal/*[out,retval]*/)
  {
    return (BSTR)GetDefaultInterface()->get_DllName(pVal/*[out,retval]*/);
  }

to get it to compile.  Since I don't think I need this function, I'm hoping it won't be a problem.

In any case, I'll award you the points - there may be more questions down the line as I try to use the results.
0
Industry Leaders: 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!

 
sburckAuthor Commented:
Thanks again.
0
 
BorlandManCommented:
thanks for the points.

what version of c++ builder do you have? do you have the patches?  That might be a bug and a fix may be in a patch.

but it looks to be a simple cast there.

right now I don't have c++ builder on my machine (it's on my other one at another location)... but you might double check that the cast from the zero terminated string (e.g char szDllName[MAX_PATH]) is ok.  The BSTR as you probably know (or will discover) is a string, which can be passed across to other COM clients and Servers.. char* doesn't cut it.

good luck with the COM stuff.

Glad I was able to help you out.
J
0
 
sburckAuthor Commented:
It's Builder 6 with the latest (update 4) patch.  I'll see what Borland has to say about it.  Thanks again.

0
 
BorlandManCommented:

there actually was a mention about a 'beta' version of a new Type Library importer. It said something like there were a few potential bugs with code gen.

http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=18865

not sure if this got rolled into BCB6 current patch yet.

hth,
J
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now