Results 1 to 4 of 4

Thread: How to use managed c++ classes/features in C#

  1. #1
    Join Date
    Nov 2008
    Posts
    996

    How to use managed c++ classes/features in C#

    This was working very well, but since .cpp file got overwritten with what was in .h file, everything just went crazy. I make a dll in managed C++ in VS2005.

    .h file:

    Code:
    namespace DetectorInterface {
    
    public ref class DetInt 
    {
    public: 
    __declspec (dllexport) bool nonsense (); 
    }; 
    }

    .cpp file:

    Code:
    namespace DetectorInterface {
    
    public ref class DetInt 
    {
    bool nonsense () 
    {
    return false; 
    }
    }; 
    }

    I have added a C# program to the DLL, and applied using DetectorInterface.

    When can I do DetInt detector = new DetInt ();. Everything hurt well so far. But I could not find a feature that is defined.

  2. #2
    Join Date
    May 2008
    Posts
    1,196

    Re: How to use managed c++ classes/features in C#

    Code:
    bool DetectorInterface :: DetInt :: nonsense () 
    {
    return false; 
    }

  3. #3
    Join Date
    Nov 2008
    Posts
    996

    Re: How to use managed c++ classes/features in C#

    OK, tried again. Here is .h file from a c++ class library project.

    Code:
    // DLLTest.h 
    #pragma once 
    using namespace System; 
    
    namespace DLLTest {
    public ref class MostlyHarmless 
    {
    public: 
    int DLLTest::MostlyHarmless::LifeUniverseAndEverything() 
    {
    return 42; 
    }
    }; 
    }
    Thank you!

    But then comes a small challenge.

    Code:
    int* getImage () 
    {
    int* arr = new int [7744]; 
    // Do stuff here ... 
    
    return arr;
    How do I handle it in C# program?

  4. #4
    Join Date
    May 2008
    Posts
    1,196

    Re: How to use managed c++ classes/features in C#

    int* getImage ()
    {
    int* arr = new int [7744];
    image = GetImage (ctr);
    return (int*) image -> data;
    }

    image is a struct which contains the image data, as an array.

    Here's some code that uses min .Dll.

    Code:
    unsafe 
    {
    int* imagePtr; 
    int[,] image = new int [88, 88]; 
    imagePtr = detector.getImage (); 
    image = arrayTo2DArray (imagePtr); 
    }

Similar Threads

  1. Calling JavaScript from Managed Code
    By Computer_Freak in forum Tips & Tweaks
    Replies: 1
    Last Post: 03-08-2010, 03:31 PM
  2. Managed Client Don't Detect Virus
    By ASHER in forum Networking & Security
    Replies: 4
    Last Post: 10-04-2010, 11:32 AM
  3. Does anyone know what is 'Managed code'?
    By Bottlenecked in forum Software Development
    Replies: 4
    Last Post: 04-02-2010, 10:08 AM
  4. SCE managed computers group policy
    By Halyn in forum Operating Systems
    Replies: 3
    Last Post: 27-06-2009, 06:49 PM
  5. Can't uninstall managed application
    By hariharan_00 in forum Windows XP Support
    Replies: 3
    Last Post: 25-08-2008, 10:22 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,633,643.50723 seconds with 16 queries