Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ATL: ATL events question

Posted on 2003-11-09
13
Medium Priority
?
549 Views
Last Modified: 2013-11-25
Hi,
I have a COM VC++ server which fires events and a VC++ client which catching the event using an ATL sink (IDispEventImpl). I have a SINK_MAP in the client, and the events are recieved OK.
My question is:
In the client I'm using #import to the .tlb/.dll of the server. If I do not use "named_guids" attribute, then I do
not get the events. Are the "named_guids" is a must attribute to recieve events ???

If it is a must then I have a second problem:
My server contains several Dll's, and inorder to make the client simpler I use the "rename_namespace" attribute to one common name:
#import "MyDll1.tlb" rename_namespace ("MyProj")
#import "MyDll2.tlb" rename_namespace ("MyProj")
#import "MyDll3.tlb" rename_namespace ("MyProj")
Now, when trying to add the "named_guids" attribute to each one of the "import" lines, I fail in compilation:
"'LIBID_MyProj' : redefinition; multiple initialization... "

Can someone please advise ???
thanks,
Yoav.
0
Comment
Question by:yoavo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 3

Expert Comment

by:komar
ID: 9710511
Hi,

I'm not that expert in COM programming, but I have a suggestion. Try to put the imports in the client code like this:

     #import "MyDll1.tlb" rename_namespace ("MyProj1")
     #import "MyDll2.tlb" rename_namespace ("MyProj2")
     #import "MyDll3.tlb" rename_namespace ("MyProj3")

Then put:

     using namespace MyProj1;
     using namespace MyProj2;
     using namespace MyProj3;

Then add the "named_guids" attribute and try to compile.

Thanks,
Khalid Omar.
0
 

Author Comment

by:yoavo
ID: 9712900
This will probably work, but as I mentioned before I want all the Dll's to be renamed to one name.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9716403
Your problem is the precise reason why libraries have their own namespaces in the first place.

[un]Fortunately, there is a solution to your problem.


[this post may be wrapped - if so unwrap it!!]

#import "MyDll1.tlb" rename_namespace ("MyProj") rename("LIBID_MyProj","LIBID_MyProj1") named_guids
#import "MyDll2.tlb" rename_namespace ("MyProj") rename("LIBID_MyProj","LIBID_MyProj2") named_guids
#import "MyDll3.tlb" rename_namespace ("MyProj") rename("LIBID_MyProj","LIBID_MyProj3") named_guids
0
Independent Software Vendors: 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!

 

Author Comment

by:yoavo
ID: 9720579
I tried it but it doesn't work. I still get the compile error message.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9720879
With the exact same error ??

"'LIBID_MyProj' : redefinition; multiple initialization... "
0
 

Author Comment

by:yoavo
ID: 9720925
Yes.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9720976
Try excluding the LIBIDs, as they're generally never referenced anyway.

[this post may be wrapped - if so unwrap it!!]

#import "MyDll1.tlb" rename_namespace ("MyProj") exclude("LIBID_MyProj") named_guids
#import "MyDll2.tlb" rename_namespace ("MyProj") exclude("LIBID_MyProj") named_guids
#import "MyDll3.tlb" rename_namespace ("MyProj") exclude("LIBID_MyProj") named_guids
0
 

Author Comment

by:yoavo
ID: 9721028
I still get the same error...
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9721052
Just noticed an error in my orignal post. Sorry.

[this post may be wrapped - if so unwrap it!!]

#import "MyDll1.tlb" rename_namespace ("MyProj") rename("MyProjLib","MyProjLib1") named_guids
#import "MyDll2.tlb" rename_namespace ("MyProj") rename("MyProjLib","MyProjLib2") named_guids
#import "MyDll3.tlb" rename_namespace ("MyProj") rename("MyProjLib","MyProjLib3") named_guids

The LIBID don't even exist yet, so you can't rename them. It should be the name of the library itself.

In your original IDL, you should have:
[
    uuid(...),
    version(x.x),
    helpstring("blah Type Library")
]
library MyProjLib  //*** this is the name you want to specify for rename
{
    ...
}
0
 

Author Comment

by:yoavo
ID: 9721408
"MyProjLib" is not written in any idl !!!
"MyProj" is just a name that the client renamed for easy access to the tlb's of the client.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9721430
Yes, but those original tlb files must have been generated from source. It's that source that you need to view, to ascertain what name it is you're wanting to rename in the first place.

It is likely to be the original namespace name.
0
 

Author Comment

by:yoavo
ID: 9721490
I tried it. still I get the same error...
0
 
LVL 9

Accepted Solution

by:
_ys_ earned 300 total points
ID: 9722625
Finally got to the bottom of your error.

rename_namespace renames the would-be library clause within the original IDL. Therefore trying to rename them all to a common name will simply not work [I learned something here as well].

I composed a simple test project, and all went well. So here is what you'll need to do to give them a common namespace.

// Let everything retain their original namespaces
#import "MyDll1.tlb" named_guids
#import "MyDll2.tlb" named_guids
#import "MyDll3.tlb" named_guids

// Bring everything into the scope of namespace MyProj
namespace MyProj
{
    using namespace MyProj1; //*** this  is whatever the original namespace is
    using namespace MyProj2;
    using namespace MyProj3;
}

After this MyProj will have everything defined within it. Of course everything is still accessible from within the original namespaces as well, but at least they're also visible from the common namespace.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question