Click here to Skip to main content
14,392,016 members

Managed C++/CLI

 
AnswerRe: C++ to C# through dll Pin
led mike7-Aug-06 7:15
Memberled mike7-Aug-06 7:15 
QuestionSTL incompatible with Windows Forms? Pin
ricecake4-Aug-06 8:57
Memberricecake4-Aug-06 8:57 
AnswerRe: STL incompatible with Windows Forms? Pin
ricecake4-Aug-06 11:34
Memberricecake4-Aug-06 11:34 
Questionc++/cli interop: wrapper should be notified if native object changes Pin
Ralf A.4-Aug-06 6:33
MemberRalf A.4-Aug-06 6:33 
QuestionVector list Pin
GameDesignerXIX3-Aug-06 17:43
MemberGameDesignerXIX3-Aug-06 17:43 
AnswerRe: Vector list Pin
Christian Graus3-Aug-06 17:52
protectorChristian Graus3-Aug-06 17:52 
AnswerRe: Vector list Pin
OrcBighter23-Aug-06 21:07
MemberOrcBighter23-Aug-06 21:07 
QuestionProblem including C++ code in C# assembly. Pin
OrcBighter23-Aug-06 16:42
MemberOrcBighter23-Aug-06 16:42 
I have a problem setting a class constant in my C# assembly to the value of a constant in a managed C++ class. The compiler does not seem to recognise that the managed C++ class constant is constant. The error message is shown below:

#error = "The expression being assigned to 'MyAssembly.SMyFooBar.bahName' must be constant

I am writing in Visual Studio 2003 on WinXP SP2 with .Net Framework V2.0.50727

What Have I done wrong here?


The reason for this attempt is that the majority of our code is unmanaged c++, which uses a glabal header file to set values through a number of projects.
I wish to include this header in our various new C# projects, and thus avoid double maintenance. If the header file changes, all that is needed is a code recompile, at least in theory.
To do this I wrapped the header file inside a managed c++ class to create a dll. I then included this dll as a reference in my C# project so that I could use it to initialise some c# constants, thus:


-- unmanaged C++ header
// CPPHeader.h

#ifndef CPPHeader_defined_hpp
#define CPPHeader_defined_hpp

#define MAX_FOOBARS 3
#define FOOBAR_NAME "Foo Bar"

#endif // CPPHeader_defined_hpp


---------------------
-- managed C++ class

//MyManagedClass.h compiled to a DLL
#pragma once
#include "CPPheader.h"

using namespace System;

public __gc class SMyManagedClass
{
public:
static const int maxFooBars = MAX_FOOBARS;
static const String* FooBarName = FOOBAR_NAME;
};

--------------------------

-- C# assembly

//MyFooBarAsembly.cs
using system;
using SMyManagedClass;

namespace MyAssembly
{
public class SMyFooBar
{
public const int maxBahs = SMyManagedClass.SMyManagedClass.maxFooBars;
public const string bahName = SMyManagedClass.SMyManagedClass.FooBarName;
}
}



OrcBighter2
AnswerRe: Problem including C++ code in C# assembly. Pin
Milton Karimbekallil4-Aug-06 3:06
MemberMilton Karimbekallil4-Aug-06 3:06 
GeneralRe: Problem including C++ code in C# assembly. Pin
OrcBighter26-Aug-06 19:27
MemberOrcBighter26-Aug-06 19:27 
QuestionHow to integrate best an MFC-component in .Net? Pin
gunag3-Aug-06 4:06
Membergunag3-Aug-06 4:06 
AnswerRe: How to integrate best an MFC-component in .Net? Pin
Milton Karimbekallil4-Aug-06 2:22
MemberMilton Karimbekallil4-Aug-06 2:22 
AnswerRe: How to integrate best an MFC-component in .Net? Pin
gunag5-Aug-06 1:53
Membergunag5-Aug-06 1:53 
GeneralRe: How to integrate best an MFC-component in .Net? Pin
Milton Karimbekallil7-Aug-06 1:00
MemberMilton Karimbekallil7-Aug-06 1:00 
QuestionAsyncCallback constructor error Pin
DQ843-Aug-06 2:44
MemberDQ843-Aug-06 2:44 
QuestionCan any "macro" take variable number of arguments? Pin
Pradosh Tapan Datta2-Aug-06 23:49
MemberPradosh Tapan Datta2-Aug-06 23:49 
AnswerRe: Can any "macro" take variable number of arguments? Pin
toxcct3-Aug-06 0:57
Membertoxcct3-Aug-06 0:57 
AnswerRe: Can any "macro" take variable number of arguments? Pin
Michael Dunn4-Aug-06 15:10
sitebuilderMichael Dunn4-Aug-06 15:10 
GeneralRe: Can any "macro" take variable number of arguments? Pin
Pradosh Tapan Datta6-Aug-06 22:27
MemberPradosh Tapan Datta6-Aug-06 22:27 
QuestionConfusion about % vs. & Pin
Joe Woodbury2-Aug-06 18:14
professionalJoe Woodbury2-Aug-06 18:14 
AnswerRe: Confusion about % vs. & Pin
Michael Dunn4-Aug-06 18:47
sitebuilderMichael Dunn4-Aug-06 18:47 
QuestionCin and Cout- Class or object Pin
Shamnar2-Aug-06 2:46
MemberShamnar2-Aug-06 2:46 
AnswerRe: Cin and Cout- Class or object Pin
NrmMyth2-Aug-06 6:52
MemberNrmMyth2-Aug-06 6:52 
GeneralRe: Cin and Cout- Class or object Pin
toxcct2-Aug-06 7:07
Membertoxcct2-Aug-06 7:07 
GeneralRe: Cin and Cout- Class or object Pin
NrmMyth2-Aug-06 20:58
MemberNrmMyth2-Aug-06 20:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.