By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,594 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,594 IT Pros & Developers. It's quick & easy.

COM object (no type library) - how do I access the interface from VB.NET?

P: n/a

I have a COM object, which implements straightforwardly the IDataObject
interface. It seems this isn't the same IDataObject interface we now have
with .NET. Basically, the COM object implements low level interfaces. It
does not have a type library. We use it freely with our unmanaged C++
projects. What I would like to do is load or create one of these objects in
VB.NET, but I cannot seem to do it.

I've tried:

Dim theObject As Object

theObject = GetObject ( "c:\gas.tgw" ) * gas.tgw is a file-type we
associated with the COM object

but how do I get the IDataObject interface from theObject?

Is it possible to use basic low-level COM interfaces with VB.NET?

Any answers would be much appreciated.
Nov 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a

"Robin Tucker" <r.******@thermoteknix.com> wrote in message
news:bk*******************@news.demon.co.uk...

I have a COM object, which implements straightforwardly the IDataObject
interface. It seems this isn't the same IDataObject interface we now have
with .NET. Basically, the COM object implements low level interfaces. It
does not have a type library. We use it freely with our unmanaged C++
projects. What I would like to do is load or create one of these objects in VB.NET, but I cannot seem to do it.

I've tried:

Dim theObject As Object

theObject = GetObject ( "c:\gas.tgw" ) * gas.tgw is a file-type we
associated with the COM object

but how do I get the IDataObject interface from theObject?

Is it possible to use basic low-level COM interfaces with VB.NET?


Sure, you can use the COM interfaces but you need a type library. Then you
need to generate an Interop Assembly.

The type library may be embedded in the dll, or you could create it if you
have the MSIL interface definitions.

David
Nov 20 '05 #2

P: n/a
So I definately need a type library? There is no way we can generate one
for this program - it implements IDataObject in COM but it isn't an
automation object. I would have thought it would just be a case of finding
the interface using "FindInterfaces". But obviously not. In this case,
VB.NET can't be properly supporting com I guess, if it only supports objects
with type libs.

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:O6**************@TK2MSFTNGP12.phx.gbl...

"Robin Tucker" <r.******@thermoteknix.com> wrote in message
news:bk*******************@news.demon.co.uk...

I have a COM object, which implements straightforwardly the IDataObject
interface. It seems this isn't the same IDataObject interface we now have with .NET. Basically, the COM object implements low level interfaces. It does not have a type library. We use it freely with our unmanaged C++
projects. What I would like to do is load or create one of these
objects in
VB.NET, but I cannot seem to do it.

I've tried:

Dim theObject As Object

theObject = GetObject ( "c:\gas.tgw" ) * gas.tgw is a file-type we
associated with the COM object

but how do I get the IDataObject interface from theObject?

Is it possible to use basic low-level COM interfaces with VB.NET?


Sure, you can use the COM interfaces but you need a type library. Then you
need to generate an Interop Assembly.

The type library may be embedded in the dll, or you could create it if you
have the MSIL interface definitions.

David

Nov 20 '05 #3

P: n/a

"Robin Tucker" <r.******@thermoteknix.com> wrote in message
news:bk*******************@news.demon.co.uk...
So I definately need a type library? There is no way we can generate one
for this program - it implements IDataObject in COM but it isn't an
automation object. I would have thought it would just be a case of finding the interface using "FindInterfaces". But obviously not. In this case,
VB.NET can't be properly supporting com I guess, if it only supports objects with type libs.


How do the unmanaged C++ programs use this component?

Do they have the interface definitions?
Do they use IDispach?

David

Nov 20 '05 #4

P: n/a

Something like this - we use CoGetObject - this is part of a method that
gets data from the object and converts it into a DIB for rendering. As you
can see, I may have my work cut-out in VB.NET! (but vb might get ditched if
I cannot do things like this).
// Connect to the object.
IDataObjectPtr image;
TryMethod(CoGetObject(display_name, 0, IID_IDataObject, (void**)&image));
// First try to get a DIB.
FORMATETC fe = { CF_DIB, 0, DVASPECT_CONTENT, index, TYMED_HGLOBAL };
if (SUCCEEDED(image->GetData(&fe, &sm)))
{



Nov 20 '05 #5

P: n/a
We implement the following interfaces on the object:

IClientSecurity
IDataObject
IDispatch
IMarshal
IMultiQI
IOleContainer
IOleInPlaceActiveObject
IOleInPlaceObject
IOleItemContainer
IOleObject
IOleWindow
IParseDisplayName
IPersist
IPersistFile
IPersistStorage
IProxyManager
IUnknown

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl...

"Robin Tucker" <r.******@thermoteknix.com> wrote in message
news:bk*******************@news.demon.co.uk...
So I definately need a type library? There is no way we can generate one for this program - it implements IDataObject in COM but it isn't an
automation object. I would have thought it would just be a case of

finding
the interface using "FindInterfaces". But obviously not. In this case,
VB.NET can't be properly supporting com I guess, if it only supports

objects
with type libs.


How do the unmanaged C++ programs use this component?

Do they have the interface definitions?
Do they use IDispach?

David

Nov 20 '05 #6

P: n/a
Hi Robin,

Have you tried hauling in your component by adding a Reference to your
project? When I tried that (a long time ago) it said something like "There's
no blah, blah, would you like me to create an Interop wrapper?". Yes please
and off you go. It may not be clever enough to map all your functions but then
again, it may.

Regards,
Fergus
MVP [Windows Start button, Shutdown dialogue]
Nov 20 '05 #7

P: n/a
No chance! It says it isn't a valid COM component or assembly, which, in a
sense, I guess is true. The component won't show up in the COM tab because
it doesn't have a typelib and it isn't an automation object. My guess is it
just isn't possible and I will either have to create a C++ source file that
will do it for me and somehow links into VB.NET or I will ditch VB.NET and
go back to plain old C++, ATL etc.

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
Hi Robin,

Have you tried hauling in your component by adding a Reference to your
project? When I tried that (a long time ago) it said something like "There's no blah, blah, would you like me to create an Interop wrapper?". Yes please and off you go. It may not be clever enough to map all your functions but then again, it may.

Regards,
Fergus
MVP [Windows Start button, Shutdown dialogue]

Nov 20 '05 #8

P: n/a
Hi Robin,

Shame about that. I'd go the C++ wrapper and then get a .NET wrapper. And
then you can write some wrapper classes around it in VB.NET just so it feels
really warm and cosy. :-)

