none
Cannot call exported methods from DLL ( DLL target: .Net 4, referencing XNA 3.1, using __declspec(dllexport) for legacy host ) RRS feed

Answers

  • The main source code is pure native:

    // File: Library.cpp
    // Compile: cl.exe /LD /clr /AIrefs Library.cpp
    #using <Microsoft.Xna.Framework.dll>
    __declspec(dllexport) void Method1()
    {
      Microsoft::Xna::Framework::Curve c;
      c.Evaluate(0);
    }
    
    // File: HelloWorld.cpp
    // Compile: cl.exe HelloWorld.cpp Library.lib
    extern __declspec(dllimport) void Method1();
    void main() { Method1(); }
    
    <!-- HelloWorld.exe.config -->
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0"/>
     </startup>
    </configuration>

    You need additional copy step: copy Library.dll.manifest HelloWorld.exe.manifest

    -Karel

    • Marked as answer by IRRR Friday, April 23, 2010 1:26 PM
    Thursday, April 22, 2010 4:56 PM
    Moderator

All replies

  • 1) Does it work without using XNA?
    2) What kind of exception is thrown? (Get full call stack)

    -Karel

    Monday, April 19, 2010 8:16 PM
    Moderator
  • If does work without XNA. It does work too if I call the method from a CLR project.

     

    The thing is, I call it from legacy code I can't modify, which does not run on CLR.

     

    Unhandled exception at 0x760c9617 in Importer.exe: 0xE0434352: 0xe0434352.

    Stack:

      KernelBase.dll!760c9617()

      [Frames below may be incorrect and/or missing, no symbols loaded for KernelBase.dll]

      KernelBase.dll!760c9617()

      clrjit.dll!6ae93247()

      clrjit.dll!6ae93396()

      clrjit.dll!6ae934c9()

      clr.dll!647c1d9e()

      00182e9c()

      clr.dll!647c191f()

      clr.dll!647c1e36()

      004bbee0()

      clr.dll!647d06b6()

    > Importer.exe!main()  Line 13 + 0x8 bytes C++


     

    Monday, April 19, 2010 8:26 PM
  • Did you use MS symbol server? (http://support.microsoft.com/default.aspx/kb/311503?p=1 ... hopefully 4.0 symbols are already there)
    This call stack is unfortunately useless without names.

    -Karel

    Tuesday, April 20, 2010 10:45 PM
    Moderator
  • BTW: I just tried your repro and it works fine on my machine.

    My steps:
    1. Fresh Win2008 installation
    2. Install XNA Framework 3.1 (downloaded from here)
    3. Build your 2 sources against Microsoft.Xna.Framework.dll (the assembly was installed in the GAC).
    4. Run it on 3.5 - works fine.
    5. Run it on 4.0 (with your config file) - works fine. (Verified that 4.0 was really loaded into memory)

    -Karel

    Wednesday, April 21, 2010 11:04 PM
    Moderator
  • Thanks for giving it a try.

     

    Just one question, did you build both sources against  Microsoft.Xna.Framework.dll ? , It works for me if both are managed, but it fails when the calling source is not ( on 3.5 does not fail).

    Thursday, April 22, 2010 2:50 AM
  • The main source code is pure native:

    // File: Library.cpp
    // Compile: cl.exe /LD /clr /AIrefs Library.cpp
    #using <Microsoft.Xna.Framework.dll>
    __declspec(dllexport) void Method1()
    {
      Microsoft::Xna::Framework::Curve c;
      c.Evaluate(0);
    }
    
    // File: HelloWorld.cpp
    // Compile: cl.exe HelloWorld.cpp Library.lib
    extern __declspec(dllimport) void Method1();
    void main() { Method1(); }
    
    <!-- HelloWorld.exe.config -->
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0"/>
     </startup>
    </configuration>

    You need additional copy step: copy Library.dll.manifest HelloWorld.exe.manifest

    -Karel

    • Marked as answer by IRRR Friday, April 23, 2010 1:26 PM
    Thursday, April 22, 2010 4:56 PM
    Moderator
  • Hey now it works!

     

    Thanks a lot, I indeed missed the last step.

     

    [Just I think you ment "copy Library.dll.config HelloWorld.exe.config"  instead of: "copy Library.dll.manifest HelloWorld.exe.manifest]

    I previously thought the config file was only necessary for the managed project.

     

    Friday, April 23, 2010 1:15 PM
  • config file is the only necessary for managed part of your project, but both binaries are also native and CRT needs a native manifest ...

    -Karel

    Friday, April 23, 2010 3:50 PM
    Moderator