-
September 11th, 2003, 06:02 AM
#1
Can I use tlb file in vc++
Dear experts,
What my doubt is:
Server application:COM dll
Client application: Vc++:
Generally what will u do is you will include *.h and *_i.c files in vc++ application to access the functionality of COM dll.
Instead of using those files could you use the .tllb file(generally its for vb clients), in vc++ application.
If yes,what functionality I have to write inorder to access that COM dll functionality(you can't call CocreateInstnace() and all that stuff).
If no,why?
please help me out.
Thanks
Rama.
-
September 24th, 2003, 08:38 AM
#2
use #import directive, for example:
#import "MyCOMFile.tlb" no_namespace
This statement creates two files in Debug/Release folders whose extention files are .tlh and .tli .
This files defines the com interface and smart-pointer typedef declarations which call CoCreateInstance for you and handle the reference-count automatically.
(The smart-pointer typedef is the name of the interface concatenated with 'Ptr'. That is, if IFoo is the interface then the smart-pointer type is IFooPtr).
Suppose the interface is IFoo, then the client code should look like this:
Code:
#import "MyCOMFile.tlb" no_namespace
void main()
{
CoInitialize(NULL);
try
{
IFooPtr pFoo(__uuidof(Foo));
pFoo->Method();
}
CoUnintialize();
}
Allways work that way as COM client.
Thats all.
-
July 5th, 2010, 02:29 AM
#3
Re: Can I use tlb file in vc++
I do not quite understand the solution provided previously. I am .NET developer and not a C++ programmer. Will this solution work in my example. I have developed a VB.NET version 1.1 dll (say "MyCOMFile.dll") and have made it COM compatible i.e. I have a class called say Class1 and an associated Interface _Class1 and hence it has a type library (MyCOMFile.tlb) file automatically built when compiled.
When I call it in say a vbScript file I use the following code:
Dim myClass1
Set myClass1 = CreateObject("My2.PartNamespace.Class1")
myClass1.PublicProperty = 2
myClass1.MySub "xx"
Dim y
y = Class1.MyFunc(15)
'etc
NB: my vbScript file and dll/tlb files are all in the same folder.
How do I do the equivalent in C++? Going from the solution provided is this correct?
In my .cpp file:
#import "MyCOMFile.tlb" My2.PartNamespace //Does this namespace need quote marks or do I use a Using statement???
void main()
{
int y;
CoInitialize(NULL);
try
{
_Class1Ptr pClass1(__uuidof(Class1));
pClass1->PublicProperty = 2;
pClass1->MySub("xx");
y = pClass1->MyFunc(15);
// Do I have to UnIntialise my dll when cleaning up???
}
CoUnintialize();
//Use y
}
Also can my dll and tlb file sit in the same folder as the cpp file or do I need to put it in the GAC?
-
April 15th, 2011, 04:49 AM
#4
Re: Can I use tlb file in vc++
Hello
I have some problem with COM. I created one dll in VB.NET. I want to use that dll in vc++. So I created tlb file based on vb.net dll. I create tbl file using
"RegAsm.exe ManagedDLL.dll /tlb:ManagedDLL.tlb /codebase"
Now, I import this tbl file to my vc++ code as below
#import "D:\tlbFile\SetupValidation.tlb" named_guids raw_interfaces_only
This works fine...
My problem is, this is the static path from where I import tlb file. Now, this tlb is anywhere in the computer on client machine. I want dynamically import this tlb file. Should I have to bind this tlb file in the project or any other soution??
Please help me. I am working in vb.net I am new in vc++.
Thanks
Ankit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|