Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Referencing MFC Dll

Status
Not open for further replies.

doja93

Programmer
Dec 6, 2004
5
US
I created an C++ MFC Dll project and am trying to call a function in the dll from a C# Class Library project using DllImport.

I seem to remember that when using DllImport you have to also add a reference to the dll in the project you're using it in. When I go to add a refernce to my MFC.dll in the C# Class Library references I get this error:

"A reference to '[path to my dll]mfc.dll' could not be added. This is not a valid assembly or COM component. Only assemblies with extension 'dll' and COM components can be referenced. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

I can clearly see that the dll I'm trying to reference is in fact a .dll so I'm wondering - is the problem that it is *not* a valid assembly or COM component? How would you tell if it is or is not? If anyone has any ideas about what may be causing the error, how to fix it i.e. how to add a reference to that dll, or why what I'm trying to do won't work it would be much appreciated.

*sorry 'bout the double post - wrong language the first time.
 
At a guess it is something to do with the managed/unmanaged stuff. I've seen the problem before but have never fixed it. It is normally fixed by those on the project who like using managed code.

I think you need managed wrappers for functions in MFC. C# can't call unmanaged code directly. It has to call managed code that then calls the unmanaged code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top