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 to export a class in a dynamic dll

How to export a class in a dynamic dll

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
7 Posts 5 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.
  • V Offline
    V Offline
    vc _fragrance
    wrote on last edited by
    #1

    Hi, I have created a function and a class in a DLL. I want to write a .DEF file instead using __declspec(dllexport) and __declspec(dllimport). I wrote the .DEF file like this.. LIBRARY "Sample.dll" //dll name is Sample.dll EXPORTS Multiply @1 //it is the function name CRectArea @2 //it is the class name and this class contains a //method called subtract Please say how to export that function. and I wrote a client program which uses that dll dynamically. //written globally in the implementation file of client typedef int (CALLBACK* LPFNMLTPLY)(int,int); //** I don't know how to declare that function from the class CRectArea HINSTANCE hClcltr=LoadLibrary("DefExported.dll"); LPFNMLTPLY lpfnMuliply; lpfnMuliply = (LPFNMLTPLY)GetProcAddress(hClcltr,"Multiply"); m_Rslt=lpfnMuliply(m_PartOne,m_PartTwo); //m_Rslt will be displayed //in the message box. FreeLibrary( hClcltr ); //now I want to use the function from class Please can anybody help me. Thanks inadvance.

    C M I H 4 Replies Last reply
    0
    • V vc _fragrance

      Hi, I have created a function and a class in a DLL. I want to write a .DEF file instead using __declspec(dllexport) and __declspec(dllimport). I wrote the .DEF file like this.. LIBRARY "Sample.dll" //dll name is Sample.dll EXPORTS Multiply @1 //it is the function name CRectArea @2 //it is the class name and this class contains a //method called subtract Please say how to export that function. and I wrote a client program which uses that dll dynamically. //written globally in the implementation file of client typedef int (CALLBACK* LPFNMLTPLY)(int,int); //** I don't know how to declare that function from the class CRectArea HINSTANCE hClcltr=LoadLibrary("DefExported.dll"); LPFNMLTPLY lpfnMuliply; lpfnMuliply = (LPFNMLTPLY)GetProcAddress(hClcltr,"Multiply"); m_Rslt=lpfnMuliply(m_PartOne,m_PartTwo); //m_Rslt will be displayed //in the message box. FreeLibrary( hClcltr ); //now I want to use the function from class Please can anybody help me. Thanks inadvance.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      The only way to import a class from a dll is by implicit linking (so, without using LoadLibrary and GetProcAddress but using the lib file supplied with the DLL).


      Cédric Moonen Software developer
      Charting control [v1.1]

      1 Reply Last reply
      0
      • V vc _fragrance

        Hi, I have created a function and a class in a DLL. I want to write a .DEF file instead using __declspec(dllexport) and __declspec(dllimport). I wrote the .DEF file like this.. LIBRARY "Sample.dll" //dll name is Sample.dll EXPORTS Multiply @1 //it is the function name CRectArea @2 //it is the class name and this class contains a //method called subtract Please say how to export that function. and I wrote a client program which uses that dll dynamically. //written globally in the implementation file of client typedef int (CALLBACK* LPFNMLTPLY)(int,int); //** I don't know how to declare that function from the class CRectArea HINSTANCE hClcltr=LoadLibrary("DefExported.dll"); LPFNMLTPLY lpfnMuliply; lpfnMuliply = (LPFNMLTPLY)GetProcAddress(hClcltr,"Multiply"); m_Rslt=lpfnMuliply(m_PartOne,m_PartTwo); //m_Rslt will be displayed //in the message box. FreeLibrary( hClcltr ); //now I want to use the function from class Please can anybody help me. Thanks inadvance.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        To export/import a class I believe you have to use __declspec(dllexport) and __declspec(dllimport). Mark

        1 Reply Last reply
        0
        • V vc _fragrance

          Hi, I have created a function and a class in a DLL. I want to write a .DEF file instead using __declspec(dllexport) and __declspec(dllimport). I wrote the .DEF file like this.. LIBRARY "Sample.dll" //dll name is Sample.dll EXPORTS Multiply @1 //it is the function name CRectArea @2 //it is the class name and this class contains a //method called subtract Please say how to export that function. and I wrote a client program which uses that dll dynamically. //written globally in the implementation file of client typedef int (CALLBACK* LPFNMLTPLY)(int,int); //** I don't know how to declare that function from the class CRectArea HINSTANCE hClcltr=LoadLibrary("DefExported.dll"); LPFNMLTPLY lpfnMuliply; lpfnMuliply = (LPFNMLTPLY)GetProcAddress(hClcltr,"Multiply"); m_Rslt=lpfnMuliply(m_PartOne,m_PartTwo); //m_Rslt will be displayed //in the message box. FreeLibrary( hClcltr ); //now I want to use the function from class Please can anybody help me. Thanks inadvance.

          I Offline
          I Offline
          includeh10
          wrote on last edited by
          #4

          VC wizard can help you to create a dll class in a second - that is a perfect sample.

          1 Reply Last reply
          0
          • V vc _fragrance

            Hi, I have created a function and a class in a DLL. I want to write a .DEF file instead using __declspec(dllexport) and __declspec(dllimport). I wrote the .DEF file like this.. LIBRARY "Sample.dll" //dll name is Sample.dll EXPORTS Multiply @1 //it is the function name CRectArea @2 //it is the class name and this class contains a //method called subtract Please say how to export that function. and I wrote a client program which uses that dll dynamically. //written globally in the implementation file of client typedef int (CALLBACK* LPFNMLTPLY)(int,int); //** I don't know how to declare that function from the class CRectArea HINSTANCE hClcltr=LoadLibrary("DefExported.dll"); LPFNMLTPLY lpfnMuliply; lpfnMuliply = (LPFNMLTPLY)GetProcAddress(hClcltr,"Multiply"); m_Rslt=lpfnMuliply(m_PartOne,m_PartTwo); //m_Rslt will be displayed //in the message box. FreeLibrary( hClcltr ); //now I want to use the function from class Please can anybody help me. Thanks inadvance.

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            Did you see examples of dll on codeproject for export class


            WhiteSky


            V 1 Reply Last reply
            0
            • H Hamid Taebi

              Did you see examples of dll on codeproject for export class


              WhiteSky


              V Offline
              V Offline
              vc _fragrance
              wrote on last edited by
              #6

              Yes Mr.whitesky I practiced the samples and while practicing I got the about. Anyhow thank you very much all of YOU.

              H 1 Reply Last reply
              0
              • V vc _fragrance

                Yes Mr.whitesky I practiced the samples and while practicing I got the about. Anyhow thank you very much all of YOU.

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                I glad you find it:)


                WhiteSky


                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