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. linkage error

linkage error

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++csharpquestion
10 Posts 3 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.
  • M Offline
    M Offline
    MozhdehQeraati
    wrote on last edited by
    #1

    I have a lib and its corresponding header file in C or C++ that I want to use it in Visual C++.net. The header file has a structure like this: Reader.h: class AFX_EXT_CLASS Reader { . . . }; extern "C" AFX_EXT_API Reader * CreateReader(); There is no problem using the class but I can't use the CreateReader() function. There are 2 linkage errors: LNK2028, LNK2019. Can you help me using this function please? Thanks in advance

    _ K 2 Replies Last reply
    0
    • M MozhdehQeraati

      I have a lib and its corresponding header file in C or C++ that I want to use it in Visual C++.net. The header file has a structure like this: Reader.h: class AFX_EXT_CLASS Reader { . . . }; extern "C" AFX_EXT_API Reader * CreateReader(); There is no problem using the class but I can't use the CreateReader() function. There are 2 linkage errors: LNK2028, LNK2019. Can you help me using this function please? Thanks in advance

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

      Its probably because the calling conventions used where the function is declared and where the function is used are different. How is AFX_EXT_API defined? If it is defined as __declspec(dllexport), make it __stdcall __declspec(dllexport) Or rather, simply make it extern "C" AFX_EXT_API Reader* __stdcall CreateReader();

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

      modified on Tuesday, August 18, 2009 5:57 AM

      M 1 Reply Last reply
      0
      • _ _Superman_

        Its probably because the calling conventions used where the function is declared and where the function is used are different. How is AFX_EXT_API defined? If it is defined as __declspec(dllexport), make it __stdcall __declspec(dllexport) Or rather, simply make it extern "C" AFX_EXT_API Reader* __stdcall CreateReader();

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

        modified on Tuesday, August 18, 2009 5:57 AM

        M Offline
        M Offline
        MozhdehQeraati
        wrote on last edited by
        #3

        I don't have any access to the lib file. I only use it. You mean I only change it in the header file?! Is it possible? Besides there is no __declspec(dllexport). It is declared exactly as I wrote: extern "C" AFX_EXT_API Reader* CreateReader(); Besides I use it with /clr. Thanks

        modified on Tuesday, August 18, 2009 6:08 AM

        _ 1 Reply Last reply
        0
        • M MozhdehQeraati

          I don't have any access to the lib file. I only use it. You mean I only change it in the header file?! Is it possible? Besides there is no __declspec(dllexport). It is declared exactly as I wrote: extern "C" AFX_EXT_API Reader* CreateReader(); Besides I use it with /clr. Thanks

          modified on Tuesday, August 18, 2009 6:08 AM

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

          It is not enough to simply change it in the header file, unless you know which calling convention was used. You can try and use different calling conventions like __cdecl and __stdcall.

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

          M 1 Reply Last reply
          0
          • _ _Superman_

            It is not enough to simply change it in the header file, unless you know which calling convention was used. You can try and use different calling conventions like __cdecl and __stdcall.

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

            M Offline
            M Offline
            MozhdehQeraati
            wrote on last edited by
            #5

            You mean when I want to call it, for example in one function in my own application I use "__cdecl" before calling? like this?: Reader* m_pReader=__cdecl CreateReader();

            _ 1 Reply Last reply
            0
            • M MozhdehQeraati

              You mean when I want to call it, for example in one function in my own application I use "__cdecl" before calling? like this?: Reader* m_pReader=__cdecl CreateReader();

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

              No. I mean in the header file.

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

              M 1 Reply Last reply
              0
              • _ _Superman_

                No. I mean in the header file.

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

                M Offline
                M Offline
                MozhdehQeraati
                wrote on last edited by
                #7

                I change the header file from: extern "C" AFX_EXT_API Reader * CreateReader(); to: extern "C" AFX_EXT_API Reader * __stdcall CreateReader(); and also: extern "C" AFX_EXT_API Reader * __cdecl CreateReader(); but it doesn't work.The same errors occur. Should I do anything while calling the function? I include the header file and call the function as a usual ones.

                modified on Tuesday, August 18, 2009 7:04 AM

                1 Reply Last reply
                0
                • M MozhdehQeraati

                  I have a lib and its corresponding header file in C or C++ that I want to use it in Visual C++.net. The header file has a structure like this: Reader.h: class AFX_EXT_CLASS Reader { . . . }; extern "C" AFX_EXT_API Reader * CreateReader(); There is no problem using the class but I can't use the CreateReader() function. There are 2 linkage errors: LNK2028, LNK2019. Can you help me using this function please? Thanks in advance

                  K Offline
                  K Offline
                  KarstenK
                  wrote on last edited by
                  #8

                  Did ya read the msdn for the errors? http://msdn.microsoft.com/en-us/library/799kze2z(VS.80).aspx I guess your CreateReader() implementation is missing or falsly decorated. A Hint: I hope you are not creating objects in the dll and try to destroy it in the app. This can leads to strange errors. Such interfaces are better "native" as integer or LPCSTR pointers!!! It is hard to tell   :((

                  Press F1 for help or google it. Greetings from Germany

                  M 1 Reply Last reply
                  0
                  • K KarstenK

                    Did ya read the msdn for the errors? http://msdn.microsoft.com/en-us/library/799kze2z(VS.80).aspx I guess your CreateReader() implementation is missing or falsly decorated. A Hint: I hope you are not creating objects in the dll and try to destroy it in the app. This can leads to strange errors. Such interfaces are better "native" as integer or LPCSTR pointers!!! It is hard to tell   :((

                    Press F1 for help or google it. Greetings from Germany

                    M Offline
                    M Offline
                    MozhdehQeraati
                    wrote on last edited by
                    #9

                    I finally could solve the problem by changing "\properties\linker\input\Additional Dependences\". It compiles well and there is no linkage error anymore but I get another error while running the project: "The specified module could not be found (Exception from HRESULT:0x8007007E)" The error happens in Application.Run in program.cs, but not at the time of loading the form, but it happens when I want to make an object from my class, even when I don't use that specific function. Besides my dll is in Visual C++.Net and I'm calling it from C#.Net. Could you please help me? Thanks in advance

                    K 1 Reply Last reply
                    0
                    • M MozhdehQeraati

                      I finally could solve the problem by changing "\properties\linker\input\Additional Dependences\". It compiles well and there is no linkage error anymore but I get another error while running the project: "The specified module could not be found (Exception from HRESULT:0x8007007E)" The error happens in Application.Run in program.cs, but not at the time of loading the form, but it happens when I want to make an object from my class, even when I don't use that specific function. Besides my dll is in Visual C++.Net and I'm calling it from C#.Net. Could you please help me? Thanks in advance

                      K Offline
                      K Offline
                      KarstenK
                      wrote on last edited by
                      #10

                      some COM-Error are a pain -most- if they arent documented by MS :mad: i found after googling: http://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx you should narrow to the problem, maybe your COM object GUID isnt properly registed or the instance cant be launched because missing dlls. Most common mixed debug and release builds. Have a lot of fun ... :doh:

                      Press F1 for help or google it. Greetings from Germany

                      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