Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to access COM Dll in .net framework using c#, But not able to initilaize the object of COM classes.all required dll are built succesfully in VC++ But while accessing in C#, it throws error as below:

"Retrieving the COM class factory for component with CLSID {4F3843A4-048B-11D4-93D8-0050BAD440B8} failed due to the following error: 800401f0."

I am not able to get any help from Google even. Kindly assist.

Thanks and Regards
Kush Sharma
Posted

Hello,

Your error code (800401f0) seems to indicate a CoInitialize or a CoCreateInstance error, this could be linked to your COM DLL not being properly registered.

You should try to run "rgsvc" with option "-r" on your DLL and then run your C# app.
 
Share this answer
 
Thanks Fred. Regsvr32 or grsvc please confirm and give me some examples how to register. I will really appreciate your help on this.
 
Share this answer
 
Comments
Fred Flams 7-Feb-13 8:50am    
I'd say regsvr32, and the command line would be (from memory) "regsvr32 -r <your dll="">", if incorrect, "regsvr32 -?" should help you.
Fred Flams 7-Feb-13 8:52am    
Actually I should have type regsvr32 -? myself, the option is -i
Thanks Fred.

I have tried But it thorws error as dll was loaded but the entry point DllInstall was not found.

make sure it si valid dll or OCX file, I have build this COM dll and built in VC++ PROJECT WITH OUT ANY ERROR.

Please help on it now.
 
Share this answer
 
Comments
Fred Flams 7-Feb-13 9:14am    
By the way try answering to my post with the "comment" button rather than posting a new solution, that way I get notified that someone is reacting to my post.
In that case your problem is stemming from there.
I your DLL doesn't have a DLLInstall entry point (and that is not mandatory to have) then you won't be able to reference directly from your C# application.
You'll have to use the P/Invoke mecanism to interact with your COM DLL from the C# application:

C#
[System.Runtime.InteropServices.DllImport("yourComLib.dll")]
static extern void SomeMethod(....);


You will need to define a external static method in you C# application for each COM method you want to use. But if you want to be able to reference your COM DLL then you should make sure it has DLLInstall and DLLUninstall method.
 
Share this answer
 
v2
thanks Fred,

But can you explain with some examples as i am not able to process it further on this.

below is my DLL

[System.Runtime.InteropServices.DllImport("ExactaUtil.dll")]

currently i am usingl ike this way:

protected EXACTAUTILLib.IUtilObj m_objUtil;

// Create an instance of the Util class.
m_objUtil = new EXACTAUTILLib.UtilObjClass();
 
Share this answer
 
thanks Fred,

But can you explain with some examples as i am not able to process it further on this.

below is the procsedure currently i am using to call my DLL:

protected EXACTAUTILLib.IUtilObj m_objUtil;
// Create an instance of the Util class.
m_objUtil = new EXACTAUTILLib.UtilObjClass();
m_objUtil.SetDBConnectionInfo(m_szDBUserID, m_szDBPassword, m_szAdoDSN, m_szOdbcDSN);

please explain how i can call using P/Invoke mecanism



thanks and Regards
Kush Sharma
 
Share this answer
 
Comments
Fred Flams 7-Feb-13 10:37am    
Well actually in your case, the easiest would be to make sure that the COM DLL has the DllInstall and DllUninstall entry points as it will be relativelly complex to convert your code into P/Invoke.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900