sburck
asked on
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?
The only way i know is to write your own.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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(p Val/*[out, retval]*/) ;
}
and I had to add this cast
BSTR __fastcall get_DllName(BSTR* pVal/*[out,retval]*/)
{
return (BSTR)GetDefaultInterface( )->get_Dll Name(pVal/ *[out,retv al]*/);
}
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.
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
}
and I had to add this cast
BSTR __fastcall get_DllName(BSTR* pVal/*[out,retval]*/)
{
return (BSTR)GetDefaultInterface(
}
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.
ASKER
Thanks again.
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
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
ASKER
It's Builder 6 with the latest (update 4) patch. I'll see what Borland has to say about it. Thanks again.
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