[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Using a tlb file in .Net 2005 solution

Posted on 2008-01-30
11
Medium Priority
?
1,160 Views
Last Modified: 2013-11-26
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??

0
Comment
Question by:gusseology
  • 6
  • 5
11 Comments
 
LVL 26

Expert Comment

by:Rejojohny
ID: 20779153
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
 

Author Comment

by:gusseology
ID: 20779445
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 20780384
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:gusseology
ID: 20780518
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
 

Author Comment

by:gusseology
ID: 20791266
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
 
LVL 26

Accepted Solution

by:
Rejojohny earned 2000 total points
ID: 20793339
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 20793366
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
 

Author Comment

by:gusseology
ID: 20796211
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 20801202
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
 

Author Comment

by:gusseology
ID: 20834274
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
 

Author Closing Comment

by:gusseology
ID: 31426415
thanks again Rejo
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses

590 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