Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2004

Tip: Looking for answers? Try searching our database.

How to Get .Net dll's ClassId on VC++6 before CoCreateInstance ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maverick - 15 Jul 2004 04:46 GMT
In VC++, I have to hardcoded the .net dll's ClassId if i want to create the com instance. How can i get the .net COM's classID without having to create the instance first ?

---------------------------------------
#import "Sample.tlb"
using namespace Sample;

//******NOTE******
const IID CLSID_SampleObj = {0x5B85B3EB,0x899B,0x440f, {0xBF,0x0A,0x67,0x43,0x0B,0x7A,0x17,0x1F}};    

int main(int argc, char* argv[])
{
   HRESULT hr;
   CoInitialize(NULL);   
   
   CComPtr<SampleObj> Obj = NULL;       
   hr = Obj.CoCreateInstance(CLSID_SampleObj, NULL, CLSCTX_ALL);

   string tooLateToGetClsidHere = Obj->GetCLSID();
}

------------------------------------------------------------------------------
Phil Wilson - 16 Jul 2004 15:49 GMT
This is a confusing question - the entire COM client-server model is based
on the client knowing the clsid before calling the COM server (or knowing a
ProgId, which amounts to the same thing). How could you *not* know the clsid
of your object? Would a ProgId solve your problem? That import will generate
a header file that will have some Guids in it - is that what you're looking
for?
Signature

Phil Wilson
[MVP Windows Installer]

> In VC++, I have to hardcoded the .net dll's ClassId if i want to create the com instance. How can i get the .net COM's classID without having to
create the instance first ?

> ---------------------------------------
> #import "Sample.tlb"
[quoted text clipped - 15 lines]
>
> ------------------------------------------------------------------------------
Maverick - 20 Jul 2004 05:09 GMT
thx... in fact, i was so stupid. There's no need to have the CLSID when doing CoCreateInstance of a .Net COM in VC++6 application. All i need to do is the following :

#import "C:\\MyCOMObj.tlb"
using namespace MyCOMObj;

int main()
{
HRESULT hr;
CoInitialize(NULL);   
   
CComPtr<CSampleObj> obj = NULL;       
hr = obj.CoCreateInstance(__uuidof(CSampleObj));
}

> This is a confusing question - the entire COM client-server model is based
> on the client knowing the clsid before calling the COM server (or knowing a
[quoted text clipped - 27 lines]
> > --------------------------------------------------------------------------
> ----
Naveen K Kohli - 19 Jul 2004 19:06 GMT
You can always CLSID from ProgId using ProgIDFromCLSID API.

Naveen
http://www.netomatix.com

> In VC++, I have to hardcoded the .net dll's ClassId if i want to create the com instance. How can i get the .net COM's classID without having to
create the instance first ?

> ---------------------------------------
> #import "Sample.tlb"
[quoted text clipped - 15 lines]
>
> ------------------------------------------------------------------------------

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.