Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How a to expose data of an application (.EXE) to a DLL on runtime?

How a to expose data of an application (.EXE) to a DLL on runtime?

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpquestion
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arris74
    wrote on last edited by
    #1

    Hello, I have an application that uses a DLL but the DLL needs to access data provided by the application on runtime. Tryng to make .exe objects visible to the DLL brings me to awful linking problems The solution I tested is to use COM but this forces to use RPC for communication between the .DLL and the .EXE world. COM solution sounds complex and out-proc is slower than in-proc. Please could you help me with a more simple solution? Thank you in advance

    _ J 2 Replies Last reply
    0
    • A Arris74

      Hello, I have an application that uses a DLL but the DLL needs to access data provided by the application on runtime. Tryng to make .exe objects visible to the DLL brings me to awful linking problems The solution I tested is to use COM but this forces to use RPC for communication between the .DLL and the .EXE world. COM solution sounds complex and out-proc is slower than in-proc. Please could you help me with a more simple solution? Thank you in advance

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      What data is needed by the DLL? You should export a function from the DLL that the EXE can call to pass in the data using function parameters.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      A 1 Reply Last reply
      0
      • _ _Superman_

        What data is needed by the DLL? You should export a function from the DLL that the EXE can call to pass in the data using function parameters.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        A Offline
        A Offline
        Arris74
        wrote on last edited by
        #3

        Data is contained in arrays which objects are instances of classes of the application. I have tried to pass a reference of the object in the exported function but the parameter type is not known by the DLL. I also tried to make the header file visible to the DLL and set a #include "myfile.h" in the DLL but this does not work.

        _ A 2 Replies Last reply
        0
        • A Arris74

          Data is contained in arrays which objects are instances of classes of the application. I have tried to pass a reference of the object in the exported function but the parameter type is not known by the DLL. I also tried to make the header file visible to the DLL and set a #include "myfile.h" in the DLL but this does not work.

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          I'm assuming you're getting compile time errors when compiling the DLL. Please post the error messages and the relevant code.

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++)

          Polymorphism in C

          A 1 Reply Last reply
          0
          • A Arris74

            Hello, I have an application that uses a DLL but the DLL needs to access data provided by the application on runtime. Tryng to make .exe objects visible to the DLL brings me to awful linking problems The solution I tested is to use COM but this forces to use RPC for communication between the .DLL and the .EXE world. COM solution sounds complex and out-proc is slower than in-proc. Please could you help me with a more simple solution? Thank you in advance

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            Presumably this is data that the dll does in fact know about. If so the dll should provide a way to specify that data. So you use that. If the dll doesn't provide such a way, then you must modify the dll to do that.

            1 Reply Last reply
            0
            • A Arris74

              Data is contained in arrays which objects are instances of classes of the application. I have tried to pass a reference of the object in the exported function but the parameter type is not known by the DLL. I also tried to make the header file visible to the DLL and set a #include "myfile.h" in the DLL but this does not work.

              A Offline
              A Offline
              Albert Holguin
              wrote on last edited by
              #6

              If you're going to pass by reference, your recipient (the DLL) needs the definition of what's enclosed, so it'll need the header file anyway. Just make sure it gets included into the DLL project as well.

              A 1 Reply Last reply
              0
              • A Albert Holguin

                If you're going to pass by reference, your recipient (the DLL) needs the definition of what's enclosed, so it'll need the header file anyway. Just make sure it gets included into the DLL project as well.

                A Offline
                A Offline
                Arris74
                wrote on last edited by
                #7

                Hello Albert, Many thanks for your help. Actually my problem is a linking issue. with this message: error LNK2019: unresolved external symbol "public: double __thiscall TestRef::unDouble(double)" (?unDouble@TestRef@@QAENN@Z) referenced in function "public: void __thiscall ClassRef::setval(int)" (?setval@ClassRef@@QAEXH@Z) MYDLL.obj fatal error LNK1120: 1 unresolved externals Debug/MYDLL.dll My Dll function has a pointer as parameter and the pointer calls the function member of the application's class and that function uses an object of another class of the application. Could you please tell me how to solve it? Below is the sample source of the DLL function

                #include "classref.h" // file header of the application using the DLL
                extern "C" __declspec(dllexport) int MainEntry( ClassRef* pRef )
                {
                // entier is a public attribute of the application that uses the DLL
                int XX = pRef->entier; // This works

                //getval is a public member function of the application that uses the DLL
                XX = pRef->setval(5); // compile but does not build. unresolved external symbol errors
                

                return 0;
                }

                And below is definition of setval(int )

                void setval( int val)
                {
                double dbl = m_ref->unDouble(16.45);// This is a member function of another class of the application
                entier = val * dbl ;
                }

                A 1 Reply Last reply
                0
                • _ _Superman_

                  I'm assuming you're getting compile time errors when compiling the DLL. Please post the error messages and the relevant code.

                  «_Superman_»  _I love work. It gives me something to do between weekends.

                  _Microsoft MVP (Visual C++)

                  Polymorphism in C

                  A Offline
                  A Offline
                  Arris74
                  wrote on last edited by
                  #8

                  Superman, Please see the code posted to Albert Thread. kind regards.

                  1 Reply Last reply
                  0
                  • A Arris74

                    Hello Albert, Many thanks for your help. Actually my problem is a linking issue. with this message: error LNK2019: unresolved external symbol "public: double __thiscall TestRef::unDouble(double)" (?unDouble@TestRef@@QAENN@Z) referenced in function "public: void __thiscall ClassRef::setval(int)" (?setval@ClassRef@@QAEXH@Z) MYDLL.obj fatal error LNK1120: 1 unresolved externals Debug/MYDLL.dll My Dll function has a pointer as parameter and the pointer calls the function member of the application's class and that function uses an object of another class of the application. Could you please tell me how to solve it? Below is the sample source of the DLL function

                    #include "classref.h" // file header of the application using the DLL
                    extern "C" __declspec(dllexport) int MainEntry( ClassRef* pRef )
                    {
                    // entier is a public attribute of the application that uses the DLL
                    int XX = pRef->entier; // This works

                    //getval is a public member function of the application that uses the DLL
                    XX = pRef->setval(5); // compile but does not build. unresolved external symbol errors
                    

                    return 0;
                    }

                    And below is definition of setval(int )

                    void setval( int val)
                    {
                    double dbl = m_ref->unDouble(16.45);// This is a member function of another class of the application
                    entier = val * dbl ;
                    }

                    A Offline
                    A Offline
                    Albert Holguin
                    wrote on last edited by
                    #9

                    Your error is telling you that that code was never compiled, did you add the header and cpp of "classref.h" to your DLL project?

                    A 2 Replies Last reply
                    0
                    • A Albert Holguin

                      Your error is telling you that that code was never compiled, did you add the header and cpp of "classref.h" to your DLL project?

                      A Offline
                      A Offline
                      Arris74
                      wrote on last edited by
                      #10

                      Sure I tried the header alone and the cpp. with the header but linking message is still here. I noticed a curious behavior as following: 1. If I put a comment on the function setval from within my Dll. Then it builds correctly 2. if I remove the comment and I just compile. This works fine as well. 3. Finally if I rebuild the DLL I get the linking errors.

                      1 Reply Last reply
                      0
                      • A Albert Holguin

                        Your error is telling you that that code was never compiled, did you add the header and cpp of "classref.h" to your DLL project?

                        A Offline
                        A Offline
                        Arris74
                        wrote on last edited by
                        #11

                        I have got the reason of the problem. Implementation and definition must be in the same file. I.e in the header. But this brings to another problem that is the source code will be disclosed if the application is distributed.

                        A 1 Reply Last reply
                        0
                        • A Arris74

                          I have got the reason of the problem. Implementation and definition must be in the same file. I.e in the header. But this brings to another problem that is the source code will be disclosed if the application is distributed.

                          A Offline
                          A Offline
                          Albert Holguin
                          wrote on last edited by
                          #12

                          It doesn't have to be in the same file, you just have to include both in your DLL project. As far as the source requiring to be disclosed.... well, don't pass an entire class to your DLL and you won't have to disclose the code. You should probably only pass data along. Make use of data structures instead of passing classes.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups