views:

84

answers:

2

I created a vb.net dll called "WSdll.dll". I compiled it, created a type library (tlb), and registered it globally(gacutil).. It includes a file called wsutils.vb, which includes a namespace called "wsutils". In the namespace, there's an interface (with attribute) called "IWSconnection", and a class called "WSconnection". The interface and class are public, as are all methods and properties.

I then tried to implement it in an unmanaged c++ project.

I imported it: #import "..\WSdll\WSdll\bin\Debug\WSdll.tlb" \ raw_interfaces_only, \ named_guids, \ no_namespace

Then tried to create an instance: CComPtr< IWSconnection > pIWSconnection; pIWSconnection.CoCreateInstance( __uuidof( wsutils::WSconnection ) );

I am getting 2 errors a)wsutils is not a class or namespace name b)wsconnection undeclared identifier

What other steps do i have to do to get the dll working here?

TIA

+1  A: 

You put no_namespace in the #import line - so your object is not in the wsutils namespace, it's in the global namespace. Remove either the no_namespace from the #import line, or the wsutils:: from the object creation line.

Seva Alekseyev
Thanks a million! That worked. Now, I have another question:I created the object using: CComPtr< IWSconnection > pIWSconnection; pIWSconnection.CoCreateInstance( __uuidof(IWSconnection ) );Then, when I tried to call a method : pIWSconnection.connect(...)I am getting an error:pIWSconnection undeclared identifierWhy would it work with 'CoCreateInstance', and not with 'connect'?
First off, you should pIWSconnection->connect. By the way, why are you mixing ATL smart pointers (CComPtr) with Native COM?
Seva Alekseyev
+1  A: 

Namespace names used in your VB.NET code are not visible to a COM client. Just omit the wsutils:: prefix. Whenever you are in doubt what the #imported names look like, open the automatically generated .tlh and .tli files with your editor.

Hans Passant
By default, #import places all the interfaces and classes into a namespace that matches the typelib name (the internal name, not the file name). Which, again by default, matches the project name for generated .NET typelibs. Which, by default, is the default namespace for all the classes in the .NET project. :)Regardless, the error is about namespace mismatch.
Seva Alekseyev