I have a dll file that also comes with a .tlb file.
When I tried to load the dll file, I imported the dll using tlbimp tool.
The dll implemented an interface that exposes some functions...
but when i tried to create an instance of the class in my dll file, it throws me :
System.Runtime.InteropServices.COMException was unhandled
Message="Retrieving the COM class factory for component with CLSID {9A85C592-4736-45CE-ADE3-200144B78F19} failed due to the following error: 80040154."
Source="PPTranning"
ErrorCode=-2147221164
StackTrace:
at PPTranning.Form1.Form1_Load(Object sender, EventArgs e) in C:\C#\PPTranning\PPTranning\Form1.cs:line 39
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at PPTranning.Program.Main() in C:\C#\PPTranning\PPTranning\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
(I even tried to use DLLImport function but it gives me entrypointnotfoundException, and I can't spot the function i want to call using dumpbin, i am sure the dll file has no error)
Any idea
thanks..

tlbimp.exe and DllImport
cp14feb
You are confusing COM interop with Platform/Invoke. You should use TlbImp to import COM definitions through a TLB or DLL. This simply creates the necessary interop code such that you can create instances of COM objects and interact with them through the COM interfaces. With Platform/Invoke you use DllImport to identify a function in a DLL that you want to call.
It sounds like you are trying to use COM interop so you first need to register the DLL on your machine. I believe the error you are getting is probably a class not registered error. This will permit you to create an instance of the class at runtime. Using the generated proxy assembly (from tlbimp) you can interact with the COM object normally.
Michael Taylor - 5/30/06
sebabas
I did register the dll I got from running tlbimp.exe.
the command that I used is "regasm myDll.dll"
do I have to run it under particular directive
Or is there any alternative I can use to load the dll
Thanks..
a006751
Got everything sorted out..
turn out that I was missing another few dll files associated with the one i am using. Found out about it using dependency walker...
and my Dll is the old school dll, no need to register it... :)
SATISD9X
Also...
when I tried regsvr32 /i myDll.dll
it says myDll.dll was loaded, but the DllRegisterServer entry point was not found.....:(
Marc L. K.
No. You shouldn't register the tlbimp-generated DLL. That DLL is a .NET assembly that contains the necessary interop code. You need to register the original DLL that came with the TLB file. The original DLL is the COM component and it will contain the COM class that you eventually instantiate on the .NET side. Regsvr32 will register a non-.NET COM DLL.
Michael Taylor - 5/30/06