locked
Wrap a MFC library into a C# library RRS feed

  • Question

  • Hello everybody,

    I am having trouble working with a MFC library given to me by a 3rd-party vendor and I hope I can find some answers here. However I am not very clear about the terminology when it comes to the un-managed world, or anything not C# related; so please bare with me.

    Let me start by describing exactly what I have in my hand (in terms of this 3rd-party library); followed by the solution I am working with at the moment, and finally I will describe exactly what I wish to achieve.

    From the vendor, I am given three files: xxx.h, xxx.dll, and xxx.lib

    The two files xxx.dll and xxx.lib are contained in a folder called Release

    and the file xxx.h is contained in a folder called Include

    From their provided documentation, I have managed to use P/Invoke from my managed C# world and write a wrapper for each of the functions. However based on additional required libraries (dll) for my wrapper to compile, I have determined that xxx.dll is actually a MFC library.

    The additional required libraries are as follows: MFC42D.DLL, MFCD42D.DLL, MFCN42D.DLL, MFCO42D.DLL, MSVCIRTD.DLL, MSVCP60D.DLL, MSVCRTD.DLL

    An example of one of my P/Invoke statement is as follows:

    [DllImport("xxx.dll", SetLastError = true)]
    private static extern int XXX(byte[] byService, int nServiceCnt);

    When I compile the wrapper library, everything works ok - except for the fact that now, everytime I use this wrapper, my application has 10 additional dll's (one for the 3rd-party dll, one for my wrapper library, and another 8 or so for MFC extensions).

    Which leads me to the point I wish to achieve, that is to be able to combine all the necessary dll's into just one wrapper dll.

    First and foremost, is this even possible?

    Secondly, please give me the steps required (i'm using Visual Studio 2005)

    I have tried using VS2005 templates for C++ MFC Library and C++ CLR Library as my original wrapper; but i'm not good with C++ (haven't used it since grade-school)

    Thanks in advance

    • Edited by ---k31--- Thursday, June 18, 2009 11:29 AM
    Thursday, June 18, 2009 11:26 AM

Answers

  • It is not possible.  You'll need to contact the vendor of this DLL and tell them you need an installer for their product.  Also point out to them that they are shipping their product compiled in the Debug build.  They might have given you both but if they didn't, they made a grave mistake.

    Hans Passant.
    Thursday, June 18, 2009 11:54 AM
  • Actually it would be possible but you'd still need to contact the vendor and ask them to statically link the MFC and CRT Libraries and while they are at it indeed use the release versions of them.

    Thursday, June 18, 2009 3:38 PM

All replies

  • It is not possible.  You'll need to contact the vendor of this DLL and tell them you need an installer for their product.  Also point out to them that they are shipping their product compiled in the Debug build.  They might have given you both but if they didn't, they made a grave mistake.

    Hans Passant.
    Thursday, June 18, 2009 11:54 AM
  • Actually it would be possible but you'd still need to contact the vendor and ask them to statically link the MFC and CRT Libraries and while they are at it indeed use the release versions of them.

    Thursday, June 18, 2009 3:38 PM