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. Call dll problem

Call dll problem

Scheduled Pinned Locked Moved Managed C++/CLI
helpcsharpc++question
2 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.
  • K Offline
    K Offline
    Kash
    wrote on last edited by
    #1

    Hi, I have created a test dll in Fortran that squares an input number. Then I'm trying to call this dll from C++.NET using the following bit of code: #include using namespace std; extern "C" __declspec(dllimport)double square(double X); int main(int argc, char* argv[]) { double a=4; double asq = square(a); cout << a << " " << asq << endl; return 0; } `I get the following error: HelloWorld error LNK2019: unresolved external symbol __imp__square referenced in function _main I've added MyDll.lib as a reference from the Fortran code but no success. (I'm not able to add MyDll.dll however, is this normal?) Any ideas please? Kash`

    U 1 Reply Last reply
    0
    • K Kash

      Hi, I have created a test dll in Fortran that squares an input number. Then I'm trying to call this dll from C++.NET using the following bit of code: #include using namespace std; extern "C" __declspec(dllimport)double square(double X); int main(int argc, char* argv[]) { double a=4; double asq = square(a); cout << a << " " << asq << endl; return 0; } `I get the following error: HelloWorld error LNK2019: unresolved external symbol __imp__square referenced in function _main I've added MyDll.lib as a reference from the Fortran code but no success. (I'm not able to add MyDll.dll however, is this normal?) Any ideas please? Kash`

      U Offline
      U Offline
      ursus zeta
      wrote on last edited by
      #2

      In the C++ .NET Framework you don't import functions from a DLL like you do in Win32; the syntax is different. The correct method is to use the DllImport attribute, which is located in: System::Runtime::InteropServices. Using the DllImport Attribute[^]

      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