|
Yeah.. I came to know about it. I thought it will work like in standard C++. It is a syntactic sugar like C# uses using to call Dispose.
BTW, then claiming C++/CLI as the only .NET language which supports deterministic destruction is not correct, right?
|
|
|
|
|
N a v a n e e t h wrote: claiming C++/CLI as the only .NET language which supports deterministic destruction is not correct,
Correct. None of the .NET languages truly support determistic destruction. Keep in mind that when a call to Dispose is made, two things are supposed to happen (it is up to you to ensure that they actually do happen, however):
1. Any managed objects have their Dispose method called.
2. Any unmanaged resources are released.
Given that scenario you might say that .NET can be determistic when it comes to releasing unmanaged resources but not managed resources.
However, just because Dispose has been called doesn't mean the object has been deallocated on the heap. That only happens when a GC cycle runs and determines that the object is eligible for collection.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Thanks scott
|
|
|
|
|
Scott:
I had further discussion on MSDN forum on this topic. If you are interested, follow this link[^].
|
|
|
|
|
Hmmm...link appears to be down at the moment. I will check it again later.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Hello I am having real trouble with the following code.
System::Boolean vDataEvent16::IsSet::get()
{
System::Boolean data = (System::Boolean)(((* _Event) & 0x01) != false);
return data;
}
I get an invalid cast exception. How would I overcome this?
_Event is defined as a System::UInt16 ^ _Event and is passed in from C# assembly to the class constructor.
I wanted to use unions with some structs to view bits in the struct as individual properties but I could not cast the System::UInt16 to an unsigned short or rather to an unmanaged value type either.
Any suggesions
Really appreciate the response.
thanks
-Peter
|
|
|
|
|
peterdrozd wrote: I get an invalid cast exception.
In VS2008 I cannot reproduce the exception
led mike
|
|
|
|
|
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
|
|
|
|