|
peterdrozd wrote: != false
You're comparing a UInt16 with false.
That should be != 0
System::Boolean vDataEvent16::IsSet::get()
{
return (((*_Event) & 0x01) != 0);
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Did you reproduce the exception? Using what version of C++?
led mike
|
|
|
|
|
led mike wrote: Did you reproduce the exception?
No sir (VS 2008 SP1).
I don't know what's up with that - not enough info for me.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I don't know what's up with that - not enough info for me.
Yeah I know, I plugged this in and ran it just fine
System::Boolean data = (System::Boolean)(((* _Event) & 0x01) != false);
led mike
|
|
|
|
|
I did this:
UInt16 ^ _Event = gcnew UInt16(4);
Boolean boolean = (((*_Event) & 0x01) != false);
*shrug*
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I did this:
and it didn't throw any exception right?
led mike
|
|
|
|
|
Correctamundo!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I tried it and it does not work.
It may be that I separated the class to a header file from the implemenation.
System::Boolean DataEvent16::IsActive::get()
{
System::Boolean data = (System::Boolean)(((* _Event) & 0x02) != 0); <--fails here.
return data;
}
header file
property System::Boolean IsActive
{
System::Boolean get();
}
this still fails.
I am trying to get bits from an unsigned short and pass back to C# the value of the bits. I tried a union with a structure to define the bits and tried to set a variable that had all the bits as a System::UInt16 but it would not let me assign the * (System::Uint16 ^ ) to the unmanaged data type so I had to switch gears and try this method. doing a return when the class is implemented inline works fine however I can not use the class in another CPP file as a class variable because I could not make one class aware of the other with out a header. so I separated them. this led to problems with visual studio 2005 C++ CLI
This should be a simple item but it's starting to take up so much time.
thanks -- Pete
modified on Thursday, September 11, 2008 11:34 AM
|
|
|
|
|
led mike and I can't reproduce the error.
Here's how I tested:
UInt16 ^_Event = gcnew UInt16(4);
Boolean boolean = (((*_Event) & 0x01) != false);
You don't need the (System::Boolean) cast. The != operator
already returns a boolean.
The only thing I can think of based on the code you've shown
is _Event isn't really a UInt16 ^.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
here is part of the header file.
public ref class DataEvent16
{
private:
System::UInt16 ^ _Event;
public:
DataEvent16(System::UInt16 ^ Event);
DataEvent16();
property System::UInt16 RawData
{
System::UInt16 get();
void set ( System::UInt16 value);
}
property System::UInt16 IsSet
{
System::UInt16 get();
}
property System::Boolean IsActive
{
System::Boolean get();
}
};
Implementation file
DataEvent16::vDataEvent16(System::UInt16 ^ Event)
{
_Event = Event;
}
DataEvent16::vDataEvent16()
{
_Event = gcnew System::UInt16(0);
}
System::Boolean vDataEvent16::IsActive::get()
{
System::Boolean data = (System::Boolean)(((* _Event) & 0x02) != 0);
return data;
}
this will compile but explode. on the boolean statement. I know it seems like overkill but I have tried several iterations.
|
|
|
|
|
I had to remove the 'v's (vDataEvent16, vDataEvent16)
to get your code to compile, but it worked fine in VS 2008.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
BTW thanks for providing code to test with
What does the calling code look like?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
fixed it.
I had to remove all references for that data. The problem was that I have some arguments that have to be passed as references. I have others that have to be passed as value types. the _Event is a value type. I was passing it in as a reference so in that function, I was referencing the pointer I think. So it would compile but the value was probably greater than max value.
I guess this all came about because I have become accustomed to coding inline classes and not removing the class definition from the implementation. there are not too many good examples online that I found on how to do it right.
thanks everyone for your help.
-Peter
|
|
|
|
|
That's what I figured - I just wasn't sure why the C# side
didn't complain about a mismatched argument.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Are you sure the C# side is providing a System::Uint16 ^
and not just a System::Uint16?
A System::Uint16 ^ (reference to a value type) is kind of
unconventional...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi @all,
I´m new at Code Project so I hope this is the right place for my question!
I´m a little bit in trouble with C++-Namespaces. I´ve 3 files like
example.cpp
#include <iostream>
#include "include/base/try.h"
int main (int argc, char** argv)
{
peng::print2(argc, argv);
return 0;
}</iostream>
try.h
#ifndef __TRY_H
#define __TRY_H
namespace peng
{
void print2(int& argc, char**& argv);
}
try.cpp
#include "try.h"
void peng::print2(int& argc, char**& argv)
{
std::cout<<"hurra"<<std::endl;
}
But I run in the linker-error:
example0.5.cpp:(.text+0x136): undefined reference to 'peng::print2(int&, char**&)'
collect2: ld returned 1 exit status
And I don´t know why! I´m using MinGW Version 5.4.1. an GVim!
Do I have to change some linker-settings?
When I initialize print2() in try.h like
namespace peng
{
void print2(int& argc, char**& argv)
{
std::cout<<"huraa"<<std::endl;
}
}
it works!
I need some help
Greetz Stefan
modified on Thursday, September 11, 2008 7:35 AM
|
|
|
|
|
how do you compile?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
via Windows-Terminal: g++ -o example.exe example.cpp
|
|
|
|
|
you're compiling example.cpp but not try.cpp
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
aaah your right!! thanks a lot!
How can I run example.exe with try.cpp and example.cpp?
|
|
|
|
|
g++ -o example.exe example.cpp try.cpp
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I am using Visual c++ NET 2005
How can I do so that My output be written in CVS File
|
|
|
|
|
CVS or CSV?. If it's a CSV, you only need to enter a comma where you finish writing your current string and start with a new one
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
It is CSV Please; How to do it from Visual c++ NET
|
|
|
|
|
I am using a computer that has not been installed VC++6.0. So, what files should I copy to my computer in order to compile successful a project without installing VC++6.0?
|
|
|
|