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. Memory access exception instantiating c++ native code from /clr c++ code

Memory access exception instantiating c++ native code from /clr c++ code

Scheduled Pinned Locked Moved Managed C++/CLI
c++helpcsharpdotnetcom
4 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.
  • R Offline
    R Offline
    redivider
    wrote on last edited by
    #1

    Here is my setup. - c# wrapper calls managed c++ API code - managed c++ calls unmanaged API code (c++ compiled with the /clr flag, located in the same project) using static funtions - API tries to instantiate object defined in another dll (native c++)

    void Screen::EvaluateScreen(LPCTSTR lpStrScreen, LPCTSTR lpStrSetName, LPCTSTR lpStrPeriods)
    {
    NativeDocument *screenDoc = NULL;
    screenDoc = new NativeDocument;

    calling the constructor causes a "Attempted to read write protected memory. ....memory corupt?..." error in the contstructor code. I'm new to c++ coding as well as this interop stuff. Any ideas? Is there an issue instantiating native code from inside the /clr compiled c++? The code i'm using (EvaluateScreen) is lifted from another native DLL so the code in there should be good (i guess).

    N 1 Reply Last reply
    0
    • R redivider

      Here is my setup. - c# wrapper calls managed c++ API code - managed c++ calls unmanaged API code (c++ compiled with the /clr flag, located in the same project) using static funtions - API tries to instantiate object defined in another dll (native c++)

      void Screen::EvaluateScreen(LPCTSTR lpStrScreen, LPCTSTR lpStrSetName, LPCTSTR lpStrPeriods)
      {
      NativeDocument *screenDoc = NULL;
      screenDoc = new NativeDocument;

      calling the constructor causes a "Attempted to read write protected memory. ....memory corupt?..." error in the contstructor code. I'm new to c++ coding as well as this interop stuff. Any ideas? Is there an issue instantiating native code from inside the /clr compiled c++? The code i'm using (EvaluateScreen) is lifted from another native DLL so the code in there should be good (i guess).

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      redivider wrote:

      Is there an issue instantiating native code from inside the /clr compiled c++

      No. /clr compiler switch indicates that a mixed mode assembly has to be generated. It can work with both managed and unmanaged types. Where is NativeDocument located? Is that in the DLL? Is your application multi-threaded?

      Best wishes, Navaneeth

      R 1 Reply Last reply
      0
      • N N a v a n e e t h

        redivider wrote:

        Is there an issue instantiating native code from inside the /clr compiled c++

        No. /clr compiler switch indicates that a mixed mode assembly has to be generated. It can work with both managed and unmanaged types. Where is NativeDocument located? Is that in the DLL? Is your application multi-threaded?

        Best wishes, Navaneeth

        R Offline
        R Offline
        redivider
        wrote on last edited by
        #3

        Not multi-threaded. NativeDocument is in another dll C# dll -> /clr dll -> c++ dll (w/ NativeDocument class)

        N 1 Reply Last reply
        0
        • R redivider

          Not multi-threaded. NativeDocument is in another dll C# dll -> /clr dll -> c++ dll (w/ NativeDocument class)

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          I couldn't reproduce this error. I have created a native DLL which has a sample NativeDocument class. Exported the functions and used this class from C++/CLI. Created a C# application and referred C++/CLI DLL there and everything worked as expected. If you can provide more information to reproduce, I will try.

          Best wishes, Navaneeth

          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