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. LNK errors while using an "extern "C"" function

LNK errors while using an "extern "C"" function

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++
5 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 am implementing a C++.Net Class Library.(I want to use it in C#.Net later) I am using an MFC C++ header file and its corresponding lib file in that class library. I set the path for header file and lib file in the project properties. In that header file there is a class which I have no problem using it. But there is an "extern "C"" function which I have some problem with it. When I call it in my code, there are two link errors while compiling: error LNK2028 error LNK2019 Please help me to use this function. I'd appreciate it. Thanks in advance

    _ 1 Reply Last reply
    0
    • M MozhdehQeraati

      I am implementing a C++.Net Class Library.(I want to use it in C#.Net later) I am using an MFC C++ header file and its corresponding lib file in that class library. I set the path for header file and lib file in the project properties. In that header file there is a class which I have no problem using it. But there is an "extern "C"" function which I have some problem with it. When I call it in my code, there are two link errors while compiling: error LNK2028 error LNK2019 Please help me to use this function. I'd appreciate it. Thanks in advance

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

      You have to specify the calling convention of the exported function because the default is different in managed and native compilation. You could declare it as __stdcall.

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

      M 1 Reply Last reply
      0
      • _ _Superman_

        You have to specify the calling convention of the exported function because the default is different in managed and native compilation. You could declare it as __stdcall.

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

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

        would you please elaborate a little bit more or send me an article with examples? Thanks a lot

        _ C 2 Replies Last reply
        0
        • M MozhdehQeraati

          would you please elaborate a little bit more or send me an article with examples? Thanks a lot

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

          The function must be declared as - extern "C" int __stdcall foo();

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

          1 Reply Last reply
          0
          • M MozhdehQeraati

            would you please elaborate a little bit more or send me an article with examples? Thanks a lot

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

            Here[^] is a great article about calling conventions. It will help you to understand the concept.

            Cédric Moonen Software developer
            Charting control [v2.0] OpenGL game tutorial in C++

            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