|
Edward Diener wrote: Obviously C# should allow static data, methods, properties, and events in interfaces.
Why do you think allowing static members on an interface is required?Best wishes,
Navaneeth
|
|
|
|
|
In order to code operators for an interface.
In dotNet all operators must be static methods in order to be CLS compliant.
There is no reason interfaces should not have operators just like classes do. If I have some functionality written in terms of interfaces, why should I not be allowed to use operators, where appropriate, instead of member functions ? Here is a simple, trivial example in C++/CLI:
interface class MultiplyTwoIntegers
{
int Multiply(int);
static int operator * (MultiplyTwoIntegers ^ first, MultiplyTwoIntegers ^ second) { return(first -> Multiply(second));
};
ref class MyInteger : MultiplyTwoIntegers
{
// Some functionality...
int Multiply(int other)
{
// ... some functionality return an int
}
}
int DoTheMultiplyAmongOtherThings(MultiplyTwoIntegers ^ one, MultiplyTwoIntegers ^ two)
{
int result(one * two);
// Some processing ...
return result;
}
// Somewhere else we have this code
MyInteger ^ my1(gcnew MyInteger);
MyInteger ^ my2(gcnew MyInteger);
int result(DoTheMultiplyAmongOtherThings(my1,my2));
As I said this is a trivial example but in real world programming much functionality can be created based on interfaces being passed to functionality and operating on those interfaces. Allowing operators for interfaces makes the syntax much nicer than if they are not allowed. This should be no different from classes. In C++/CLI one can code the above without error, since interface operators are allowed. In C# interface operators are not allowed, nor are any static functions, properties, or events for an interface.Edward Diener
|
|
|
|
|
Edward Diener wrote: There is no reason interfaces should not have operators just like classes do.
I agree if .NET allows operator overloads as non-static methods. Unfortunately, .NET requires operator methods to be static and having static members to be part of an interface doesn't make sense. Because interface methods are used through the instance variable and static members are not accessible through instance variable. This is the reason why .NET uses interfaces like IComparable , IEquatable etc to do operations where a operator overload could have made more sense.
Edward Diener wrote: Here is a simple, trivial example in C++/CLI:
If you don't care about your code to be used by other .NET languages, you can ensure the contract with the help of templates. Something like,
template<typename T>
int multiply(T first, T second)
{
return first * second;
} You can pass in any type that has got proper operator overloaded.
Best wishes,
Navaneeth
|
|
|
|
|
If static methods are not accesible through instance variables why do static operators work for class instances ? Your argument makes no sense because it is apparent that static operators work with class instances, so there is no reason why they should not work with interface variables instantiated from class instances. The fact that they do work with interface variables instantiated with class instances also shows that your argument is wrong BTW. Try it in C++/CLI and you will see that they do work as advertised.
The fact that C# does not allow what C++/CLI does allow does not bother me that much. I only wanted to have C# follow the CLI just as C++/CLI. Arguing that it can not work when clearly it does seems fruitless to me.
Somehow I think you are talking about C++/CLI as if it is just native C++. C++/CLI is a superset of C++ but it is not the same language. As far as using templates, I am very much aware of their capabilities but I am currently writing C++/CLI code to be used by other dotNet languages which means following the CLI standard as much as possible.Edward Diener
|
|
|
|
|
Edward Diener wrote: If static methods are not accesible through instance variables why do static operators work for class instances ?
That is a syntactic sugar. When compiler sees expression int result = first * second where first and second are instance variables of type Foo , it checks that operator overload is available and if it is available, this expression will be rewritten like int result = Foo.op_Multiply(first, second) .
If you are interested why operator overloads are static, take a look at what Eric Lippert says[^].
Edward Diener wrote: Try it in C++/CLI and you will see that they do work as advertised.
What do you mean by that?
Edward Diener wrote: Somehow I think you are talking about C++/CLI as if it is just native C++
No. I know the difference quite well.
Best wishes,
Navaneeth
|
|
|
|
|
>> Try it in C++/CLI and you will see that they do work as advertised.
> What do you mean by that?
You can currently create a static operator in C++/CLI for an interface and use it when dealing with the interface. It does not have to be only a static operator for a class to work properly. Whether it is syntactic sugar or not means nothing to me as to whether it works or not. Unlike many people I view syntactic sugar as often very important and justified.Edward Diener
|
|
|
|
|
I want to write an application, that monitors a third party application, by examining the properties and values of those properties associated with that application's controls. For example, if the control is a button, I'd like to get a list of all it's properties and their values (e.g. if the button is enabled or disabled). If the application has a grid or spreadsheet component, I'd like to get the number of columns, rows, the column headers, and the values in the individual cells. I know how to get a window/control's text with GetWindowText, however; I need much more info than that.
Can this be done? The internet searches I have done to date, (and I have searched other forums) have come up short. Can anyone give me advice/pointers or point me to resources to help me?
Thanks!Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
The only suggestion I can offer is to check the type of control when you get a handle to it, and then use the other Win32 calls to check the different styles and states it is using. This will mean checking all the options for every type of control; a fairly tedious task. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
This isn't really an answer for you, but on that other OS, system support for this kind of thing is in "Universal Access", which is a suite of tools for supporting people with disabilities. Are there similar facilities in Windows?
|
|
|
|
|
Ron Aldrich wrote: Are there similar facilities in Windows?
Not that I'm aware of. You could try searching Google to see if anyone else has come up with a solution.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
I have a class in C++ (unmanaged) which I would like to place a wrapper around in managed (visual) C++ in order to create a dll which I can use in C# applications as a class library.
I'm having quite a bit of trouble getting this to work by following MSDN's article here:
http://msdn.microsoft.com/en-us/library/aa712961%28VS.71%29.aspx[^]
and was wondering if this is even possible in VS2008? If there's a tutorial showing how to do this I'd be greatly interested in seeing it.
Thanks for any help / advice
Gvanto
|
|
|
|
|
I've done this several times. If you have a specific question, I'd be glad to do what I can to help.
|
|
|
|
|
Hi Richard,
I'm just after an example of how to do it.
Came across this: Managing the Unmanaged Code[^]
In VS2008, what project do I need to create to get started in this?
Cheers
gvanto
|
|
|
|
|
You create a new C++ project (MFC allowable) and then once it's created, go into the project properties and enable CLR support.
Now your C++ project can mix managed and unmanaged code.
|
|
|
|
|
thanks Richard with some fiddling got it working!
pretty stoked, the possibilities are now endless
|
|
|
|
|
Hi,Im using WPF as C# dll in VC++.Im sending datas to the Listbox inthe third tabitem in a tabcontrol by using this coding.
void CToolTab::SendPresetmenu(CString menu)
{
FrameworkElement^ page;
String ^ msg = gcnew String( menu );
Globals1::gwpreset->AddPresetmenu(msg);
page = Globals1::gwpreset;
Globals1::gHwndSource->RootVisual = page;
}
By this code,wat happend is my entire tabcontrol becomes a third tab item.there is not other tabs .
If i commented those last two bolded line.Full tabcotrol appears correctly but the listbox doesnot contain text.
How can i do that?Anu
|
|
|
|
|
I created a c++ .net dll, in which I need to implement logging. I decided to go with Microsoft Enterprise Library's Logging.
Now, I am calling this dll from a COM application (I created a .tlb from the dll to use in the COM application), and the error I am getting is this:
Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
How can I get around this??
TIA
|
|
|
|
|
chana gibber wrote: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
That is pretty straightforward. Is that file exist?Best wishes,
Navaneeth
|
|
|
|
|
yes, the file exists in the debug folder of my (c++) dll.
It did not get carried over to the debug folder of the COM exe.
What do I need to do with Microsoft's dll in order to get it running in my exe?
|
|
|
|
|
Have you tried copying it manually to the COM exe's folder? If it didn't worked, use dependency walker and profile the EXE to identify which dependency is actually failing. Best wishes,
Navaneeth
|
|
|
|
|
yes, I tried copying it. But remember, this is a COM exe. Does that require a tlb file instead of a dll file?
|
|
|
|
|
I got it working. I created a tlb file for each of Microsoft's dlls using regasm/tlb
|
|
|
|
|
Wow I am burning my brain right here... I'm so very close to just saying screw it and writing some sort of conversion myself.
First I'd love to know if there is an existing macro to do what I want to do...
I have a char array:
char OutputBuffer[1024] = {0}; (huge i know, but ill lower the size later )
that has a byte put into it... (78 AB 45 44) is a value I had at one time... as a float it means 790.67919921875
note!: this value has been read straight from memory
The problem is I cant get this DWORD into a float for the life of me...
Is there any existing macro? If not throw me a bone and tell me how i might convert this into a float from scratch...
|
|
|
|
|
Mattzimmerer wrote: The problem is I cant get this DWORD into a float for the life of me...
If this is already a float (as you state) then there is nothing to do. If you mean reference it as a float then you just use the (float) cast in front of the reference.
Or do I misunderstand your problem?MVP 2010 - are they mad?
|
|
|
|
|
I don't know about an existing macro, but this will do it:
char OutputBuffer[4] = { 0x78, 0xAB, 0x45, 0x44 };
float d = *((float*)&OutputBuffer[0]);
|
|
|
|