Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 01-12-2008
Member
 
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.
Reply With Quote
  #2  
Old 01-12-2008
Member
 
Join Date: May 2008
Posts: 1,180
Re: How to use managed c++ classes/features in C#

Code:
bool DetectorInterface :: DetInt :: nonsense () 
{
return false; 
}
Reply With Quote
  #3  
Old 01-12-2008
Member
 
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?
Reply With Quote
  #4  
Old 01-12-2008
Member
 
Join Date: May 2008
Posts: 1,180
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); 
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use managed c++ classes/features in C#"
Thread Thread Starter Forum Replies Last Post
Calling JavaScript from Managed Code Computer_Freak Tips & Tweaks 1 03-08-2010 03:31 PM
Managed Client Don't Detect Virus ASHER Networking & Security 4 10-04-2010 11:32 AM
Does anyone know what is 'Managed code'? Bottlenecked Software Development 4 04-02-2010 10:08 AM
SCE managed computers group policy Halyn Operating Systems 3 27-06-2009 06:49 PM
Can't uninstall managed application hariharan_00 Windows XP Support 3 25-08-2008 10:22 AM


All times are GMT +5.5. The time now is 01:49 AM.