|
PS.
All this (except how to store or manage class identifier *properties*) may be moot however, if the Activator class provides the needed services.
|
|
|
|
|
mmontagne wrote: But again, thanks for the starting point (which may be much more than that).
You're very welcome. Have you thought about combining the code above with a template to hide the cast and present a nice interface to users of your code?
|
|
|
|
|
Good suggestion. I'm not sure the Activator needs to be handled that way, but in either case, if there is an opportunity to build a generic/template, that is certainly how to approach this.
Where we are really stuck for the moment (we're new to VS) is component development references. We have a book on order, but have some steep issues which require that we know much more about classes and how their properties are registered/supported in the IDE than we're finding bundled/linked documentation for. Any suggestions for top quality references appreciated. The book we're looking at is "Programming .NET Components, 2nd Edition," by Juval Lowy. It's C# oriented, but we're hoping that the approaches/examples will be conducive to managed C++, if that will be preferrable for us. Otherwise, we'll have to look at doing these projects in C#. For the moment (until this book gets here and we have it under our belt), things are on hold.
Actually, we're doing a final release build in Delphi as we get ready for a serious VS push.
|
|
|
|
|
mike montagne wrote: Otherwise, we'll have to look at doing these projects in C#.
I dont see a huge advantage in managed c++ over c#. We have a lot of unmanaged c++ code that we would like to use from c# clients so I have been investigating using managed c++ to make wrapper classes for our existing libraries. It looks like we're going to go down this path and my next big challenge is to see how much of this we can generate.
Unless you think you can reuse a lot of the code from your Delhpi perhaps c# would be a good option.
I dont have any specific book recomendations. I would look for something that addresses the run time more than a particular language.
|
|
|
|
|
Thanks much for the advice. We're trying to weigh all this with an open mind. One thing we have been interested in (for our own style of doing things) is being able to run native code. That's a C++ thing. But if we can run C# components in native C++ implementations, the broad acceptance of C# as a more expedient tool has major influence on our own disposition. I suppose this book is going to be a hinge point.
|
|
|
|
|
I have a class that implements System::Collections::Generic::IEnumerable<> interface. System::Collections::Generic::IEnumerable<> is derived from System::Collections::IEnumerable and both have a pure virtual method called GetEnumerator() but with different return types.
To over come the "overloaded function differs only by return type" error I used an 'explicit override' as described in the documentation. The code looks like this....
virtual System::Collections::Generic::IEnumerator<OptiverAu::VaultDotNet::TradeDelta^>^ GetEnumerator()
{
//to be implemented
return nullptr;
}
//note the '= blah blah' (this is the expicit override)
virtual System::Collections::IEnumerator ^ GetEnumeratorNG() sealed = System::Collections::IEnumerable::GetEnumerator
{
return GetEnumerator();
}
Seems a wierd way of doing things but it works. Now I want to write a class that implements the System::Collections::Generic::IEnumerator<> generic interface to be returned from the GetEnumerator() function above
System::Collections::Generic::IEnumerator is derived from System::Collections::IEnumerator in the same way as the example above. Both have a 'pure virtual' property called Current but with different return types.
What is the syntax for an explicit override of a property? I have spent an entire day searching and cant find the answer anywhere.
|
|
|
|
|
You override the get and set and not the property itself
interface class IFoo
{
property int Count
{
int get();
void set(int);
}
};
ref class Foo : IFoo
{
public:
Foo() : m_count(1) {}
property int Size
{
virtual int get() = IFoo::Count::get
{
return m_count;
}
virtual void set(int value) = IFoo::Count::set
{
m_count = value;
}
}
private:
int m_count;
};
|
|
|
|
|
Thanks you VERY much. I tried just about every combination except renaming the property and putting the expicit override on the get() & set().
|
|
|
|
|
Hello,
How to call CoGetInterfaceAndReleaseStream(…) in a secondary thread in managed VC++.NET 2003 application? I can successfully call CoMarshalInterThreadInterfaceInStream(…) in the main thread. After that in the secondary thread I call CoInitialize(NULL) with S_OK result, but CoGetInterfaceAndReleaseStream(…) returns -2147352568 error code.
Please help!!!!!!!!
Regards,
Leonid
|
|
|
|
|
Hi friends,
Can anyone tell me what will be the output of the folloing code and whats the reason for that.
It will be a great help.
<br />
int x = 12;<br />
int y = 6;<br />
x = x++ + y++<br />
cout<<x<<endl<<y;<br />
can you tell me the output for C++ and Java compiler and whats the reason for the answer.
Thanks in Advance
Sushant Duggal.
|
|
|
|
|
Sushant Duggal wrote: can you tell me the output for C++ and Java compiler and whats the reason for the answer.
Yes I can... but then I would be doing your class assignment for you.
led mike
|
|
|
|
|
Sushant Duggal wrote: cout<<x<<endl<<y;< blockquote="">
This code is making some assumptions that are now being shown for it to compile as C++. It's not going to compile for Java.
Beyond that, I agree with the other reply, you need to do your own homework.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for your reply friends,
But I just want to know the reason why the outputs differ.
i
In C++, The result is x=18.y=7
where as in Java, The result is x=19, and y=7
I want to know the reason for this output.
Is there a difference of stack implementation in the two languages or there is some other reason..
Please let me know.
Thanks,
Sushant Duggal.
|
|
|
|
|
++x guarentees that the number is incremented before it's returned. x++ guarentees it's incremented after, but not how LONG after.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yes, I agree on your comment.
so do you want to say that there is no method to determine the value?
Sushant Duggal.
|
|
|
|
|
OK
now i got the point.
its correct to get 19 in C++,
but I still didnt understand why it comes 18 in java.
Can you comment on this?
Thanks
Sushant Duggal.
|
|
|
|
|
I believe it goes like this:
The ++ operator occurs in both languages AFTER x is given it's final value. The difference is that in Java, the values are by reference, so the value that x is assigned to, is the value that still has a ++ operator outstanding. so, x gets set to 18. y gets incremented, to 7, and x also gets incremented, but it's the same x that is 18, not a copy of x which is 16.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Oh - you also posted in the wrong forum, I didn't notice before.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Then where I would have posted this?
Sushant Duggal.
|
|
|
|
|
Managed C++/CLI is the forum for discussion of .NET C++, as it clearly states. This[^] is the general C++ forum.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The ++ operator occurs in both languages AFTER x is given it's final <BR>value. The difference is that in Java, the values are by reference, so <BR>the value that x is assigned to, is the value that still has a ++ operator outstanding. so, x gets set to 18. y gets incremented, to 7,<BR> and x also gets incremented, but it's the same x that is 18, not a <BR>copy of x which is 16.
I can understand that in java, the values are by reference. that means X is incremented direectly where it is stored, it sets it to 12 + 6 = 18.
Confusion ..... when the X is going to incremented? and why it is not reflected(X's value is still 18).
Thanks For your Patience,
Sushant Duggal.
-- modified at 3:39 Thursday 28th September, 2006
Sushant Duggal.
|
|
|
|
|
The statement i = i++ has undefined behavior in C++ and different compilers can generate different code and still be standards compliant. The = operator does not define a separate sequence point, and C/C++ rules dictate that an expression can modify an object's value only once within a single sequence point - else the compiler's free to interpret the code in whatever way it wants to.
|
|
|
|
|
Hi All,
I was trying to explore the working of double Linklist in MFC using CList.
I have created a struct such as
struct XXXX{
char buff[10];
char buff1[10];
}YYY;
then
CList <YYY,YYY&>my_list;
my_list.AddHead();
This is working fine . But my problem is when i want do ...
struct zzzz{
char buff[10];
char buff1[10];
}PPP;
struct XXXX{
CList<PPP,PPP&>my_second_Struct;
char buff[10];
char buff1[10];
}YYY;
Is it help me to achive my goal. If Not please help me
Regards &Thanks
Neeraj Kumar Jha
|
|
|
|
|
My overall advice is that you'd do better to learn to use the stl::list instead of the MFC one. Either way, which ever you use, it's not a managed C++ construct, so you're in the wrong forum.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hey...........
i managed to compile and run a C++ program that intializes and reads/writes to a serial port . I was using the Dev C++ compiler to write the code.
Now I am trying to verify the output.What I did was to write the letter 'a' to the serial port. The serial port is connected to a digital oscilloscope and I intend to see the voltage patterns that correspond to the letter 'a' as below.
11 01000001 0 = stop bits / data bits / start bit
But this voltage pattern is not shown in the oscilloscope. Instead I only see the handshaking signal (a data bit '1') coming from the serial port.( I was able to see the handshaking control signal/initializing signal but not the data signal (the data signal was the letter 'a') ).
I saw a '1' from pin 3 and pin 6 of the R232 serial port when I ran the program. These pins correspond to Transmit data, Data set ready signals that are sent from the laptop to the oscilloscope.
1. I cannot see any data signals corresponding to the letter 'a'. What is the reason behind this????
Is it because there is no reply from the oscilloscope for the handshaking signal the laptop sends to it?? (i am using a laptop to run the program)
(Meaning the oscilloscope fails to send a handshking signal back to the laptop......this might indeed be the case because oscilloscopes are not built to send handshking signals)
2.If so how can I bypass sending handshking signals and simply send the letter 'a' to the oscilloscope and view its voltage pattern???
3.Can I do this by a simple adjustemnt to the code I have written below????
I would greatly appreciate any help u guys can give....
the code is below (compiles without errors on Dev C++ )
Serial.h
CODE
CODE// Flow control flags
#define FC_DTRDSR 0x01
#define FC_RTSCTS 0x02
#define FC_XONXOFF 0x04
// ascii definitions
#include <stdio.h>
#include <time.h>
//#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <string.h>
#define ASCII_BEL 0x07
#define ASCII_BS 0x08
#define ASCII_LF 0x0A
#define ASCII_CR 0x0D
#define ASCII_XON 0x11
#define ASCII_XOFF 0x13
HANDLE SerialInit(char*, int);
char SerialGetc(HANDLE*);
void SerialPutc(HANDLE*, char);
--------------------------------------------------------------------------
Serial.cpp
CODE
CODE
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <string.h>
#include "serial.h"
// Flow control flags
#define FC_DTRDSR 0x01
#define FC_RTSCTS 0x02
#define FC_XONXOFF 0x04
// ascii definitions
#define ASCII_BEL 0x07
#define ASCII_BS 0x08
#define ASCII_LF 0x0A
#define ASCII_CR 0x0D
#define ASCII_XON 0x11
#define ASCII_XOFF 0x13
using namespace std;
// variables used with the com port
BOOL bPortReady;
DCB dcb;
COMMTIMEOUTS CommTimeouts;
BOOL bWriteRC;
BOOL bReadRC;
DWORD iBytesWritten;
DWORD iBytesRead;
HANDLE SerialInit(char *ComPortName, int BaudRate)
{
HANDLE hCom;
hCom = CreateFile(ComPortName,
GENERIC_READ | GENERIC_WRITE,
0, // exclusive access
NULL, // no security
OPEN_EXISTING,
0, // no overlapped I/O
NULL); // null template
bPortReady = SetupComm(hCom, 2, 128); // set buffer sizes
bPortReady = GetCommState(hCom, &dcb);
dcb.BaudRate = BaudRate;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
// dcb.Parity = EVENPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.fAbortOnError = TRUE;
// set XON/XOFF
dcb.fOutX = FALSE; // XON/XOFF off for transmit
dcb.fInX = FALSE; // XON/XOFF off for receive
// set RTSCTS
dcb.fOutxCtsFlow = TRUE; // turn on CTS flow control
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; //
// set DSRDTR
dcb.fOutxDsrFlow = FALSE; // turn on DSR flow control
dcb.fDtrControl = DTR_CONTROL_ENABLE; //
// dcb.fDtrControl = DTR_CONTROL_DISABLE; //
// dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; //
bPortReady = SetCommState(hCom, &dcb);
// Communication timeouts are optional
bPortReady = GetCommTimeouts (hCom, &CommTimeouts);
CommTimeouts.ReadIntervalTimeout = 5000;
CommTimeouts.ReadTotalTimeoutConstant = 5000;
CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
CommTimeouts.WriteTotalTimeoutConstant = 5000;
CommTimeouts.WriteTotalTimeoutMultiplier = 1000;
bPortReady = SetCommTimeouts (hCom, &CommTimeouts);
return hCom;
}
char SerialGetc(HANDLE *hCom)
{
char rxchar;
BOOL bReadRC;
static DWORD iBytesRead;
bReadRC = ReadFile(*hCom, &rxchar, 1, &iBytesRead, NULL);
return rxchar;
}
void SerialPutc(HANDLE *hCom, char txchar)
{
BOOL bWriteRC;
static DWORD iBytesWritten;
bWriteRC = WriteFile(*hCom, &txchar, 1, &iBytesWritten,NULL);
return;
}
int main()
{
HANDLE my=SerialInit("com1",1200);
char letter;
HANDLE *ptr;
*ptr=my;
SerialPutc(ptr,'a');
//letter=SerialGetc(ptr);
getch();
return 0;
}
hi
|
|
|
|