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. C - DLL Export

C - DLL Export

Scheduled Pinned Locked Moved C / C++ / MFC
csharphelp
11 Posts 7 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.
  • D Offline
    D Offline
    dataminers
    wrote on last edited by
    #1

    I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant

    L N _ A 4 Replies Last reply
    0
    • D dataminers

      I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I've never seen extern "C" without curly brackets, so try extern "C" { ... unmangled C code here ...} :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      _ 1 Reply Last reply
      0
      • D dataminers

        I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant

        N Offline
        N Offline
        norish
        wrote on last edited by
        #3

        What compiler do you use in your IDE environment? I think __declspec(dllexport) is only for MS compiler, not for gcc.

        D 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, I've never seen extern "C" without curly brackets, so try extern "C" { ... unmangled C code here ...} :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

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

          extern "C" will work without curly brackets. Curly brackets are required if you need to include multiple lines in the scope of extern "C".

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

          Microsoft MVP (Visual C++)

          Polymorphism in C

          P 1 Reply Last reply
          0
          • D dataminers

            I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant

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

            Check the line number where the error occurs and post the code. The code that you've posted here has the correct syntax.

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

            Microsoft MVP (Visual C++)

            Polymorphism in C

            D 1 Reply Last reply
            0
            • _ _Superman_

              extern "C" will work without curly brackets. Curly brackets are required if you need to include multiple lines in the scope of extern "C".

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

              Microsoft MVP (Visual C++)

              Polymorphism in C

              P Offline
              P Offline
              Peter_in_2780
              wrote on last edited by
              #6

              If we're being picky here, the actual condition is not "multiple lines" but "more than a single declaration". Refer section 7.4 of the standard. For example,

              extern "C"
              double
              sqrt(
              double)
              ;

              is OK, but

              extern "C" double sqrt(double); double exp(double);

              and

              extern "C" int square(int x) {return x*x;}

              are not.

              Software rusts. Simon Stephenson, ca 1994.

              1 Reply Last reply
              0
              • N norish

                What compiler do you use in your IDE environment? I think __declspec(dllexport) is only for MS compiler, not for gcc.

                D Offline
                D Offline
                dataminers
                wrote on last edited by
                #7

                I use GCC compiler.

                G 1 Reply Last reply
                0
                • _ _Superman_

                  Check the line number where the error occurs and post the code. The code that you've posted here has the correct syntax.

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

                  Microsoft MVP (Visual C++)

                  Polymorphism in C

                  D Offline
                  D Offline
                  dataminers
                  wrote on last edited by
                  #8

                  line 2

                  1 Reply Last reply
                  0
                  • D dataminers

                    I use GCC compiler.

                    G Offline
                    G Offline
                    Graham Breach
                    wrote on last edited by
                    #9

                    If you're using gcc file.c from the command line, then that could be the problem - gcc is the C compiler and extern "C" is C++ code. Use g++ file.c, or make sure the file extension is .cpp or .c++ for gcc to compile it as C++.

                    N 1 Reply Last reply
                    0
                    • D dataminers

                      I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant

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

                      Try binning the extern "C" off the front of the function. If that compiles without error then enclose the lot in a extern "C" {} block. Cheers, Ash

                      1 Reply Last reply
                      0
                      • G Graham Breach

                        If you're using gcc file.c from the command line, then that could be the problem - gcc is the C compiler and extern "C" is C++ code. Use g++ file.c, or make sure the file extension is .cpp or .c++ for gcc to compile it as C++.

                        N Offline
                        N Offline
                        norish
                        wrote on last edited by
                        #11

                        This is just the solution for original question, I think. :)

                        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