|
if anyone is interested, i found the reason for this behaviour.
the local translation are all placed in satellite assemblies (.resx) files, and in a compiled version they are expected to be in subfolders of the working directory.
e.g. the translations for the de-DE Culture should be in ./de-DE/<assembly.dll>
Somehow the Setup Routine didnt include those assemblies and therefore the program could not find em and did fall back to its default language.
cheers
|
|
|
|
|
So it had nothing to do with C++/CLI. Glad you got it working and thanks for posting back the outcome.
led mike
|
|
|
|
|
Hi All,
I encoutered an issue in my program that uses .net serial port component. The scenario is as below:
1. I have developed my program and it works fine in "debug mode".
2. When I compile and run it in "Release mode", something wrong happened to the program. Some of my program logic
is no longer working as in "debug mode".
3. After performing some debug, I found out that the problem is I am using a while loop (pooling) on a flag
'AckReceived', and the flag is in an inconsistent state in 'release mode'.
Brief description on my serial port program design,
1. Main thread send a packet of serial data through serial port to external device, and expect an acknowledgement
within an interval, or else timeout will occur.
2. After sending data, main thread will perform a while loop to pool the 'AckReceived' flag. If it is true or
timeout occur, jump out from while loop.
3. When data is received at serial port, my receive event handler (port_DataReceived) will be fired to process the
serial data. The delegation is assigned as below:
objSerialPort->DataReceived+= gcnew SerialDataReceivedEventHandler(this,&CSerialPort_Driver::port_DataReceived);
4. When complete parsing the data, if a full serial packet is received and verified ok, 'ACKReceived' flag will be
set to true.
**Remark: Parsing and setting the flag 'AckReceived' is all done in the event handler port_DataReceived.
5. When 'AckReceived' flag is set to true, my main thread will jump out from while loop and continue the remaining
logic.
Problem:
1. In 'release mode', even though serial packet has been received successfully, and the 'AckReceived' flag is set
to true, the WHILE loop in main thread will NEVER jump out until timeout. This means, in main thread, it always
see the 'AckReceived' flag as false.
2. The logic works fine in 'DEBUG mode'.
3. My temporary solution is to put a System::Threading::Thread::Sleep(5) in the WHILE loop to keep the WHILE loop
checking at lower frequency, and this make the 'release mode' works!!
Obviously, the temporary solution is not a perfect one, but it does give some clue that timing is a problem in
'Debug' & 'Release' mode.
However, I couldn't figure out what is the exact problem and debugging in 'relese mode' is very hard and I am
helpless now. I am new in .NET development and not really sure on the threading model of .NET serial port, hence
not really sure if this issue is caused by syncronization problem of the 'AckReceived' flag?
Please can anyone explain to me what happen here and if possible share with me some possible solution?
Thanks in advance!
Development environment:
1. Language: Managed C++
2. IDE: Visual Studio.NET 2005
3. Serial port component: Version 2.0.0.0
Best Regards,
Winson My
|
|
|
|
|
Debugging in release mode is easy, just make sure you get the compiler to produce the debug symbols (you can do this for release builds) and then debug as normal.
regards,
|
|
|
|
|
|
Hi Everyone,
I am working on a project on VC++ 2008. It requires to generate reports based on predefined templates.
I found lot of information on how to attain this thru c#, but am not able to find out easy ways to do this in VC++ using .Net framework.
Any suggestion will be a great help to my project.
Thanks everyone,
Kasi
|
|
|
|
|
krish99 wrote: Any suggestion will be a great help to my project.
Try asking a specific question.
“Cannot find REALITY.SYS...Universe Halted.”
~ God on phone with Microsoft Customer Support
|
|
|
|
|
Hi,
Is it possible to do type casting implicitly, i.e. when making assignments, in managed c++.
In unmanged code it seemed good enough to overload the type cast operators for this to happen but it appears that this is not the case in managed c++.
I know that c# has an implicit keyword, is there an equivalent for c++?
Basically I want like to make an assignment from a number contained in my class to an int, bool or double without explicitly declaring this conversion.
Hope you can help out,
m.
|
|
|
|
|
mike toon wrote: In unmanged code it seemed good enough to overload the type cast operators for this to happen but it appears that this is not the case in managed c++.
Do you have an example where this isn't the case?
This still works in C++/CLI:
ref class numericstring
{
String ^str;
public:
numericstring()
{
str = gcnew String("123.456");
}
operator bool() {return Convert::ToDouble(str) != 0;}
operator int() {return Convert::ToInt32(Convert::ToDouble(str));}
operator double() {return Convert::ToDouble(str);}
};
[STAThreadAttribute]
int _tmain()
{
numericstring ns;
bool nsbool = ns;
int nsint = ns;
double nsdouble = ns;
...
This form works as well
ref class numericstring
{
String ^str;
public:
numericstring()
{
str = gcnew String("123.456");
}
static operator bool(numericstring^ val) {return Convert::ToDouble(val->str) != 0;}
static operator int(numericstring^ val) {return Convert::ToInt32(Convert::ToDouble(val->str));}
static operator double(numericstring^ val) {return Convert::ToDouble(val->str);}
};
[STAThreadAttribute]
int _tmain()
{
numericstring ^ns = gcnew numericstring();
bool nsbool = ns;
int nsint = ns;
double nsdouble = ns;
...
In both versions above, implicit is implied, but you can add the explicit
keyword to force explicit conversion semantics (which in the above examples
would be a good idea )...
ref class numericstring
{
String ^str;
public:
numericstring()
{
str = gcnew String("123.456");
}
static explicit operator bool(numericstring^val) {return Convert::ToDouble(val->str) != 0;}
static explicit operator int(numericstring^val) {return Convert::ToInt32(Convert::ToDouble(val->str));}
static explicit operator double(numericstring^val) {return Convert::ToDouble(val->str);}
};
[STAThreadAttribute]
int _tmain()
{
numericstring ^ns = gcnew numericstring();
bool nsbool = (bool)ns;
int nsint = (int)ns;
double nsdouble = (double)ns;
...
See Changes to Conversion Operators[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi thanks for the help. The problem making assignments after the initial declaration.
e.g.
double nsdouble = ns;
nsdouble = ns; //complition error here.
Error 1 error C2678: binary '=' : no operator found which takes a left-hand operand of type 'double' (or there is no acceptable conversion)
I tried to strip down my code into a new class ( to post ) and lo and behold it compiled and operated as should be.
So i'm baffled where the problem might be.
modified on Wednesday, October 29, 2008 7:45 AM
|
|
|
|
|
mike toon wrote: i'm baffled where the problem might be.
Me too.
There's no reason that shouldn't compile, and it compiles fine
in both examples I gave.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yeah. Sorry i didn't communicate that well. Your code works and compiles fine.
I think i've figured out the problem, but not entirely sure why it occurs.
In addition to the cast overloads i also have an assignment overlaod which uses a template.
If i remove this template then it compiles fine, however with the template it causes the said error.
using namespace System;
ref class Value
{
public:
enum struct ValType
{
Empty,
Bool,
Double,
Integer
};
Value();
Value^ operator=( Value^ rhs );
Value( bool value );
Value( double value );
Value^ operator=( double doubVal );
Value^ operator=( bool boolVal );
template<typename t="">
Value^ operator=( T value )
{
m_type = ValType::Integer;
m_value = static_cast<int>( value );
return this;
}
operator double( );
operator bool( );
private:
Object^ m_value;
ValType m_type;
};</int></typename>
Any ideas why this compilation error occurs?
Many thanks,
mike.
|
|
|
|
|
Just found out that you can't overload the type cast () in .net which has made this attempt rather pointless. I had been compiling a dll library in managed c++ which was to be used by c# code. Any clues as how I can provide the functionality to do the type casting implicitly with .net?
thanks,
Mike
|
|
|
|
|
mike toon wrote: Any clues as how I can provide the functionality to do the type casting implicitly with .net?
Sure. Use implicit[^]
led mike
|
|
|
|
|
mike toon wrote: I had been compiling a dll library in managed c++ which was to be used by c# code.
In that case you should be using the second version of my sample -
the managed version (as also shown in led mike's link).
Like I mentioned, the operators in that form are implicit unless explicitly set
explicit with the keyword explicit.
using namespace System;
namespace TestCPlusPlusClassLibrary
{
public ref class numericstring
{
String ^str;
public:
numericstring()
{
str = gcnew String("123.456");
}
static explicit operator bool(numericstring^ val) {return Convert::ToDouble(val->str) != 0;}
static explicit operator int(numericstring^ val) {return Convert::ToInt32(Convert::ToDouble(val->str));}
static explicit operator double(numericstring^ val) {return Convert::ToDouble(val->str);}
};
}
...
TestCPlusPlusClassLibrary.numericstring ns = new TestCPlusPlusClassLibrary.numericstring();
bool nsbool = ns;
int nsint = ns;
double nsdouble = ns;
...
Note how WITH the "explicit" keyword in the example above, the C# will not compile.
Without the "explicit" keyword, it compiles and runs fine.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
modified on Thursday, October 30, 2008 3:20 PM
|
|
|
|
|
Thanks to both of you for the help, this works fine now.
Is it possible to over-ride the '=' operator as well, can this be declared as a static function in the same way?
I get this error if i try this:
error C2581: static 'operator =' function is illegal
According to msdn '=' operators cannot be static.
Oops, answer was already contained in that blog article
Cheers again.
|
|
|
|
|
Write a program management personnel of 1 companies with functions:
Get a 1 staff to the company.
Delete 1 employees.
Search for employees under the code staff.
Print a list of employees in the company.
End the program.
(Required at this leading export and use inheritance.)
Hope you help me! I'm very urgent.
Thanks!
|
|
|
|
|
qt_oct wrote: very urgent
You better get working then, rather than wait for someone to do it for you.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
AND cross-poster.
Blog link to be reinstated at a later date.
|
|
|
|
|
Hi ya
I'm working on a native C++ Client/Server application, where the Client is implemented using MFC. The Client and Server shares a common DataModel-library.
I want to perform a incremental conversion of the MFC Client to a .NET implementation. The code-base is rather large (and obscure), so turning on /clr for the entire Client-project is not a good option.
Is it possible to create a new ManagedClient-library, which the original Client-project can link with. Then slowly move the views and controls from the original Client-Project to the ManagedClient-library while converting them to managed c++/c#. So the main Client-project will continue to be unmanaged but will link to a managed library.
At the same time the ManagedClient-library will probably need to access classes in the DataModel-library. Is it possible to create a ManagedDataModel-library which contains managed wrappers around the native DataModel-library.
Is there a better way for incrementally converting an existing MFC application ? And are there any obvious pitfalls I should be aware of ?
Best regards
-Rolf
|
|
|
|
|
Yes. You can maintain your old MFC client application while calling into new managed DLLs. In fact, this is an article I've wanted to write for awhile.
Any file which will be calling into a C# DLL will need to have the following options set in its Properties dialog:
* C/C++/General - Compile with common language runtime (/clr)
* C/C++/General - Debug Information Format - Program Database (/Zi)
* C/C++/Code Generation - Basic Runtime Checks - Default (others may work too)
* C/C++/Code Generation - Enable Minimal Rebuild - No
* C/C++/Code Generation - Enable C++ Exceptions - Yes With SEH Exceptions (/EHa)
* C/C++/Precompiled Headers - Create/Use Precompiled Header - Not Using Precompiled Headers
Add the following near the top of your file (after #include's)
* #pragma managed
* using namespace System::Windows::Forms;
* using namespace MyManagedDLL;
...and any other namespaces you may want to add. This just makes coding easier so you won't always need to prepend your classes with the fully qualified name.
Right click on your project and select References. Add the following references.
* mscorlib
* System
* System.Windows.Forms
* Your special C# DLL
Depending on your code, you may need to add more References. You will receive compilation errors if anything is missing.
The above will allow you to call a managed DLL from your client MFC application. There might be one thing I left off. I've had others do this same thing and I recall one time someone mentioning they had to add another reference I missed.
Going from managed to non-managed is a different story. One option is to use P/Invoke, but that is really best used for calling 'c' functions, not for C++. There is quite a lot written in regards to P/Invoke on this site.
http://www.codeproject.com/KB/miscctrl/HostMFC.aspx[^]
I haven't yet used it, but plan to look more into this for work when I have more time. This is a project explaining how to host your MFC application from within a .NET App Framework. It looks very interesting.
I have not really had any pitfalls, but there are some things to be aware of. You will need to write code to convert between your C++ data types/classes and the managed data class. You will need to write this code in C++ using CLI.
|
|
|
|
|
I was actually planning to link with a static library compiled with /CLR (Giving access to .NET), while the old MFC project remains untouched. Is this not possible ?
Found this article that seems to answer some of my technical questions Mixed (Native and Managed) Assemblies
modified on Tuesday, October 28, 2008 11:50 AM
|
|
|
|
|
I've got friend suggesting me to convert cons char* variable to char* by copying the data. I mean using: char *x = strdup(const char *y).
But I think I can easily typecasting it, like this: x = (char *) y.
Am I doing a good coding practice here because I prefer typecasting it I don't even get warning for doing this.
Any way are they the same? Which one should be a good programmer do?
THX!!!!
From Indonesia with love..!!
|
|
|
|
|
auralius wrote: Am I doing a good coding practice here
No. Casting away const is bad. Without the const it implies
the location is writable, which it is not, otherwise it wouldn't
be const
You'd only need a strdup() duplicate of the string if you're going to
alter its contents.
Static casting is rarely necessary so I always consider it bad practice.
Casts are not for fixing compiler errors and warnings!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Casting is always "dangerous", so think what you do. It is really often the course of strange bugs and problems, which appear months or years after writing the crap. (believe me)
Types are your helpers, if it is a const think why!!! Why isnt char* x const?
x = (char *) y : the same string to which are pointing two pointers.
In your case with strdup you got another string !!!
(you must understand that, or stop coding )
PS: I compile my Release builds always with warning level 4
Greetings from Germany
|
|
|
|