managed-c++

False Alarm: SqlCommand, SqlParameter and single quotes

Hello! I'm trying to fix single quote bug in the code: std::string Index; connection->Open(); String^ sTableName = gcnew String(TableName.c_str()); String^ insertstring = String::Format("INSERT INTO {0} (idx, rec, date) VALUES (@idx, @rec, getdate())", sTableName); SqlCommand^ command = gcnew SqlCommand(insertstring, connection); St...

Instantiating a child class as the parent, but calling the child's methods

I am writing an application that required the development of an engine for handling data, but the engine had to be replaceable by another depending on the customers' need. Since each customer had very different needs, I wanted to make each engine separated from the others so we could only deliver the application with the engines the cust...

How to convert a user-defined unmanaged type to a managed type?

I have a test that I'm writing in MSTest, which is managed C++, and I'm trying to test an unmanaged class. Specifically, I'm trying to use the PrivateObject class to call a private method. This is the code that I have so far: CUnmanagedType foo; PrivateObject privateFoo = gcnew PrivateObject( foo ); CString strFromFoo = privateFoo.Inv...

Managed C++ unresolved token

I'm new to managed C++. I have two managed C++ projects in a single .sln, Project Lib and Project LibTest. LibTest makes use of Lib. Lib compiles and links fine. The project is set as a .dll. LibTest is also compiled as .dll, but when it goes into linking, I get "unresolved token" on all of the Lib::methods. Those methods definitions ...

C++/CLI Converting from System::String^ to std::string

Can someone please post a simple code that would convert System::String^ to C++ std::string ? i.e I just want to assign the value of String^ originalString; to std::string newString; ...

How can I implement variant types in the CLR/Managed C++ ?

In the .net CLR Object is the base for all class objects, but not basic types (e.g. int, float etc). How can I use basic types like Object? I.e. Like Boost.Variant? E.g. like :- object intValue( int(27) ); if (intValue is Int32) ... object varArray[3]; varArray[0] = float(3.141593); varArray[1] = int(-1005); varArray[2] = string("...

Arrays of strings in Managed C++

I'm trying to write an application in Managed C++, but I cannot work out how to declare an array of strings. String^ linet[]; throws an error 'System::String ^' : a native array cannot contain this managed type So I suppose there's a different way to do this for managed data types. What exactly is it? ...

DependencyProperties where the value is not stored locally

I'm a little confused on creating a DependencyProperty for properties that depend on external sources. For example, in an ultrasound application I'm writing, I currently have the following in a Managed C++ wrapper (translated to C# for simplicity on here, implementing INotifyPropertyChanged): public int Gain { get { return ultrasoun...

Callback unmanaged code from managed C#

Bit of a history lesson here. I'm working on a legacy C++/MFC application and am trying to start a incremental modernization by pushing components written in C# (WinForms and later WPF). I'm stucking using .Net/1.1 and VS/2003 for many reasons which are impossible to resolve in the near future. Currently, as a proof of concept, someth...

C++ calling C# options

Hi We have native Win32 C++ code and a set of C# assemblies which we wish to call from the C++ code. I summaries our optios as: Use COM. The C# code would need to be decorated with additional attributes (GUID, COMVisible). The C# assemblies would need to be registered regasm and would then be available to the native C++ code via CO...

AccessViolationException in Release mode (C++)

Hi, I'm getting the following exception when I run my application in Release mode from Visual C++. Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at _cexit() at .LanguageSupport._UninitializeDefaultDomain(Vo...

Events in Managed C++: Problem with Events, WindowEvents

Hello, Working on a VisStudio 2008 addin, using managed C++ (C++/CLR in the New Project wizard). In the OnConnection() function, I want to add a handler to the WindowEvents collection. When I do this: // Hook up events EnvDTE::Events ^ events = _applicationObject->Events; EnvDTE::WindowEvents ^winEvents = events->WindowEve...

Learning C++ from scratch in Visual Studio?

I need to get up to speed with C++ quite quickly (I've never used it previously) - is learning through Visual Studio (i.e. Managed C++) going to be any use? Or will I end up learning the extensions and idiosyncracies of C++ in VS, rather then the language itself? If learning in VS is not recommended, what platform / IDE do you guys sugg...

managed c++ syntax

Try as I might, I cannot convert this Managed C++ code to C++/CLI. Can someone give a pointer (pun intended)? static String *ignoreStrings[]; Later in the code, an Add(string) method is called on it. Elsewhere, in some C# code, new String[]{"foo", "bar"} is passed into a function that is somehow cast into the type of ignoreStrin...

Necessary to pin_ptr on C++ CLR Value types, why?

Since .NET Value types (managed C++ structs) are stored on the Stack why is it (or, alternatively is it actually) necessary to pin_ptr them in order to pass a pointer to an unmanaged function? Eg. BYTE b[100]; If I pass &b to an unmanaged function without first pinning it, may the stack become corrupted? Is the CLR stack subject to c...

understanding String^ in C++ .Net

I remember seeing somewhere there "^" operator is used as a pointer operator in Managed C++ code. Hence "^" should be equivalent to "*" operator right?? Assuming my understanding is right, when I started understanding .Net and coded a few example programs, I came across some code like this: String ^username; //my understanding is you ...

private/public class in namespace problem

This is a question about what defining a class as public or private does. Right now, I have various classes defined inside of a namespace and I only want some of those classes to be visible/usable to the outside world. So, for example, if the classes below were the only ones in the program, I would want main.cpp to only be able to see/...

in VS2008, where do I configure the "Platform Target" for a (managed) C++ project?

In VS2008, I can specify that a C# assembly should target only the x86 platform by going to the project properties, clicking the "Build" section, and then setting the "Platform target" box. What is the equivalent for an assembly written in C++? ...

Why is unmanaged exception call stack is missing relevant information when caught in managed code?

I have an application that consists of managed and unmanaged DLLs. My managed DLL is a C++/CLR DLL that is used to access a native C++ DLL. When code crosses from managed to native the logic is wrapped in a try/catch statement. The purpose is to log any exceptions before we rethrow them. C++/CLR code calling into native code. try ...

Passing an unmanaged C++ structure by reference to a managed C++ method causes an access violation when the structure is referenced

I'm trying to pass this structure: #pragma unmanaged typedef struct { void* data; unsigned nlen; unsigned int type; } PARAMETER; To this class static method: #pragma managed private class __gc GlobalFunctions { static void WriteField(Object* object, PARAMTER& par, unsigned dec) { switch (par.type) { ...