Go back?? You can't go back. Or maybe I'm just biased.

Best wishes,
Fergus
MVP [Windows Start button, Shutdown dialogue]
Nov 20 '05 #9

P: n/a
What I don't understand about this situation is the files will happily embed
in Word documents (Insert->Object) - so I must be doing something wrong!

I don't want to go back to C++ - luckily I'm just experimenting with VB.NET
at the start of a project which, after much deliberation, we decided would
be best written in VB.NET. Of course, provided our existing COM components
were compatible. Designing a nice looking UI is a pain in the ass with ATL.
I am going to jump out of the office window if I have to do that.

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:ud**************@TK2MSFTNGP12.phx.gbl...
Hi Robin,

Shame about that. I'd go the C++ wrapper and then get a .NET wrapper. And then you can write some wrapper classes around it in VB.NET just so it feels really warm and cosy. :-)

Go back?? You can't go back. Or maybe I'm just biased.

Best wishes,
Fergus
MVP [Windows Start button, Shutdown dialogue]

Nov 20 '05 #10

P: n/a

"Robin Tucker" <r.******@thermoteknix.com> wrote in message
news:bk*******************@news.demon.co.uk...

Something like this - we use CoGetObject - this is part of a method that
gets data from the object and converts it into a DIB for rendering. As you can see, I may have my work cut-out in VB.NET! (but vb might get ditched if I cannot do things like this).
// Connect to the object.
IDataObjectPtr image;
TryMethod(CoGetObject(display_name, 0, IID_IDataObject, (void**)&image));
// First try to get a DIB.
FORMATETC fe = { CF_DIB, 0, DVASPECT_CONTENT, index, TYMED_HGLOBAL };
if (SUCCEEDED(image->GetData(&fe, &sm)))
{

Great!!

You should have what you need.

In your C++ program source folder you should have either the .tlb or an .idl
file.

If you have an .idl file, just run midl.exe on it and it will output the
type library (as well as some .c stubs which you don't need). Then in
dotnet just add a reference to the .tlb file.

David

Nov 20 '05 #11

P: n/a
A few things to try:

midl
tlbimp
tlbexp (i think)

failing that, a fantastic way to make managed wrappers for non managed code
(COM or otherwise) is by using Managed C++
If you're proficient with C++ managed C++ will let you perfectly tune how
you expose your existing C/C++ code to the managed world. You can write
the remainder of your app in VB.NET...


--------------------
From: "Robin Tucker" <r.******@thermoteknix.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: Re: COM object (no type library) - how do I access the interface from VB.NET?Date: Thu, 18 Sep 2003 22:10:13 +0100
Lines: 29
Message-ID: <bk*******************@news.demon.co.uk>
References: <bk*******************@news.demon.co.uk> <O6**************@TK2MSFTNGP12.phx.gbl>
<bk*******************@news.demon.co.uk>
<Or**************@tk2msftngp13.phx.gbl>NNTP-Posting-Host: 80.176.255.158
X-Trace: news.demon.co.uk 1063919309 20922 80.176.255.158 (18 Sep 2003 21:08:29 GMT)X-Complaints-To: ab***@demon.net
NNTP-Posting-Date: Thu, 18 Sep 2003 21:08:29 +0000 (UTC)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MSMail-Priority: Normal
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!kibo.news.demon.net!news.demon.co.uk!demon!no t-for-mailXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:139063
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

No chance! It says it isn't a valid COM component or assembly, which, in a
sense, I guess is true. The component won't show up in the COM tab becauseit doesn't have a typelib and it isn't an automation object. My guess is itjust isn't possible and I will either have to create a C++ source file that
will do it for me and somehow links into VB.NET or I will ditch VB.NET and
go back to plain old C++, ATL etc.

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
Hi Robin,

Have you tried hauling in your component by adding a Reference to your project? When I tried that (a long time ago) it said something like

"There's
no blah, blah, would you like me to create an Interop wrapper?". Yes

please
and off you go. It may not be clever enough to map all your functions but

then
again, it may.

Regards,
Fergus
MVP [Windows Start button, Shutdown dialogue]



Matt Evans
--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.