c++-cli

modopt and .NET reflection

I have a CLI/C++ interface that I want to examine via .NET Reflection. Here's the function signature in the source code: class ClassA; template<typename _Type> class ClassTempA; public interface class Test : BaseFunc { public: ClassTempA<int>& SomeFunc2(ClassA inst) = 0; }; Here's what the function looks like when examined in .N...

InternalsVisibleTo not working for Managed C++

InternalsVisibleTo is not working for my managed C++ projects, but it is for my C# projects. Any help would be appreciated. Here is a simplified layout. Project A - C#, has an internal property I want to access from B/C. Project B - Managed C++. References A. Project C - C#, references A. All projects are signed with the same key. Lo...

Is it possible for native class to consume .NET event?

Any idea how to initialize .NET delegate that points to method from 'mixed' class instance? I have 'mixed' C++ class like this: class CppMixClass { public: CppMixClass(void){ dotNETclass->StateChanged += gcnew DotNetClass::ServiceStateEventHandler(&UpdateHealthState); } ~CppMixClass(void); void UpdateState(System:...

Proper way of raising events from C++/CLI ?

Hi, I was wondering what's the proper way of raising events from C++/CLI. In C# one should first make a copy of the handler, check if it's not null, and then call it. Is there a similar practice for C++/CLI? ...

How do you treat handles in C++/CLI?

I know I'm not asking this quite right, either. Please help me better form my question. I'm having a bit of a hard time getting my mind wrapped around handles -- in some ways, it looks like pointers. But unlike pointers, it seems like I can assign values directly to the handle variable, and it affects the underlying data value, not t...

Silverlight and C++ or C++ to C# ongoing code conversion?

I am working on a drawing-based product where I want to produce versions for iPhone, desktop OS/X, Windows Tablets, Silveright-based browser, Windows Mobile, and Windows in that order of priority. For GUI portability, the classic answer is to keep the core in C++ and use Cocoa/Objective-C or WPF/C# thin layers. However, Silverlight com...

C++: What would be an appropriate solution to forming a collection of different data types?

I'm writing a command line interpreter and I'm trying to setup formats for individual commands. I have things like the name of the command, the maximum amount of parameters and the minimum amount of parameters. I want to have sort of collection, a sort of prototype of what kind of types the parameters are. My first thought was just to d...

what is the C++/CLI syntax to subscribe for events?

I'm updating some old Managed C++ code with lines like this: instanceOfEventSource->add_OnMyEvent( new EventSource::MyEventHandlerDelegate(this, MyEventHandlerMethod) ); where EventSource is the class that publishes events instanceOfEventSource is an instance of that class EventSource::MyEventHandlerDelegate is the delegate typ...

What is the best way to initialize an array to a fixed-length array? (C++/CLI)

In managed C++/CLI, I could do this either as (1): array<System::Byte>^ css_keycode = {0x51, 0x67, 0x67, 0xc5, 0xe0, 0x00}; or (2): array<System::Byte>^ css_keycode; css_keycode = gcnew array<System::Byte>(6) {0x51, 0x67, 0x67, 0xc5, 0xe0, 0x00}; But I apparently can't do (3): array<System::Byte>^ css_keycode; css_keycode = {0x5...

Visual C++ GUI app stuck in MTA mode

I've got a C++ gui project exhibiting some strange behavior. On my machine, the code compiles and runs just fine. However, on another machine, The code compiles but ends up running in MTA somehow. Obviously, being in MTA causes all sorts of runtime problems for the GUI. Here is my main: [STAThreadAttribute] int main(...

Can you derive a Managed C++ class from an Unmanaged C++ class?

I have an unmanged C++ class I have written in an unmanged dll. I have a managed dll that references the unmanaged dll. Can a class in the managed dll derive from the unmanaged class? Using Visual Studio 2008 ...

Transferring vector of objects between C++ DLL and Cpp/CLI console project

Hi, I have a C++ library app which talks to a C++ server and I am creating a vector of my custom class objects. But my Cpp/CLI console app(which interacts with native C++ ), throws a memory violation error when I try to return my custom class obj vector. Code Sample - In my native C++ class - std::vector<a> GetStuff(int x) { -- do...

C++ CLI cryptic function call

So I'm trying to call a function that is a manged wrapper around an OCX object. Having great difficulty. Function is; foo(System::Object ^% theBuffer) where 'theBuffer' is an array of bytes. The template for the unmanaged OCX which 'foo' wraps is goo(VARIANT* theBuffer); So I've tried; System::Int32 buf[10]; foo(buf); which fail...

Visual Studio 2008 linker error: ALINK operation failed (80070005) : Access is denied

I have Visual Studio 2008 (9.0.30729.1 SP) installed on my computer and a build machine. On my computer, a project builds fine. On the build machine, I have started getting this error. ALINK operation failed (80070005) : Access is denied This is incredibly irritating because it doesn't say Access TO WHAT??? is denied. I've tried rebo...

Is there a way to use C++/CLI managed Enums as array subscripts?

i have an enum declared as enum class AccessLevel : int { ReadOnly = 0, Excluded = 1, ReadWrite = 2, }; and an Array declared as static array<String^>^ _accessMap = gcnew array<String^> { "R", "X", "W" }; I want to do something like this: AccessLevel^ access = access::ReadOnly; String^ foo = _accessMap[access]; ...

Can I stop C++/CLI from adding IDisposable to my ref class?

C++/CLI helpfully generates the IDisposable scaffolding for you when you implement a destructor on a ref class. Also, if you don't implement a destructor, but your class has a member variable which implements IDisposable, then IDisposable is again automatically implemented on your class. It's pretty helpful and much better than how IDisp...

Applying pin_ptr to fields

I have some C++/CLI code that needs to pin a struct (value type) in order to pass it back to unmanaged code. The unmanaged code knows enough to unmarshal what it needs. The struct may contain managed strings and so I also need to pin these before calling the unmanaged function. The problem is that my managed helper class is generic: ...

MSBuild fails to build C++/CLI friend assemblies

I have Visual Studio 2008 SP1, two C++/CLI projects, lets say proj1 and proj2. proj2 is dependent on proj1, but in a weird way (see below). In Project Dependencies I specify that proj2 depends on proj1. Also proj2 references include proj1. Then I want proj1 to be a friend to proj2, so, as MSDN page on "Friend Assemblies" says, I write so...

Is it acceptable to add a "using namespace" immediately after the namespace declaration?

I have a small namespace containing some type definitions, which I use to make my code look cleaner. However I don't want to have to add a "using namespace ..." line to every file that uses one of these types, after all I already have to add a #include for the file. MyFile.cpp: #include "typedefs.h" void Bob() { IntList^ list = gcne...

C++/CLI generates ugly-looking raise_XXX methods for events

Hi, I'm writing my custom events in C++/CLI (I pretty much only care about the add/remove methods) as such: event EventHandler<XyzEventArgs^> ^Xyz { void add(EventHandler<XyzEventArgs^> ^handler); void remove(EventHandler<XyzEventArgs^> ^handler); void raise(Object ^sender, XyzEventArgs ^e); } Ever...