|
Bsaksida,
Just wanted to follow up with you. Thanks for that sample project. At first glance, it appeared I was doing everything correctly, but a little deeper digging revealed the problem: My project is built with the /clr option rather than /clr:pure. Once I moved my custom control into a separate DLL project built with the /clr:pure switch, I was able to bring that control into forms in the main project with no problem.
Thanks again,
xpnctoc
|
|
|
|
|
The reason i put in dll, was because sometimes a IDE desing bisplayed errors instead design if it wasn't in dll.
|
|
|
|
|
I have two projects, one "Visual C++/CLR/Class Library" (DLL file) and one "Visual C#/Windows Application"
The DLL file:
namespace Foo<br />
{<br />
public ref class RC<br />
{<br />
public:<br />
static const System::Int16 value = 0;<br />
};<br />
<br />
public enum class EC : System::Int16<br />
{<br />
value = 0;<br />
};<br />
}
In the application I have the following problem:
static class Program {<br />
static void Main()<br />
{<br />
Int16 sh = Foo.EC.value;
switch(sh)<br />
{<br />
case Foo.RC.value:
MessageBox.Show("Information");<br />
break;<br />
}<br />
return 0;<br />
}<br />
I need to solve one of these problems (which one is not that important), i.e. to have implicit type casting from an enumeration to a short (or other type of integer), or to get a "static const" defined in MC++ to actually be a constant value.
I have looked all over the net trying to find a solution for this, but it seems that this behaviour actually is what is intended, is it really so?
Forgot to add, I am using VS 2005, i.e. .NET 2.0
-- modified at 5:37 Monday 8th January, 2007
Internet - the worlds biggest dictionary
|
|
|
|
|
The enum should not be derived from Int16.
Use the enum type name in c# not Int16 and you should be right
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|
|
Seems like I did not explain my problem good enough;
What I need is some way of having a constant value in MC++ as an integer of any size (have several of them, some 16-bit, some 32-bit and some 64-bit), and I need the value to be viewed from C# as constant.
When trying it as a "static const" value, as seen in my question, the compiler does not regard this as a constant value. When searching forums I found out that this is what the compiler should do, becase "static const is not const" or similar quote, and I found the suggestion of having it as a typed enumeration (i.e. public enum class NAME : TYPE), just as seen in my question.
The downside on doing this is that an enum is not implicitly casted to an integer, and then I have to write:
int i = (int) myEnum.value;
with the explicit type cast each time. This is the same both with and without the enum being derived from an integer, I have tried both.
What I am hoping is that I am not the only one who have tried this, and that someone out there has found a way of doing this, but since I have googled this it does not seem like this, so that is why I asked here.
Internet - the worlds biggest dictionary
|
|
|
|
|
ShermansLagoon wrote: get a "static const" defined in MC++ to actually be a constant value.
It is a "const". That means it is immutable. That is not the same thing as a compiler constant that is required for a case statement. C# is not C++, it has it's own definition of required const's for a case statement. I believe you need to use a different design for whatever your goal is.
led mike
|
|
|
|
|
Ahh, ok, I understand the difference between "immutable" and "compiler constant" now. Thank you for clearing that up, lead mike.
So what I am looking for then is a way of having a "compiler constant" integer value defined in MC++, encapsulated in a .DLL class library and then regarded by C# as a "compiler constant" and as an integer value. With a "static const" it is regarded as an integer value, and the "enum class" definition is "compiler constant".
Is this possible, or should I just give up?
Internet - the worlds biggest dictionary
|
|
|
|
|
ShermansLagoon wrote: So what I am looking for then is a way of having a "compiler constant" integer value defined in MC++
So you say, but what is the actual problem you are trying to solve. It is very likely that a different design will solve it without that requirement.
led mike
|
|
|
|
|
I have IDL files for a CORBA subset language that until recently only compiled to C++ code. Since I wanna do the client side in a nice managed language like C# the idea was to create a compiler for the IDL files that created MC++ code that is compiled into a .DLL library.
In the IDL language there are several constant values declared, which is used similar to enumerations. In the C++ compiler they are defined as "compiler constant" values, i.e. it is possible to do neat switch-case code with their values. What I am looking for is a way of creating a IDL -> MC++ -> C# way that creates values that are equally "compiler constant", i.e. switch-case friendly. As shown in my first post I have found two ways, "static const" which are immutable but not compiler constant, and "enum class" which must be explicitly casted to integer values when used.
I hope this give you a more clear way of knowing what I really need, and that you (or anyone else) knows if this can be done or not.
Internet - the worlds biggest dictionary
|
|
|
|
|
ShermansLagoon wrote: it is possible to do neat switch-case code with their values.
Yes because IDL is native to C++. You cannot use C++ compiler constants as C# complier constants nor can you use C++ enums as C# enums in a swtich statement. You could use C++/CLI (managed) enums in C# but that does not address your IDL code.
ShermansLagoon wrote: I hope this give you a more clear way of knowing what I really need
No it doesn't. All you did was restate the same proposed approach you already posted. I want to know the actual project based problem you are facing. There is an alternate design that will solve that problem (whatever it is) that will not require using constants in a switch statement.
ShermansLagoon wrote: create a compiler for the IDL files that created MC++ code
That would be a code generator not a complier, and it still does not explain what you are attempting to do with it in the C# application. As a wild guess you might need some sort of factory mechanism that would key off of the values defined in the C++/CLI module. The fact that they originate from IDL is irrelevant. It is certainly possible to accomplish this.
led mike
|
|
|
|
|
Thanks for showing an interest and trying to help me with my problem, but unfortunately I must inform you that it is not possible to do any other design, since it is in a locked system, so I will try to do a workaround for it.
Internet - the worlds biggest dictionary
|
|
|
|
|
I just recently solved this problem. The keyword in MC++ for this is "literal":
namespace Foo<br />
{<br />
public ref class RC<br />
{<br />
public:<br />
literal System::Int16 value = 0;<br />
};
Which now can be used by C# as a compiler constant value:
static class Program {<br />
static void Main()<br />
{<br />
Int16 val = 0;<br />
switch(val)<br />
{<br />
case Foo.RC.value:
MessageBox.Show("Information");<br />
break;<br />
}<br />
return 0;<br />
}
Just wanted to tell the world, if anybody else have had a similar problem and was looking for a way to solve it
Internet - the worlds biggest dictionary
|
|
|
|
|
Hi all,
I wants to use time in using visul studio 2005(c++)which is console base application.
can any body tell me how can i use time.
thanks
bankey
|
|
|
|
|
What kind of "time" do you mean? The current time (found in the System::DateTime class) or do you mean a "timer" (found in class System::Windows::Forms::Timer or System::Timers::Timer).
Internet - the worlds biggest dictionary
|
|
|
|
|
The answer you were given assumes you're using C++/CLI ( as that's where you asked ). If you wan tto use ANSI C++, you need to ask in the visual C++ forum. Or, just use google. There are at least 3 ways for time to be represented in C++, but there are MSDN pages that go over them all.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi all
I am try to use "ScheduleTimer.dll" which is uploaded by "Andy Brummer" article as ".NET Scheduled Timer".
But i am unable to exacute a function at schedule time by using this dll
if anybody have idea about this DLL or another method for executing a method at scheduled time please share with me.
thanks
bankey
|
|
|
|
|
To execute a function at a scheduled time, you just need to set a timer to check the time, and see if the time you are looking for has elapsed. If you're having trouble using the code from an article, the message board on that article is the best place to ask.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I want to run an external executable file, but i'm not sure what the command line is....help?
Woohooo! I'm a tarnard.
|
|
|
|
|
In C++/CLI ( which is where you're asking ), it's process.Start. In normal C++, on windows, it's ShellExecute ( if you wanted that, I suggest asking in the right forum in future ).
It's also clear you want C++ help, you may try making your header more meaningful. Imagine if all these psots said 'help with C++' ???
If you want a standard C++ answer, none exists. ShellExecute assumes you're programmiung for windows and have access to the Windows APIs.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
To add to Christian's reply, you may also use system calls such as system(), _exec() and _spawn(). They are C API, but not Windows specific.
Best,
Jun
|
|
|
|
|
Hi All,
I get the following compilation error:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\cstringt.h(875): error C2664: 'PtrToStringChars' : cannot convert parameter 1 from 'unsigned char *' to 'const System::String __gc *'
The code segemnt is:
#pragma once
#pragma managed
void CDailyRep::OnBnClickedNewreportsOk()
{
/*********************************************************/
CrystalDecisions::CrystalReports::Engine::ReportDocument * crReportDocument = new ReportDocument();
// ReportDocument::FileName = "BATCH.RPT" ;
// ReportDocument::FilePath = "c:\\QpayReports_CR10\\" ;
crReportDocument->Load(L"C:\\QpayReports_CR10\\Batch.RPT",OpenReportMethod::OpenReportByTempCopy);
// crReportDocument->Load(( System::String __gc*)L"c:\\QpayReports_CR10\\BATCH.RPT"); // ,OpenReportMethod::OpenReportByTempCopy);
// crReportDocument->Load("c:\\QpayReports_CR10\\BATCH.RPT"); // ,OpenReportMethod::OpenReportByTempCopy);
// crReportDocument->Load(reportDocument) ;
// char * file1 = "c:\\QpayReports_CR10\\BATCH.RPT";
// wchar_t *file1 = L"c:\\QpayReports_CR10\\BATCH.RPT";
// String* file = System::Runtime::InteropServices::Marshal.PtrToStringAnsi(file1[0]);
// String* file = Marshal::PtrToStringAnsi("c:\\QpayReports_CR10\\BATCH.RPT");
// String* file = Marshal::PtrToStringAnsi(file1);
// String *file = __gc new String(file1); // char *.
// String *file = __gc new String("c:\\QpayReports_CR10\\BATCH.RPT"); // char *.
// String *file = __gc new String("c:\\QpayReports_CR10\\BATCH.RPT"); // char *.
// String *file
// crReportDocument->Load((String *)file);
// crReportDocument->Load(__gc new String("c:\\QpayReports_CR10\\BATCH.RPT"));
// crReportDocument->Load((__wchar_t)L"c:\\QpayReports_CR10\\BATCH.RPT");
My command lin ios :
/G7 /GA /I "C:\TUXEDO\include" /I "C:\Program Files\Common Files\Crystal Decisions\2.5\managed" /AI "C:\Program Files\Common Files\Crystal Decisions\2.5\managed\en" /AI ".\Release" /D "NDEBUG" /D "_DWIN32" /D "WIN32" /D "_WINDOWS" /D "WINNT" /D "_AFXDLL" /D "_MBCS" /FD /MD /GS /J /Zc:wchar_t /Yu"stdafx.h" /Fp".\Release/Qpay.pch" /Fo".\Release/" /Fd".\Release/vc7.0.pbd" /W3 /nologo /c /Zi /clr /TP
No matter what i use, the agrument passed to PtrToStringChars is always an unsigned char *. I am at the end of my wits can any one please help?
Thanks,
Madhu
|
|
|
|
|
PtrToStringAnsi or PtrToStringChars? Where are you calling PtrToStringChars?
Mark
|
|
|
|
|
Mark,
I was able to resolve this issue.
The command line:
crReportDocument->Load(L"C:\\QpayReports_CR10\\Batch.RPT",OpenReportMethod::OpenReportByTempCopy);
The frist argument to Load wascalling thr PtrToStringChars.
Solution:
As with other MS products, Look elsewhere for the error instead of where the compiler complains.
Thx Madhu.
|
|
|
|
|
Cool 
|
|
|
|
|
hi every 1, this is my 1st post and i hope you guys can help me with my problem.
this is my problem .a quistion and i dont know how to solve it:
(Word Processing) One important function in word-processing systems is type justification—the alignment of words to
both the left and right margins of a page. This generates a professional-looking document that gives the appearance of being set in
type rather than prepared on a typewriter. Type justification can be accomplished on computer systems by inserting blank characters
between each of the words in a line so that the rightmost word aligns with the right margin.
Write a program that reads several lines of text and prints this text in type-justified format. Assume that the text is to be
printed on 8-1/2-inch-wide paper, and that one-inch margins are to be allowed on both the left and right sides of the printed page.
Assume that the computer prints 10 characters to the horizontal inch. Therefore, your program should print 6 1/2 inches of text, or
65 characters per line.
|
|
|
|