|
Did you mean (m_array.GetAt(i)).Set(); ?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
No Check the code
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Technically, yes, but 0 was used in the example so it just propagated to the reply. In any case, whether 0 or i was used was not the cause of the problem.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
It depends on the application, maybe he just wanted to call Set on the first object 20 time.
That's why i suggested that he checks the code.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Since you are adding a CEmail reference to the CEmailArray , you need to do the same thing (i.e., you can't use a pointer, unless new was called first) when accessing the array. So just change the call to GetAt() to:
CEmail eml;
...
eml = m_array.GetAt(0);
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thank you all, guys !
GetAt(0) was typo, it had to be (i) but it's not important.
I'm curious, why my solution did not work. Maybe temporary object
returned from GetAt was destroyed before I called Set().
But anyway, I found GetAt() unusable, since I need to change objects in array,
not some temporary object returned by GetAt().
I don't understand why GetAt is designed to return copy of the object instead of reference/pointer to object in the array,
I had to use this :
for (i=0; i<20; i++)
{
m_array[i].Set();
}
AfxMessageBox(m_array.GetAt(0).m_data);
The dialog in GetAt case shows "aaa", in operator[] case returns correct result "hello"
But operator[] is also defined like returning reference, or constant, returning copy, I don't have a clue which type the compiler will choose,
I'm happy that correct type was choosen in my code.
Thanks !
rrrado
|
|
|
|
|
Hi
I have created a class (class A) that manages a number of image. The images' pixel values are stored as unsigned char *. These images are destroyed using delete[] in A's destructor. Another class, class B, in turn manages a number of A objects, and each A object is assigned a unique ID. At first I was planning to declare something like:
std::map<unsigned int, A> m_mA;
in B. My concern is, when I insert a new element to m_mA using:
std::pair<unsigned int, A> pTmp(A_UNIQUE_ID, AN_A_OBJECT);
m_mA.insert(pTmp);
a copy of AN_A_OBJECT will be created and destroyed, invalidating AN_A_OBJECT's pointer to the pixel values. Is this correct?
If it's correct, one possible solution may be defining a copy constructor and assigment operator for A that take care of this issue, although I'm not sure whether this is the most elegant solution. Another possible solution, although I find it very_very strange, is to use 2D vector instead of unsigned char* to store the pixel values. Could someone tell me how I can overcome this? Hopefully the solution does not require me to use classical arrays....
Thanks!
|
|
|
|
|
Yes, a temporary A object will be created (pTmp), and the m_mA.insert will make a copy of this - you will have two objects constructed, with pTmp being destructed once it goes out of scope. Depending how you obtain the pixel data in class A (you didnt provide details of this), then the destruction of pTmp may, or may not, invalidate the A that was inserted into m_mA.
You could define a copy constructor, but it will be tricky to ensure that the memory is deallocated at the appropriate time. A better solution would be to use something like Boost shared_ptr[^], and dynamically allocate the A objects and get the SmartPtr to handle deallocation.
<br />
typedef boost::shared_ptr<A> APtr;<br />
typedef std::map<int,APtr> MyMap;<br />
<br />
m_mA[id] = APtr (new A);<br />
This way there is no copying of objects, only of pointers. Not only will it be more efficient, but the SmartPtr will ensure that the class is destroyed once it is no longer used.
|
|
|
|
|
Hi
Thanks for the reply. The pixel data are allocated by class A with the new[] operator upon A's instantiation, and deallocated (using delete[]) in A's destructor. In this case, I think pTmp's destruction will invalidate A's pixel data, won't it? And will converting the pixel data to 2d vector get rid of this problem?
Thanks!
|
|
|
|
|
We can Enable/Disable the hibernation support by follow procedure :
1. Open Control Panel.
2. Select Power Options.
3. Click Hibernation.
4. Check/Uncheck Enable Hibernation.
How to implement this function in VC++ ?
Jesa
|
|
|
|
|
Hi guys
How can I change my cursor whem I'm over a precise region of a CStatic control?
I've tried Setcursor(...) inside OnMouseMove but without succes (debugging the code enters but the cursor doesn't change).
What exactly I have to use? (any example?)
Best Regards
Doc
|
|
|
|
|
You'll want to do it in OnMouseMove with SetCursor , as you have already tested, but you'll also have to do a SetCursor in OnSetCursor (a handler for the WM_SETCURSOR -message).
|
|
|
|
|
- hi all, I want to find all folders which are shared fully in my drive and list them on. But i don't know how.
hope you help me
thanks
|
|
|
|
|
I also want to know this.
I want to find all the shared folders on the computer in same LAN.
Please help me regarding this.
Thanks and Regards,
Shri
|
|
|
|
|
Hello !
I have a dll that is written in C++ and is called in VB. In one function I need to send a structure containing strings !! But how can I do this, this is really hell to understand how VB handles the strings ! I tried with the BSTR type but this doesn't work
Example:
struct VBSTRUCT<br />
{<br />
BSTR String1;<br />
BSTR String2;<br />
}<br />
<br />
<br />
int __stdcall TestFunc(VBSTRUCT* VbStruct)<br />
{<br />
}<br />
<br />
The structure is declared in VB also !
The thing I don't understand is that it's working the other way: when the function is called and when I fill the structure within my Dll (using SysAllocStringByteLen function to allocate the string). And also, when I check in memory the strings that are allocated, the characters are on ONE byte and VB still understand it .
I tried a lot of things but nothing works. If someone has an idea how to do this, this would be great .
Thanks
|
|
|
|
|
If you change the type to a VARIANT and do the following you should be able to pass a collection of strings through to it. I have not tried this with VB but it ought to work.
int __stdcall TestFunc(VARIANT var)
{
if ((var.vt & VT_ARRAY) == 0)
return E_INVALIDARG;
<br>
if ((var.vt & VT_BSTR) == 0)
return E_INVALIDARG;
<br>
SAFEARRAY* pSA = var.parray;
BSTR* bstrArray;
<br>
SafeArrayAccessData(pSA, reinterpret_cast<void**>(&bstrArray));
<br>
for (unsigned i = 0; i < pSA->rgsabound->cElements; i++)
{
}
<br>
SafeArrayUnaccessData(pSA);
}
Some C++ test code
VARIANT var;
int nSize = <size of array>;
<br>
VariantInit(&var);
<br>
var.vt = VT_ARRAY | VT_BSTR;
<br>
SAFEARRAY* pSA;
SAFEARRAYBOUND bounds = {nSize, 0};
<br>
pSA = SafeArrayCreate(VT_BSTR, 1, &bounds);
<br>
BSTR* bstrArray;
<br>
SafeArrayAccessData(pSA, reinterpret_cast<void**>(&bstrArray));
<br>
for (int i = 0; i < nSize; i++)
{
}
<br>
SafeArrayUnaccessData(pSA);
<br>
var.parray = pSA;
<br>
Hope that helps
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Hello,
I'd like to know how I'd go about putting a file select control into a dialog using VC++ 6.0.
I've tried adding a registered activex control -> SelectFile to my project but when I drag and drop the control onto my dialog, I get errors saying that the control is missing an interface.
Regards.
|
|
|
|
|
Do you mean CFileDialog?
(opening, saving files?)
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
No, not after the CFileDialog, to be more clear I'm developing a dialog that enables the user to find images based on keywords that the user enters into the dialog.
So what I needed was a combo box or a tree control that would let the user pick the directory on which they want to browse.
Regards.
|
|
|
|
|
Hello!
I have a question about RegQueryValueEx API, after the second execution of this API, it does not return an ERROR_SUCCESS value provided there is a correct registry entry and path. Why is this?
Ex:
if( ERROR_SUCCESS == ::RegOpenKeyEx(HKEY hKey, LPCTSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult))
{
if (ERROR_SUCCESS == ::RegQueryValueEx(HKEY hKey,LPCTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData))
{
if lpData.Find("Sample"); //lpData as _TCHAR, Sample = Data from registry
{
if( ERROR_SUCCESS == ::RegOpenKeyEx(HKEY hKey2, LPCTSTR lpSubKey,DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)) // another path is opened
{
If (ERROR_SUCCESS == ::RegQueryValueEx(HKEY hKey2,LPCTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)) //this condition failed to return an ERROR_SUCCESS provided there is a correct path from the registry.
{
...
}
}
}
}
}
"smile donkey, smile!"
|
|
|
|
|
if lpData.Find("Sample"); should be if (lpData.Find("Sample") != -1)
sorry...
|
|
|
|
|
Hi all,
I am very keen to change the caption of a button (Ok,Cancel,Apply and Help)on a property page and also change the caption of Title bar on a Properysheet.How can I know the ID of buttons on a property page.
Please help me.
rajesh
|
|
|
|
|
OK is IDOK
Cancel is IDCANCEL
Apply is ID_APPLY_NOW
Help is IDHELP
Use GetDlgItem() to get the window (CWnd) associated with the control then use SetWindowText() to set the control text. The title of the property sheet is set when you create the property sheet. Or using SetWindowText() within the property sheet class.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
In the appication that i m developing,i wish to create an alert messages whenever certain condition is met. i have already created such an alert message using MessageBox but instead of that i know wish to show that alert as a popup from the tray which stays for few seconds and disappers atomatically. need suggestions on how to do....
ask_you
|
|
|
|
|