Using a tlb file in .Net 2005 solution

Hello experts, see if you can help me on this one.

I have a .TLB file that I need to interract with.  Not sure when or where this TLB file was made, but I have API documentation on it, and I need to use it in a C# .Net VS 2005 app.

I tried adding a reference to this .tlb file, but VS2005 barked at me and said it was either not a real com object or corrupted, etc.  

So then I tried the manual way of importing by using the tlbimp.exe utility.  This seemed to work.  It created a DLL from this tlb file.  I added a reference to the newly created DLL.  The reference added fine, it shows up in my project, all the function associated with it show up in intellisense, everything seemed okay.

So then I went to actually use it.  And when I am debugging the code, it errors out when I run it.  When it gets to the point where I use a function associated with this DLL it says, "Retreiving the COM class factory for component with CLSID {bleah bleah} failed due to the following error : 80040154."

So I researched that up a bit, couldn't find much, other than some discussions about it (the com dll) not being registered.  So I tried using the regsvr32.exe utility to try to register it.  This didn't work, said it couldn't find the dll entry point or something like that.  So I researched that, came to come things that said if that happens you need to use the regasm.exe utility.  So I tried that, and, it was able to successfully register it.  So, I tried re-running the code again now that I theoretically have the com dll registered.  Well, run the code, and I get the same exact error.  The 'could not retrieve due to error code: 80040154' stuff.

I'm sorta at a brick wall now.  Don't know what else to try.  

Any ideas??

gusseologyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RejojohnyCommented:
it also seems to happen with permission setting for the dll as described here .. http://support.software602.com/kb/view.aspx?articleID=987

Rejo
0
gusseologyAuthor Commented:
Rejo

Thanks for the reply.  I tried going to the registry values and setting them to complete full control for all users, system user, administrator, etc. etc.  I set everything to full control.....yet...of course....still have the same problem.

Any other ideas??

vr,

gusseology
0
RejojohnyCommented:
do remember that with com classes, it gets loaded into memory and IIs does not release it is restarted .. maybe something like that is happening for you too .. maybe you can try restarting the IIS admin services or better restarting the machine ..

Rejo
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

gusseologyAuthor Commented:
Rejo,

I'm not totally sure what IIS Admin services is, but, I tried your suggestion.  I registered my DLL, shut down and restaretd my computer.  Then ran the app, still get the same error.

jesse
0
gusseologyAuthor Commented:
anyone have any other ideas on this one??

I recently have tried re-doing everything the manual way.  You can use these com dll's by using the IDE (tlbimp.exe, add reference, etc.) or do it manually in code.  Both ways result in the same thing for me.  Which is good and bad.  Bad, because, well, still have the same problem.  but good because at lesat it is consistent even when I do it completely different ways.

The bottom line is, I am getting an error code: 80040154.  Which means DLL is unregistered.  But no matter what I do from here, I can't get it to work.

Experts....come through for me!!  :)

gusseology
0
RejojohnyCommented:
do you have a vb6 installable somewhere? try adding this ddl as refernce over in VB6 project and check if everything works fine .. also make sure this is a COM dll ..

rejo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RejojohnyCommented:
i just read your problem again and i noticed you mentioned the original file was a tlb .. so where is the dll? do you have the dll that the tlb refers to? is that registered?

Rejo
0
gusseologyAuthor Commented:
Rejo,

Okay, to answer your first question.  I have this project already, in C++.  I have a good C++ example (compiled and working!) in Visual Studio 2005 C++ project.  So I know it can work.  In C++ you use:
 
#import <filename.tlb> and everything works fine, compiles, runs, etc.

The problem occurs when I try to do this in C# where there isn't a #import and I have to use the techniques I have been trying.  So anyway, yea, I have built and ran a c++ VS2005 equivalent of what I am trying in C# and everything is working fine with the tlb.

To answer your second question, I only have the tlb.  Like I said, only having the tlb works fine in c++ and from the research I did, that makes sense....the tlb works fine.

Now, when I do this in C#, as I said, I can't seem to add a reference to the tlb (VS2005 won't let me, says "Please make sure that the file is accessible, and that it is a valid assembly or COM component".  So that's why I used tlbimport.exe so I can get a dll, reference that, and use it.

Hope this helps someone get an answer, cause I'm runnin' out of things to try...

gusseology
0
RejojohnyCommented:
i have not worked in C++, so my comments over those might be wrong. . but as far as I know, you can reference both COM and other types of dll in a C++ project, but you can only reference a .Net or COM dll in a C# project .. so if it works on c++ does not mean that it will work on C# project ..
and that is the reason why you get this as mentioned above  -- "VS2005 barked at me and said it was either not a real com object or corrupted, etc. "

>>So I tried using the regsvr32.exe utility to try to register it.  This didn't work, said it couldn't find the dll entry point or something like that
You get this error when this is not a COM dll ..
http://www.uninet.net/~blaisdel/Regsvr32Info.htm .. have a look here for what kind of objects can be registered using this exe
from the above link - "Dllname was loaded, but the DllRegisterServer or DllUnregisterServer entry point was not found.
Dllname is not a .dll or .ocx file.
For example, typing regsvr32 wjview.exe generates this error message"

usage of Regasm.exe .. just so that you are clued in .. pls ignore if you alrady know about it ..
http://msdn2.microsoft.com/en-us/library/tzat5yw6.aspx

having said all that I had heard somewhere and sometime back about something called P/Invoke to use these kinds of dll .. maybe you can lookup P/Invoke on MSDN, you'll see some sample codes on how to do that in C#. i will also try and find something on this ..
0
gusseologyAuthor Commented:
Okay, well, here is what I have gathered.  It is not a solution, but, I wanted to post what I learned anyway unless someone else is having a similar problem.

Okay, well, I *think* everything I did was correct.  I basically tried several methods of getting access to this COM DLL.  I tried the tlbimnp.exe thing, I tried the manual approach, I tried the Systems.Reflection approach, and all three are quite different approaches and all three resulted with me getting the same error.  the 80040154 error.

I found a posting on a forum that dealth with the same API I was dealing with.  And someone on there mentioned they were having similar problems (keep in mind, the task we are trying is to bring something into C# that was never intended for it, so the people trying were few and far between) and ended up doing something to sorta get it working.  Apparently, they tried importing the dll they wanted with tlbimp.exe and it kept failing.  Eventually they learned that some of the elements in the COM DLL used a property named "Type", which is a problem for tlbimp.exe.

To fix it, they generated an IDL file, changed the property named "Type" to something else, took the IDL, rebuilt it to get a new TLB, then imported the TLB into .Net and things were able to move forward from there.  They had further problems, but I don't know what those problems were and if they were related.

So, I think when it is all said and done, the problem wasn't so much with what or how I was doing it, but the problem resided with using a COM DLL that just wouldn't work in .Net.  Again, I *think* this is the problem from everything I've learned, but not totally sure.

There happens to be a web service API available to me that will accomplish the same task I need accomplished, but doesn't require me using the COM DLL in my .Net C# project.  So this is what I am going to pursue and it appears will work for me fine.  I don't want to try the other method (hacking the IDL, regenerating a tlb, etc.) because I'm not sure what further effects this might yield or if this is even the root problem, and it really isn't necessary since I've found this web services API that will work just fine for my needs.

Rejo, thanks for all your help.  Everything you said was spot on, I just think our problem wasn't so much with implementation, but using an imcompatible COM DLL.  I'm giving you the points for your excellent effort, knowledge, and commitment to helping me solve this.

thanks again

gusseology
0
gusseologyAuthor Commented:
thanks again Rejo
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.