managed-c++

Pointer to Pointer Managed C++

I have an old C library with a function that takes a void**: oldFunction(void** pStuff); I'm trying to call this function from managed C++ (m_pStuff is a member of the parent ref class of type void*): oldFunction( static_cast<sqlite3**>( &m_pStuff ) ); This gives me the following error from Visual Studio: error C2440: 'static_...

Tools for finding memory corruption in managed c++ code?

I have a .NET application, which is using an open source C++ compression library for compressing images. We are accessing the C++ library via managed C++. I'm seeing heap corruption during compression. A call to _CrtIsValidHeapPointer is finding an error on a call to free() when cleaning up after compression. My question is, are th...

How do I Convert an IntPtr to a Stream?

class Foo { static bool Bar(Stream^ stream); }; class FooWrapper { bool Bar(LPCWSTR szUnicodeString) { return Foo::Bar(??); } }; MemoryStream will take a byte[] but I'd like to do this without copying the data if possible. ...

EEFileLoadException when using C# classes in C++(win32 app)

For deployment reasons, I am trying to use IJW to wrap a C# assembly in C++ instead of using a COM Callable Wrapper. I've done it on other projects, but on this one, I am getting an EEFileLoadException. Any help would be appreciated! Managed C++ wrapper code (this is in a DLL): extern "C" __declspec(dllexport) IMyObject* CreateMyOb...

Difference between managed c++ and c++

The topics title is actually my question. And the second question is: When do I use what of these two? ...

Are there any tools for converting Managed C++ to C++/CLI?

We have an old project written using Managed C++ syntax. I would like to propose to the team a reasonably pain-free (I don't mind some level of human interaction, I think I'm realistic in my expectations that we'll still have to do some work by hand) method of updating the existing code to C++/CLI syntax so that we can also add XML docum...

Managed C++ Assembly Attributes

Is there a way to add assembly attributes to a Managed C++ assembly? IE, specifically in C# in the AssemblyInfo.cs file, you'd typically have something like this: [assembly: AssemblyTitle("Some Assembly")] I have a private assembly attribute that I want to add (not one of the version attributes that could be added through a resource f...

Handling Managed Delegates in Unmanaged code

I know I can get this to technically work but I'd like to implement the cleanest possible solution. Here's the situation: I have a managed library which wraps an unmanaged C-style library. The C-style library functionality I'm currently wrapping does some processing involving a list of strings. The library's client code can provide a...

How do you catch a managed exception (from a delegate) in unmanaged C++

I have unmanaged C++ calling a managed delegate via the function pointer provided by Marshal::GetFunctionPointerForDelegate. This delegate has the potential to throw an exception. I need to be able to properly handle this exception in my unmanaged C++ to ensure things like pointer cleanup, and potentially rethrow the exception up into ...

In managed C++, how do I declare and call a function with an 'out' parameter?

I have a function which parses one string into two strings. In C# I would declare it like this: void ParseQuery(string toParse, out string search, out string sort) { ... } and I'd call it like this: string searchOutput, sortOutput; ParseQuery(userInput, out searchOutput, out sortOutput); The current project has to be done in m...

pass DataTable to unmanaged environment (visual c# 2005)

Hi, What will the best way to pass a datatable data to unmanaged environments? (c++) Ofer ...

string to char* marshaling

Hi, a strange problem .... I wrote a managed c++ class that has the followig function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage) { strErrorMessage = (char*) Marshal::StringToHGlobalAnsi(_managedObject->GetLastError()).ToPointer(); } As you can see, this is simple methode to copy the managed string of the l...

_CRT_DEBUGGER_HOOK throws exception

Hi, I'm having a problem converting my program from VS2005 to VS2008. When I run the program in VS2008, the application starts up fine but when start playing around with the application it crashes giving me this error: "Microsoft Visual Studio C Runtime Library has detected a fatal error" And then the debugger points me to this functi...

MC++ interop array access

Using Managed C++ (VS 2005), how would you pass a array< unsigned char > to a function as a unsigned char*? ref class Utils { public: static void A(array<unsigned char, 1> a) { //How do I call B()???? } static void B(const unsigned char* a) { //do stuff } }; ...

What is the Managed C++ equivalent to the C# using statement

How would one code the following C# code in Managed C++ void Foo() { using (SqlConnection con = new SqlConnection("connectionStringGoesHere")) { //do stuff } } Clarificaton: For managed objects. ...

Generic Generics in Managed C++

I want to create a List of KeyValuePairs in a managed C++ project. Here is the syntax I'm using List<KeyValuePair<String^, String^>^>^ thing; but I'm getting the following error: error C3225: generic type argument for 'T' cannot be 'System::Collections::Generic::KeyValuePair ^', it must be a value type or a handle to a reference t...

Creating a KeyValuePair in Managed C++

I have yet another managed C++ KeyValuePair question where I know what to do in C#, but am having a hard time translating to managed C++. Here is the code that does what I want to do in C#: KeyValuePair<String, String> KVP = new KeyValuePair<string, string>("this", "that"); I've reflected it into MC++ and get this: KeyValuePair<Strin...

How do you dispose of an IDisposable in Managed C++

I'm trying to Dispose of an IDisposable object(FileStream^ fs) in managed C++ (.Net 2.0) and am getting the error 'Dispose' : is not a member of 'System::IO::FileStream' It says that I should invoke the destructor instead. Will calling fs->~FileStream(); call the dispose method on the FileStream object? Why can't I call Dispose? ...

Verbatim Literals in Managed C++? (like C#'s @"blah")

Is there a way to use verbatim String literals in managed C++? Similar to C#'s String Docs = @"c:\documents and settings\" ...

Unresolved Token in Managed C++

I have a mystery on my hands. I am trying to learn managed C++ coming from a C# background and have run into a snag. If I have a project which includes two classes, a base class Soup and a derived class TomatoSoup which I compile as a static library (.lib), I get unresolved tokens on the virtual methods in Soup. Here is the code: Abst...