Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Using MFC and .NET

Back to Forum: Tech Off
  • User profile image
    brussell

    I am trying to take old MFC code and use it in a C++.NET container.
    If I have all the code in the same project, I get an error about delete being defined twice if I #include "afx.h" so that I can use DWORD[] and such.

    How do I get this to work?
    Or do I make the MFC code a DLL and include it? If so, how do I do that?

  • User profile image
    Maurits

    brussell wrote:
    Or do I make the MFC code a DLL and include it? If so, how do I do that?

    You can wrap .dll's in a .NET construct with tlbimp and ildasm

  • User profile image
    Maurits

    Have you tried making a dbBuilder_dotnetproxy.dll along these lines

  • User profile image
    brussell

    Maurits wrote:
    Have you tried making a dbBuilder_dotnetproxy.dll along these lines


    TlbImp error: The input file 'C:\Documents and Settings\brussell\My Documents\Vi
    sual Studio Projects\dbBuilder\Debug\dbBuilder.dll' is not a valid type library

  • User profile image
    brussell

    I have figured out how to DllImport in my C++.NET program but I am having problems figuring out how to extern my MFC function from a dll so the C++.NET program can see it.

    Any ideas?

    I have
    public:  void BuildASCII( CString sPath )
    in the MFC DLL that needs to be used in the .NET program.



    I have
    [DllImport("dbBuilder.dll", EntryPoint = "BuildASCII", CharSet = Unicode)]
        void BuildASCII( System::String* sPath );

    ...
    private: System::Void btnStartBuild_Click(System::Object *  sender, System::EventArgs *  e)
                 {
                     BuildASCII( "./" );
                 }
    in the .NET.


    Edit:
    In the DLL's .h, I have:
    extern "C"
    {
        void BuildASCII( CString sPath );
    }


    I get this error in the .NET program:
    An unhandled exception of type 'System.EntryPointNotFoundException' occurred in Symbol Database Generator.exe

    Additional information: Unable to find an entry point named BuildASCII in DLL dbBuilder.dll.

  • User profile image
    brussell

    I was doing everything right except I forgot to put the function into the .def....

    Works now, thanks

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.