DLL export, decorated function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UGF0cmljayBXZXN0ZXJob2Zm?=

    DLL export, decorated function

    Hello,

    I'm currently working on a small DLL that will be used as an extension to a
    working application. It is required that the DLL has only one export named
    "C16_DLLCAL L". So I started creating a DLL in Visual C++ 2008 using the Win32
    application wizard for DLLs and changed it so it would work for our
    application.
    However when I build the DLL file and look at it using dumpbin.exe /exports,
    the exported function is not exactly called "C16_DLLCAL L". Depending on the
    function declaration I get one of the following export names:

    ?C16_DLLCALL@@Y AHPAUvC16_CCB@@ @Z = ?C16_DLLCALL@@Y AHPAUvC16_CCB@@ @Z (int
    __cdecl C16_DLLCALL(str uct vC16_CCB *))
    when using: __declspec(dlle xport) [...]

    C16_DLLCALL = _C16_DLLCALL
    when using: extern "C" __declspec(dlle xport) [...]

    I have got a example DLL from the application developers and when I look at
    it using dumpbin, it exactly has the required name, without equally signs or
    other characters, just a plain "C16_DLLCAL L" - and in that case the
    application finds the entry point within the dll. However with any of my
    DLLs, it fails.
    How can I export the function without having its export name changed at all?

    Thank you,
    Patrick Westerhoff
  • SvenC

    #2
    Re: DLL export, decorated function

    Hi Patrick,
    ... I like to have one export named "C16_DLLCAL L".
    ... but I get ...
    C16_DLLCALL = _C16_DLLCALL
    when using: extern "C" __declspec(dlle xport) [...]
    Add a def file to your project



    --
    SvenC

    Comment

    • =?Utf-8?B?UGF0cmljayBXZXN0ZXJob2Zm?=

      #3
      Re: DLL export, decorated function

      Hi SvenC,

      thank you for your answer. I tried that now but received the following
      exports:

      C16_DDLCALL = ?C16_DLLCALL@@C AHPAUvC16_CCB@@ @Z (int __cdecl
      C16_DLLCALL(str uct vC16_CCB *))
      when using only the .def file without any additional things in the function
      declaration
      and
      C16_DDLCALL = _C16_DDLCALL
      when using the .def with extern "C" __declspec(dlle xport)

      both don't work in the application :(

      Patrick Westerhoff

      "SvenC" wrote:
      Hi Patrick,
      >
      Add a def file to your project
      >

      >
      --
      SvenC
      >

      Comment

      • SvenC

        #4
        Re: DLL export, decorated function

        Hi Patrick,
        thank you for your answer. I tried that now but received the following
        exports
        Reread the article and find:
        "If you are *not using* the __declspec(dlle xport) keyword to export
        the DLL's functions, the DLL requires a .def file."

        Instead you should specify the calling convention explicitly in your
        header so that you do not depend on vc project defaults.

        extern "C" __stdcall C16_DDLCALL(str uct vC16_CCB *);


        --
        SvenC

        Comment

        • =?Utf-8?B?UGF0cmljayBXZXN0ZXJob2Zm?=

          #5
          Re: DLL export, decorated function

          Hm, sorry but I don't get it :( So before I continue misunderstandin g, I'll
          post a bit from my code:

          C16DLL.def
          ----
          LIBRARY "C16DLL"
          EXPORTS
          C16_DLLCALL @1
          ----

          C16DLL.h (apart from that only has the standard definition of C16DLL_API
          __declspec(dlle xport) etc.)
          ----
          extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );
          ----

          C16DLL.cpp (includes also stdafx.h which is including some header files for
          the different types/structs I have to use so that they work with the target
          application)
          ----
          vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
          {
          // ...
          }
          ----

          Apart from that I only have the default dllmain.cpp which contains BOOL
          APIENTRY DllMain

          Whatever suggestion I tried until now, I never was able to reduce the export
          listed with dumpbin to only C16_DLLCALL resulting in the application not
          recognizing the function (it actually returns an error which says that the
          entry point was not found).
          When I try it with the dll the developers sent to me, it works fine; I also
          have the "source" (=.c file only) of that dll but I don't have any settings
          for it so I'm probably not able to compile it to test if the problem is maybe
          the Studio 2008 compiler (which I believe by now :/).
          If it helps within the developers source, the function is defined with:
          vERROR WINAPI C16_DLLCALL( vC16_CCB* aCCB )
          and instead of the DllMain function they use
          vINT APIENTRY LibMain ( ... )
          which is the same according to what I read yesterday on the msdn library..

          So where is the problem? :|

          Patrick Westerhoff


          "SvenC" wrote:
          Hi Patrick,
          >
          thank you for your answer. I tried that now but received the following
          exports
          >
          Reread the article and find:
          "If you are *not using* the __declspec(dlle xport) keyword to export
          the DLL's functions, the DLL requires a .def file."
          >
          Instead you should specify the calling convention explicitly in your
          header so that you do not depend on vc project defaults.
          >
          extern "C" __stdcall C16_DDLCALL(str uct vC16_CCB *);
          >
          >
          --
          SvenC
          >
          >

          Comment

          • SvenC

            #6
            Re: DLL export, decorated function

            Hi Patrick,
            Hm, sorry but I don't get it :( So before I continue
            misunderstandin g, I'll post a bit from my code:
            >
            C16DLL.def
            ----
            LIBRARY "C16DLL"
            EXPORTS
            C16_DLLCALL @1
            ----
            >
            C16DLL.h (apart from that only has the standard definition of
            C16DLL_API __declspec(dlle xport) etc.)
            ----
            extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );
            Did you add the def file to your project property settings?

            Config Props/Linker/Input/Module Definition File

            --
            SvenC

            Comment

            • =?Utf-8?B?UGF0cmljayBXZXN0ZXJob2Zm?=

              #7
              Re: DLL export, decorated function

              Hi SvenC,

              yes, it was added there automatically when I created it.

              Patrick

              "SvenC" wrote:
              Hi Patrick,
              >
              Did you add the def file to your project property settings?
              >
              Config Props/Linker/Input/Module Definition File
              >
              --
              SvenC
              >

              Comment

              • Giovanni Dicanio

                #8
                Re: DLL export, decorated function


                "Patrick Westerhoff" <PatrickWesterh off@discussions .microsoft.comh a
                scritto nel messaggio
                news:89376758-F7A3-45C6-BED0-98C8B553C7FC@mi crosoft.com...
                C16DLL.def
                ----
                LIBRARY "C16DLL"
                EXPORTS
                C16_DLLCALL @1
                That is good.

                C16DLL.h (apart from that only has the standard definition of C16DLL_API
                __declspec(dlle xport) etc.)
                ----
                extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );
                OK.
                (But I would prefer useinga #ifdef __cplusplus guard here...)

                C16DLL.cpp (includes also stdafx.h which is including some header files
                for
                the different types/structs I have to use so that they work with the
                target
                application)
                ----
                vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
                {
                I think the problem is here.
                This is a .CPP file, so I think that you should add 'extern "C"' explicitly
                here:

                // Function implementation in .cpp file
                extern "C" vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
                {
                ...
                }

                HTH,
                Giovanni


                Comment

                • =?Utf-8?B?UGF0cmljayBXZXN0ZXJob2Zm?=

                  #9
                  Re: DLL export, decorated function

                  Hi Giovanni,

                  thank you for your answer, however sadly it didn't solve the problem either..

                  "Giovanni Dicanio" wrote:
                  C16DLL.h (apart from that only has the standard definition of C16DLL_API
                  __declspec(dlle xport) etc.)
                  ----
                  extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );
                  >
                  OK.
                  (But I would prefer useinga #ifdef __cplusplus guard here...)
                  >
                  I actually tried that in between, but it will probably not change the
                  results if it doesn't work without.
                  I think the problem is here.
                  This is a .CPP file, so I think that you should add 'extern "C"' explicitly
                  here:
                  >
                  // Function implementation in .cpp file
                  extern "C" vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
                  {
                  ...
                  }
                  When I try this explicitely, it gives me
                  C16_DDLCALL = _C16_DDLCALL@4
                  Does it help if I would change the file extensions to .c or change the
                  compiler settings so that it would compile as a C project?

                  Thank you,
                  Patrick Westerhoff

                  Comment

                  • Giovanni Dicanio

                    #10
                    Re: DLL export, decorated function

                    Hi Patrick,

                    "Patrick Westerhoff" <PatrickWesterh off@discussions .microsoft.comh a
                    scritto nel messaggio
                    news:6C3755BD-BA1D-49AC-8810-6BA637DFC434@mi crosoft.com...
                    >I think the problem is here.
                    >This is a .CPP file, so I think that you should add 'extern "C"'
                    >explicitly
                    >here:
                    >>
                    >// Function implementation in .cpp file
                    >extern "C" vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
                    >{
                    > ...
                    >}
                    >
                    When I try this explicitely, it gives me
                    C16_DDLCALL = _C16_DDLCALL@4
                    Does it help if I would change the file extensions to .c or change the
                    compiler settings so that it would compile as a C project?
                    You could change the extension to .c, but I think it is not necessary; I
                    mean: you can still use C++ and have a "pure-C" interface.

                    Note that my answer is an addition to correct Sven's suggestion of using
                    ..def files for exporting.

                    I will do a test...

                    Giovanni


                    Comment

                    • SvenC

                      #11
                      Re: DLL export, decorated function

                      Hi Patrick,
                      >Did you add the def file to your project property settings?
                      >>
                      >Config Props/Linker/Input/Module Definition File
                      yes, it was added there automatically when I created it.
                      I do expect the same as Giovanni and I guess his test project
                      should work for you.

                      Maybe you should give us a minimal sample, which includes the
                      missing types: vERROR and vC16_CCB.

                      extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );

                      Maybe some weird preprocessor side effects are going on?

                      What happens when you put this test function in your header:

                      extern "C" int __stdcall TestFoo(int);


                      And this in your cpp:

                      extern "C" int __stdcall TestFoo(int x)
                      {
                      return x;
                      }

                      --
                      SvenC

                      Comment

                      Working...