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. .NET (Core and Framework)
  4. Call DLL in WinForms App Fails But Works In MFC App

Call DLL in WinForms App Fails But Works In MFC App

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpc++questionwinformscom
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.
  • J Offline
    J Offline
    Jonnster
    wrote on last edited by
    #1

    I have a DLL written in Visual C++ 6.0. I have a MFC test application which calls this DLL and it works fine. I also have a .NET C# WinForms test app which calls this DLL. I am importing the DLL and calling it successfully. I can see that the DLL is called correctly and all parameters are passed successfully. The DLL works for a time and then fails when trying to create a COM component by calling CoCreateInstance. This fails with an Access Violation. This doesn't happen when called from the MFC app. Why does this happen in the .NET app and how do I solve it?

    D 1 Reply Last reply
    0
    • J Jonnster

      I have a DLL written in Visual C++ 6.0. I have a MFC test application which calls this DLL and it works fine. I also have a .NET C# WinForms test app which calls this DLL. I am importing the DLL and calling it successfully. I can see that the DLL is called correctly and all parameters are passed successfully. The DLL works for a time and then fails when trying to create a COM component by calling CoCreateInstance. This fails with an Access Violation. This doesn't happen when called from the MFC app. Why does this happen in the .NET app and how do I solve it?

      D Offline
      D Offline
      Daniel Grondal
      wrote on last edited by
      #2

      Could you provide some more detailed information about how you use this from C#? Could you also provide more details about what kind of error you see when trying to use the dll? If my COM-memory is not totally wrong, CoCreateInstance() cannot be called until the calling thread has called CoInitalize(). Could that be your problem?

      //daniel

      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