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. Managed C++/CLI
  4. Including .dll in /clr:pure project [VC++ '05]

Including .dll in /clr:pure project [VC++ '05]

Scheduled Pinned Locked Moved Managed C++/CLI
c++csharpdotnetquestionlounge
5 Posts 2 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.
  • J Offline
    J Offline
    jantimmerman
    wrote on last edited by
    #1

    Hello, Is it possible to include a .dll in a /clr:pure project? I am currently using unmanaged code for this. I was wondering if it is also possible with a /clr:pure project which does not allow native C++? Including a .dll can be done with C#. (Full setting is "Pure MSIL Common Language Runtime Support (/clr:pure)" in the project properties -> General) best regards, Jan Timmerman

    M 1 Reply Last reply
    0
    • J jantimmerman

      Hello, Is it possible to include a .dll in a /clr:pure project? I am currently using unmanaged code for this. I was wondering if it is also possible with a /clr:pure project which does not allow native C++? Including a .dll can be done with C#. (Full setting is "Pure MSIL Common Language Runtime Support (/clr:pure)" in the project properties -> General) best regards, Jan Timmerman

      M Offline
      M Offline
      Milton Karimbekallil
      wrote on last edited by
      #2

      What do you mean by 'include a dll'? If ur question is whether an unmanaged dll can be used in a /clr:pure c++/cli project, Yes, You can do. Inlcude the lib and header file to c++/cli project and you can create objects of unmanaged clasees in the dll or u can call unmanaged functions in that dll. You can use a com dll as well using the #import c++/cli is the only language where u can mix both managed unmanaged code. deoes this make sense...mil10.

      J 1 Reply Last reply
      0
      • M Milton Karimbekallil

        What do you mean by 'include a dll'? If ur question is whether an unmanaged dll can be used in a /clr:pure c++/cli project, Yes, You can do. Inlcude the lib and header file to c++/cli project and you can create objects of unmanaged clasees in the dll or u can call unmanaged functions in that dll. You can use a com dll as well using the #import c++/cli is the only language where u can mix both managed unmanaged code. deoes this make sense...mil10.

        J Offline
        J Offline
        jantimmerman
        wrote on last edited by
        #3

        Thanks for your reply: Well that was about where I was aiming at. I never heard of the "#import" directive before so I will have to look into that. I have not too much experience with Visual studio. Perhaps I should explain a little more about the situation. Currently I have a ".lib" and a ".dll" generated by Compaq Visual Fortran. I've declared the function called from the .dll as follows: extern "C" void __declspec(dllimport) extiteratie( [arguments] ) First I get the warning: TFortranInterface.cpp(27) : warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify native calling convention when importing a function. after that an error error LNK2031: unable to generate p/invoke for "extern "C" void __clrcall extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata (After this an unresolved token error which is most likely caused by the previous error.) I am currently using a native class as interface because I need to pass the function in the .dll a set of pointers which will be filled with results. The questions: 1. With /clr:pure I cannot use that native class? 2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?) (3. what does #import do?) best regards, Jan Timmerman

        M 1 Reply Last reply
        0
        • J jantimmerman

          Thanks for your reply: Well that was about where I was aiming at. I never heard of the "#import" directive before so I will have to look into that. I have not too much experience with Visual studio. Perhaps I should explain a little more about the situation. Currently I have a ".lib" and a ".dll" generated by Compaq Visual Fortran. I've declared the function called from the .dll as follows: extern "C" void __declspec(dllimport) extiteratie( [arguments] ) First I get the warning: TFortranInterface.cpp(27) : warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify native calling convention when importing a function. after that an error error LNK2031: unable to generate p/invoke for "extern "C" void __clrcall extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata (After this an unresolved token error which is most likely caused by the previous error.) I am currently using a native class as interface because I need to pass the function in the .dll a set of pointers which will be filled with results. The questions: 1. With /clr:pure I cannot use that native class? 2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?) (3. what does #import do?) best regards, Jan Timmerman

          M Offline
          M Offline
          Milton Karimbekallil
          wrote on last edited by
          #4

          1. With /clr:pure I cannot use that native class? Yes, You can use native class in a /clr:pure c++/cli project. 2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?) Note the warning you got: "warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify **native calling convention** when importing a function." Your function declaration was: extern "C" void __declspec(dllimport) extiteratie( [arguments] ): Here you havn't mentioned any calling convention. So compiler took the clr only calling convention __clrcall. Now see the error message you got - "error LNK2031: unable to generate p/invoke for "extern "C" void __clrcall extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata" This means that C++/CLI compiler is not able to generate the p/invoke for a function which is reserverd for CLI only (because of the by default __clrcall calling convention). So to fix this, change the function declaration as below: extern "C" void __stdcall __declspec(dllimport) extiteratie( [arguments] ) Here if the calling convention of extiteratie is soemthing else other than __stdcall , then put the same instaed. 3. what does #import do?) You dont have to worry abt #import as ur dll is not a com dll. It is for using com components. Hope this will help...mil10.

          J 1 Reply Last reply
          0
          • M Milton Karimbekallil

            1. With /clr:pure I cannot use that native class? Yes, You can use native class in a /clr:pure c++/cli project. 2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?) Note the warning you got: "warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify **native calling convention** when importing a function." Your function declaration was: extern "C" void __declspec(dllimport) extiteratie( [arguments] ): Here you havn't mentioned any calling convention. So compiler took the clr only calling convention __clrcall. Now see the error message you got - "error LNK2031: unable to generate p/invoke for "extern "C" void __clrcall extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata" This means that C++/CLI compiler is not able to generate the p/invoke for a function which is reserverd for CLI only (because of the by default __clrcall calling convention). So to fix this, change the function declaration as below: extern "C" void __stdcall __declspec(dllimport) extiteratie( [arguments] ) Here if the calling convention of extiteratie is soemthing else other than __stdcall , then put the same instaed. 3. what does #import do?) You dont have to worry abt #import as ur dll is not a com dll. It is for using com components. Hope this will help...mil10.

            J Offline
            J Offline
            jantimmerman
            wrote on last edited by
            #5

            Great, it works! i've modified the function call to extern "C" void __cdecl extiteratie( [arguments] ) (from the error messages I noticed the compiler ignores the "__declspec(dllimport)" part when including __cdecl) Also I added an underscore to the function export in the Fortran code which was needed by __cdecl. An alternative is (most likely but not tested) to use __stdcall in the export. I do not think it makes much difference whether I use __stdcall or __cdecl? Thanks a lot! Jan Timmerman

            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