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. My own written DLL not accessible in dialog based app; [modified]

My own written DLL not accessible in dialog based app; [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
5 Posts 3 Posters 1 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
    AmbiguousName
    wrote on last edited by
    #1

    hllo guys...I tried to write my own DLL with simple functions which so far im successful. It lookd like this

    MyDll.h

    namespace MyDll
    {
    class MyOwnDll
    {
    //function here
    static _declspec(dllexport) void PrintMsg();
    };
    }

    MyDll.cpp

    namespace MyDll
    {
    void MyOwnDll::PrintMsg()
    {
    ::MessageBox(0,"","",0);
    }
    }

    Now I added this DLL to my dialog based application (MyDll.h in "stdafx.h" of MyProj) and build the solution. Everything is fine and it builds. But when I try to use this, it show errors stating Undeclared Identifier. Here is how I use it

    MyProjDlg.cpp

    {
    ...............
    ...............

     void MyProjDlg::MyMsg() //function added to a button
     {
         MyOwnDll mod;     //myTapi, mod ==> Undeclared Identifier
         mod.PrintMsg();  //mod ==> Undeclared Identifier
     }
    

    }

    All the paths and libraries are included, everything looks fine. But why it is not able to find this?? :confused: thnx

    modified on Thursday, December 2, 2010 2:47 PM

    A S 2 Replies Last reply
    0
    • A AmbiguousName

      hllo guys...I tried to write my own DLL with simple functions which so far im successful. It lookd like this

      MyDll.h

      namespace MyDll
      {
      class MyOwnDll
      {
      //function here
      static _declspec(dllexport) void PrintMsg();
      };
      }

      MyDll.cpp

      namespace MyDll
      {
      void MyOwnDll::PrintMsg()
      {
      ::MessageBox(0,"","",0);
      }
      }

      Now I added this DLL to my dialog based application (MyDll.h in "stdafx.h" of MyProj) and build the solution. Everything is fine and it builds. But when I try to use this, it show errors stating Undeclared Identifier. Here is how I use it

      MyProjDlg.cpp

      {
      ...............
      ...............

       void MyProjDlg::MyMsg() //function added to a button
       {
           MyOwnDll mod;     //myTapi, mod ==> Undeclared Identifier
           mod.PrintMsg();  //mod ==> Undeclared Identifier
       }
      

      }

      All the paths and libraries are included, everything looks fine. But why it is not able to find this?? :confused: thnx

      modified on Thursday, December 2, 2010 2:47 PM

      A Offline
      A Offline
      Aescleal
      wrote on last edited by
      #2

      You haven't qualified the class name with the namespace it's in, eg:

      MyDll::MyOwnDll mod;

      No idea if that's the source of your problem but it's a good place to start. Another thing to watch out for is the way you export the function from the DLL. Ideally you want to export the name in the DLL and import it in the EXE file. It might be worth having a look at some sample code to see how you're supposed to do that. Cheers, Ash

      1 Reply Last reply
      0
      • A AmbiguousName

        hllo guys...I tried to write my own DLL with simple functions which so far im successful. It lookd like this

        MyDll.h

        namespace MyDll
        {
        class MyOwnDll
        {
        //function here
        static _declspec(dllexport) void PrintMsg();
        };
        }

        MyDll.cpp

        namespace MyDll
        {
        void MyOwnDll::PrintMsg()
        {
        ::MessageBox(0,"","",0);
        }
        }

        Now I added this DLL to my dialog based application (MyDll.h in "stdafx.h" of MyProj) and build the solution. Everything is fine and it builds. But when I try to use this, it show errors stating Undeclared Identifier. Here is how I use it

        MyProjDlg.cpp

        {
        ...............
        ...............

         void MyProjDlg::MyMsg() //function added to a button
         {
             MyOwnDll mod;     //myTapi, mod ==> Undeclared Identifier
             mod.PrintMsg();  //mod ==> Undeclared Identifier
         }
        

        }

        All the paths and libraries are included, everything looks fine. But why it is not able to find this?? :confused: thnx

        modified on Thursday, December 2, 2010 2:47 PM

        S Offline
        S Offline
        Sauro Viti
        wrote on last edited by
        #3

        On your header file you have declared your export as __declspec(dllexport): this is right as it instruct the compiler that the method MyOwnDll::PrintMsg() is implemented in your code and should be exported from the library. On the other hand, when you use the dll, you should include the header file, but you need the MyOwnDll::PrintMsg() method to be imported, then it should be declared as __declspec(dllimport). A typical approach, is to add a pre-processor definition in your dll project, for example MYOWNDLLPRJ, and modify the header file as follow:

        #ifdef MYOWNDLLPRJ
        #define MYOWNDLLAPI __declspec(dllexport)
        #else
        #define MYOWNDLLAPI __declspec(dllimport)
        #endif

        namespace MyDll
        {
        class MyOwnDll
        {
        //function here
        static MYOWNDLLAPI void PrintMsg();
        };
        }

        A 1 Reply Last reply
        0
        • S Sauro Viti

          On your header file you have declared your export as __declspec(dllexport): this is right as it instruct the compiler that the method MyOwnDll::PrintMsg() is implemented in your code and should be exported from the library. On the other hand, when you use the dll, you should include the header file, but you need the MyOwnDll::PrintMsg() method to be imported, then it should be declared as __declspec(dllimport). A typical approach, is to add a pre-processor definition in your dll project, for example MYOWNDLLPRJ, and modify the header file as follow:

          #ifdef MYOWNDLLPRJ
          #define MYOWNDLLAPI __declspec(dllexport)
          #else
          #define MYOWNDLLAPI __declspec(dllimport)
          #endif

          namespace MyDll
          {
          class MyOwnDll
          {
          //function here
          static MYOWNDLLAPI void PrintMsg();
          };
          }

          A Offline
          A Offline
          AmbiguousName
          wrote on last edited by
          #4

          Since im new to DLLs so plz dont mind. After this, how do I call this function in MyProjDlg.cpp? Like this?

          void MyProjDlg::MyMsg()
          {
          MyDll::MyOwnDll mod;
          mod.PrintMsg();
          }

          S 1 Reply Last reply
          0
          • A AmbiguousName

            Since im new to DLLs so plz dont mind. After this, how do I call this function in MyProjDlg.cpp? Like this?

            void MyProjDlg::MyMsg()
            {
            MyDll::MyOwnDll mod;
            mod.PrintMsg();
            }

            S Offline
            S Offline
            Sauro Viti
            wrote on last edited by
            #5

            That will work, but is not the right way: as the MyDll::MyOwnDll.PrintMsg() method is static, you don't need to instantiate an object of your class to call it. The right way is the following:

            void MyProjDlg::MyMsg()
            {
            MyDll::MyOwnDll::PrintMsg();
            }

            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