473,503 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


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
11 4165

"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
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

"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

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
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
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
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
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3234
by: Grant | last post by:
I've cross-posted this in the COM+ group as well - apologies if that's a no-no. But the problem might be caused by either... interop or just plain COMAdmin....
0
1395
by: Tom Z. | last post by:
Hi All, I'm trying to make an assembly in C# to use as a COM server. I'm building as normal and ruinning regasm at the end. Everything is generally working, except that I'm having a problem...
1
3557
by: Tom Z. | last post by:
Hi All, I'm trying to make an assembly in C# to use as a COM server. I'm building as normal and ruinning regasm at the end. Everything is generally working, except that I'm having a problem...
1
2452
by: Ping | last post by:
Hi, i am trying to : dim db As database and i have Access 2002. The object type "database" is not in the list and error message is "type mismatching " when run. i am wondering if the...
6
9401
by: Programmer | last post by:
I am making a project in which i have one interface ITest, and a class which is implementing that interface. I am making object of that class using object...
0
2503
by: Erwan | last post by:
I have a strange (but very blocking) result when using the smtpmail class from an ASPX page : here is the (very simple !) code... '-------------------------------------------------- mail.To =...
6
1895
by: Picho | last post by:
Hi all. I have a webservice and a windows app. both of them reference the same class library called WebServiceTest.Core that defines a class called Class1. the webservice exposes a method...
2
3126
by: nigel.stephens | last post by:
nigel.stephens@parasolit.­co.uk Nov 24, 10:04 am show options Newsgroups: microsoft.public.dotnet.framework.interop From: "nigel.steph...@parasolit.co.uk" <nigel.steph...@parasolit.co.uk> -...
7
11919
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.