|
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?
|
|
|
|
|
Hi, I'm completely new to C++ as a whole, so there might be a simple answer to my question, so here goes.
I'm trying to write a program that will have the screen broken up into zones, or areas, each with a Point (location) a Size, an Image, and an array of terrain types (an enum). Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this, I tried extending the PictureBox control, but this has given me even more headaches.
Basically, I can't figure out how to declare/use an array in an extended control.
#pragma once
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace cli;
namespace MapEdit
{
const int MAX_TERRAIN = 3;
public ref class Zone : public System::Windows::Forms::PictureBox
{
public:
enum Terrain
{
Plain,
Hill,
Wood,
Marsh,
Stream,
River,
ShoreLine,
Impassable
};
array<byte^> ^TerrainTypes;
int TerrainTypes[3];
...
All of my errors (except the parts where I try to use these faulty enum/ array) come from this block. Frankly, I'm at a loss as to how to fix this.
Also, if someone could tell me how to include a Bitmap in an unmanged class, that would be nice too.
Thanks,
Christian
|
|
|
|
|
poppabaggins wrote: Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this
Rather than work around by making something up yourself I would strongly suggest that you learn C++/CLI. There are excellent tutorial articles on CLI here at CodeProject. Look under the "Chapters" in the site menu.
Of course I would also strongly recommend you learn C++ first and then learn C++/CLI. I mean CLI is an extension so it seems rather obvious that one learns the root before the extension, but what do I know right?
led mike
|
|
|
|
|
|
Mark Salsbery wrote: it's pretty obvious
there's a whole new generation of "programmers" that
have completely bypassed the fundamentals.
they also seem to mostly bypass thinking. It's likely a symptom of Drag and Drop development. Vee Bee Stupid
led mike
|
|
|
|
|
Are you trying to make an array of enums?
If so, why did you try to create a byte (whatever that is)
array and an int array?
First, you can't embed a native enumeration in a ref class.
Second, once you have a managed enum class, you can create an
array that stores the enum type...
enum class Terrain
{
Plain,
Hill,
Wood,
Marsh,
Stream,
River,
ShoreLine,
Impassable
};
array<Terrain> ^TerrainTypes;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks, I was trying to come up with some sort of sensible code from searching the internet, but nothing seemed to work for me. Basically, I'm working off of what little I know from C# and the small amount of information I can get from my professor after class. It obviously wasn't working well for me.
This is part of a project for school, but my book has absolutely nothing on managed c++. I would take the time to learn C++/cli, but this project is due at the end of the semester, and I have so many other things I'm reading now for classes/personal study/entertainment. I'll get to it eventually, but I have a lot of other things I'm doing now.
|
|
|
|
|
hello,
I am writing an extension to Ms Outlook and I came across this problem. In this extension I'm adding some buttons to Outlook's toolbar and my goal is to display their tooltip texts in Unicode encoding. The problem is that by default it is displayed in ANSI encoding and I have no idea how to change it.
STDMETHODIMP MyExchExtCommands::QueryHelpText(UINT cmdid, ULONG ulFlags,
LPTSTR psz, UINT cch)
{
HRESULT hr = S_FALSE;
if (cmdid == MyCmdid)
{
if (ulFlags == EECQHT_STATUS)
lstrcpyn(psz, "Some status text", cch);
if (ulFlags == EECQHT_TOOLTIP)
lstrcpyn(psz, "Some tooltip text", cch);
hr = S_OK;
}
return hr;
}
In the above piece of code MyExchExtCommands ofcourse inherits from the IExchExtCommands interface and psz is a pointer to buffer to be populated with text to display. And no matter what I pass in that buffer, the text is always displayed in ANSI. Maybe I'm looking in the wrong place? Any help would be appreaciated.
Regards,
pawel
|
|
|
|