|
Dear Members,
I need to color a button using ATL, WTL or WIN 32 API..
I can easily do it using MFC but because of the Application requirement
I have to do it by using the above mentioned technologies only.
Kindly help me out by sending tips and useful codes.
Regards,
Mayank Srivastava
|
|
|
|
|
you are on the managed C++ forum, which .NET related. what you need (ATL, WTL, MFC, Win32) is all except MC++.
try the ATL/WTL/STL forum[^]...
ps: asking your question once is sufficient...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
-- modified at 9:41 Wednesday 14th December, 2005
|
|
|
|
|
thanks a lots,
My meaning is web service client how to access web service endpoint?
|
|
|
|
|
If I have a dll created by Managed C++ and receiving array. How do I pass the array from application in C# to the generated DLL?
Any help is appreciated.
|
|
|
|
|
C++/CLI
public: void MyClass::myDllFunction(cli::array<String^>^ stringList)
{
...
}
C#
using MyClass;
string[] list = new string[]{"one", "two", "three"};
myClassInstance.myDllFunction(list);
-- modified at 16:05 Tuesday 13th December, 2005
|
|
|
|
|
Thanks a lot. So it is pretty natural on both sides.
|
|
|
|
|
Hi All,
This might be a really silly question but,...
I have a class A defined as:
<br />
class A<br />
{<br />
protected:<br />
float data[4][4];<br />
};<br />
And I need to get the data out so I created a function:
float **GetData (void) { return (float **) data }
However this causes an 3f800000 exception in VS 2005 Express when I try to use the float returned. Do I need to physically copy the data into a tempory buffer?
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
is the array well initialized (in the constructor tor instance)
before using it, test if it is different from NULL .
and at last, if your class exist only for such things, prefer using a struct instead...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20] | soon : [VisualCalc 3.0]
|
|
|
|
|
Hi,
The array is initialised to have all elements 0. It is not pointer, so it is not dynamically allocated, and it is not a NULL pointer exception. Also I need to overload the arithmetic operators so the best is to use a class. There are also other data members not meantioned here.
BTW, I tried this in normal code (i.e. in the main function) calling another function that took a float ** and it did the same thing.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
toxcct wrote: and at last, if your class exist only for such things, prefer using a struct instead...
Just curious - why ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The problem is probably elsewhere because it looks correct. Did you try to use the debugger and see where EXACTLY the code crashes ? (Press F5 to start the debugger and F9 to set or remove breakpoints).
|
|
|
|
|
Cedric, how can you be so sure that his code is correct ?
nowhere he says that he initialized the array, so if he doesn't test for a NULL pointer, i may use a wrong array !!!
moreover :
float **GetData (void) { return (float **) data }
is missing a ; after the return statement...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20] | soon : [VisualCalc 3.0]
|
|
|
|
|
Hi,
You are right, there should be a ';'. I didn't copy it exactly as I removed a lot of other stuff to simplify the post
I also thought that seeing that the memory is allocated with the class, I wouldn't need to test for a NULL pointer. Am I wrong?
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Ok, maybe I was a little bit fast to say that but I suspected that if he declare the array like that:
float data[4][4];
he will use it without using pointers, so something like that:
data[0][0] = 1.2345;
When you do that, there is no chance that your pointers inside your array are NULL (and they are allocated when the array is created, not like declaring an array float* data[4]; ).
|
|
|
|
|
Hi,
Yes I did. It crashes as I use the memory passed back. If I look at the memory it has f [0x0012fe30 -> 0x3f800000]. The memory address of 0x0012fe30 corresponds to the memory in the class.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Hmmm, it is difficult to guess what is happening. Post the code in which you use the array (where you put stuff inside it).
Off topic: I like your sig
|
|
|
|
|
Sure:
<br />
void main (void)<br />
{<br />
float **f;<br />
A id;<br />
f = id.GetData ();<br />
<br />
cout << f[0][0] << endl;<br />
}<br />
I have also just noticed that the error code is:
Unhandled exception at 0x004150e0 in agile_tests.exe: 0xC0000005: Access violation reading location 0x3f800000.
Sorry for the misleading info before.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
looking in the debugger, is id well constructed so ?
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20] | soon : [VisualCalc 3.0]
|
|
|
|
|
Yes, I checked and with the simple code he gave the program crashes. The array inside the class is correct (except that the data is not initialized but the array itself is valid). The problem appear because of the casting from float[4][4] to float** . At this point, the pointers becomes invalid (even if the it points to the same memory ). Probably because the two arrays are represented differently in memory (I didn't knew that)
|
|
|
|
|
Yes, id is constucted fine. If I use data[r][c] it is fine. Inside the class there are no problem with the data.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Ok, I created a new project to check your code and yes, I have the same problem. It comes from the casting of float[4][4] to float** (never had the problem before because I never use fixed sized double dimensions arrays). Maybe the best way to do it would be to use dynamic arrays:
class A<br />
{<br />
protected:<br />
float** data;<br />
}
Then, in the constructor of your class, create the array:
A::A()<br />
{<br />
data = new float[4];<br />
for(int i=0;i<4;i++)<br />
data[i] = new float[4];<br />
}
This will create a float[4][4] array (but still, the data in it is unitialized).
Don't forget to free the memory in the destructor of your class:
A::~A()<br />
{<br />
if (data)<br />
{<br />
for (int i=0;i<4;i++)<br />
{<br />
if (data[i])<br />
delete[] data[i];<br />
}<br />
<br />
delete[] data;<br />
}<br />
}
|
|
|
|
|
Ok, but how do you get double dimension arrays of constant size out of a class? It must be some how possible?
Thanks for the help btw
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Hi, I have a solution, but I don't know if you'll like it.
#include <iostream>
class A
{
public:
A(){ for( int i = 0; i < 4; i++ ) for( int j = 0; j < 4; j++ ) data[ i ][ j ] = 0; }
float** GetData()
{
float **g = new float*[ 4 ];
for( int i = 0; i < 4; i++ )
g[ i ] = data[ i ];
return g;
}
protected:
float data[ 4 ][ 4 ];
};
using namespace std;
int main( int nargs, char * cargs[] )
{
A id;
float** f = id.GetData();
cout << f[ 0 ][ 0 ] << endl;
delete [] f;
return 0;
} As far as I can tell, when you cast data as a float**, it interprets the value of data[ 0 ][ 0 ] as f[ 0 ]. Since data[ 0 ][ 0 ] == 0, then f[ 0 ] becomes the null pointer for the first row of the array. In my solution, you create the pointer array of pointers and initialize the values of the row pointers to the correct memory locations of data.
Of course, you have to delete the returned double pointer's array.
Hope that helps.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi,
Currently I have this way implemented but I was hoping that there could just get around it, as subsiquent posts have revealed.
Thanks anyway,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
No problem. Hope all turns out well. I, too, like that code below. <smile />
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|