 |
 |
Index ‹ Visual Studio ‹ Visual Studio C++
|
- Previous
- 1
- VB Scripts >> Problem with XCACLS.VBSHi
Is anyone using this? I down loaded it from Microsoft and I am having
trouble with the function to remove inherited rights and replacing them with
a copy of the rights
From reading the documentation, I am using /I COPY , but what happens is the
inherited permissons get removed, but nothing gets copied in - so subsequent
actions that rely on the parent permissions being copied are failing
(because the permissions aren't there)
Does anyone have any suggestions
Cheers
Bob
- 2
- VB Scripts >> Emptying the Recycle Bin without the Hand objectI'm using VBS 5.6 under W98 and I'm trying to empty the Recycle Bin. I
can get to the Recycle Bin via the Shell.Application object and I can
use InvokeVerb to get at the "Empty Recycle &Bin" action, but the
script stalls at the "Confirm Multiple File Delete" window that opens
until the "Yes" or "No" button is pushed... by hand. SendKeys (as well
as oAutoItX's Send) never see the window that harbors the Yes/No
buttons.
Here's the (very simple) code:
Set oShellApp = CreateObject("Shell.Application")
Const ssfDESKTOP = 0
Set oDT = oShellApp.Namespace(ssfDESKTOP)
For Each oFolderItem In oDT.Items
If oFolderItem.Name = "Recycle Bin" Then
oFolderItem.InvokeVerb("Empty Recycle &Bin")
Exit For
End If
Next
Other than by instantiating a Hand object (which is a well-known
member of Human.Application), is there any way to automate the
emptying of the Recycle Bin?
regards, Andy
--
**********
Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com
**********
- 3
- Visual Basic >> mdiforms and child formsI am creating a MDI application and when the user hits the cross to close the
app and selects no or cancel I want them to return to the current form they
were on with any data they had entered.
It appears to unload any child forms before running my sub routine that asks
if they are sure they want to exit.
I have tried the following code in the child forms unload event, in the
unload event of the MDI
Public CurForm as form 'this is in my module
set curForm = frmDeal
I can then go curForm.show in my sub routine when they select no or cancel
but all the entered info is missing
Is there a different form event I could use to catch this
The problem is that they complete around 10 forms with there information
before I save it to SQL through my stored procedures.
TIA for any help
- 4
- Visual Studio C++ >> Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code//goal: to make a 2 dimentional dynamic array and use it in matrix
multiplication plz help me, //i am using VC++
#include<iostream.h>
class Matrix
{
private:
int *e;
int m,n,sz;
static char count;
char name;
public:
Matrix(int mx = 0,int nx = 0):m(mx),n(nx)
{
sz = m*n;
e = new int[sz];
for(int i = 0;i<sz;i++) //initiaklize d array elements to 0
e[i] = 0;
count++;
name = count; //to have a naming convention of objects, etc A,B,C
}
void insert (int i,int j,int v) //to insert an element in the 2D array
{
if(i<=m && j<=n) //check is refference is ok then insert the item.
e[i * n + j] = v; //convert 2D indexes to one dimention.
else
cout<<"order violation, the matrix has order:"<<m<<'x'<<n<<endl;
}
//returns value of a particular pos /**********I get error in this
function i think*****/
int & pull (int i,int j) //retuns the number after converting 2D
indexes to one D index
{
if(i<=m && j<=n)
{
return e[i * n + j]; //conversion of 2D indexes to 1D, n is the 2nd
Dimention
}
else
{
cout<<"order violation, the matrix has order:"<<m<<'x'<<n<<endl;
return e[0];
}
}
//will store its order into two varables passes as refference by the
calling func
void order(int &M,int&N)
{
M = m;
N = n;
}
Matrix operator * (Matrix B) // matrix multiplication, works fine but
error comes in this
//block when pull is
called
{
if(n == B.m)
{
Matrix C(m,B.n);
for(int i=0;i<m;i++)
for(int j=0;j<B.n;j++)
for(int k=0;k<n;k++)
C.insert(i,j,C.pull(i,j) + this->pull(i,k) * B.pull(k,j));
return C;
}
else
{
Matrix null(m,B.n);
cout<<"order mismatch"<<endl;
return null;
}
}
void setMatrix()
{
int temp;
for(int i = 0;i<m;i++)
for(int j= 0;j<n;j++)
{
cout<<"Enter values of Matrix "<<name<<' '<<m<<'x'<<n<<" matrix at:
"<<i+1<<','<<j+1<<" :";
cin>>temp;
this->insert(i,j,temp);
}
}
void show()
{
for(int i = 0;i<m;i++)
{
for(int j = 0;j<n;j++)
cout<<this->pull(i,j)<<'\t';
cout<<endl;
}
}
~Matrix()
{
delete []e;
count--;
}
};
char Matrix::count = 64;
/********************************************************************************/
int main (void)
{
Matrix A(2,3),B(3,2),C(2,2);
A.setMatrix();
B.setMatrix();
C = A*B;
C.show();
A.show();
cout<<endl;
B.show();
cout<<endl;
C.show();
return 0;
}
///PLEASE any help will be greatly apriciated, i get error of
//Assertation falure at line 47 of dbgdl.cpp
//Expression:_block_type_is_valid(phead->nBlockType)
- 5
- VB Scripts >> Apply to All Folders - programaticallyHi,
I am wondering does anybody know how to do the following:
1. Open Windows Explorer.
2. Choose Tools - Folder Options...
3. Click View.
4. Then Either Select "Apply to All Folders" or "Reset All Folders"
I have found the registry settings to achive 1-3 above. (Although would be
happier to find a more approved way of doing this). However have not been
able to work out how step 4 works. Is their either a registry setting, a
windows API call or VBScript function that can achieve this?
Thanks,
Ward.
- 6
- MFC >> Adding lists to tabsI have a floating/dockable window derived from CControlBar and I have
declared a "CTabCtrl m_tabCtrl;" in the header for my class. In the OnCreate
method of the class I have created the tab control and assigned it an
imagelist. I can create tabs with whatever names and icons I need, but I
need help adding a CListCtrl. I have declared a list control in the class
and can create it with a fixed size, but I need it to use up the entire
client area of the dynamically sized and docked/floating tabbed window, but
I don't know how to attach the list control to the window / tab. Each tab in
this window needs to display a list control (same one?) with different
columns and items.
Thanks
- 7
- 8
- Visual Basic [VB] >> DataGrid Get F3 keypressI design my own datagrid which can turn Enter into 'Tab', BUT I cannot
detect the user keypress 'F3' , Why
I try to detect keyCode, it only effect on 'keydown' , 'keyup' , but it
cannot get my keypress 'FX'
Anybody got idea ? thanks a lot
Protected Overrides Function ProcessKeyPreview(ByRef m As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType(m.WParam.ToInt32(), Keys) And
Keys.KeyCode
If m.Msg = WM_KEYDOWN And keyCode = Keys.Enter Then
m.WParam = New IntPtr(Keys.Tab)
endif
end function
- 9
- MFC >> Print a BMPHi
I need to write an application that can print a BMP in its original size
(length and width). The application is not a dialog based application so
OnPrint event is not expected either thus the printer device context is to
be obtained manually too. Please guide me with any helping code available.
Regards
Usman
- 10
- Visual Basic >> VB6 report problem*hie~everyones...
I had done my VB6 project with Ms.Access as database. and now I conver
the access to Ms.SQL Server. I have modify my project and success t
connect the sql server, the whole program can work correctly except th
DataReport have problem. The DataReport pages can be show with title
header but empty record. I'm sure my previous access database versio
program can show the record.
Can anyones here tell me how?? I did not change anything on th
DataReport and DataEnvironment from my previous access database versio
Pls help me, urgent.
-
djla
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------
- 11
- 12
- Visual Basic [VB] >> Showing message without halting executionThe only way that I found to display a message to the user from an application that has an interface is by using the MessageBox.Show() method. What I need to do is notify the user of something without having to wait for user interaction.
Is there a way to display messages on screen that I could remove programmatically when I want to and would not stop execution?
Example:
1) User launches application
2) Application requests input file selection
3) User selects input file
4) Application displays message 'doing something with file' while doing something with file
5) Application finishes 'doing something with file'
6) Application removes message
- 13
- Visual Basic [VB] >> Focus Issue with an MDI applicationI have an MDI application that uses a main form frmMaint that is inheritted
from a Base Form we have created. In this form, we create a User Control
that contains the main entry fields. At the top of the form is our main
toolbar.
When I click on the tool bar to do a save for example, I loose focus from
the last input box that I was in. When I try to return focus to that text
box, I am not able to. I have saved the current control as a member
variable of the Base Form and populate in on a Control enter handler. When
I try to use the saved current control and do a CanFocus or CanSelect, both
come back as true. When I try to actually do the focus, False is returned.
Any suggestions?
Thanks
- 14
- 15
- Visual Basic [VB] >> InteropI have developed a COM INterop package in vb.net
The dll's for this package reside in a folder named DotNet.
Now, everything s works fine as long as the VB6 program calling this
pachage is above
the DOTNet folder ( the vb6 exe has a config file with probing
privatePath="DotNet" )
so the assemblies in the DOTNET folder successfully load.
Now some questions :
1) How can you get the Com Interop package to work with a vb6 program
when the vb6 program
is not above it in the file path structure ( ie. DotNet folder is not
below the folder
that contains the vb6 program trying to use the Com Interop Package.
2) Now, if you answered "Use the GAC" for the question #1 above, how
come that fails. The vb .net
interop assembly uses the
Microsoft.Practices.EnterpriseLibrary.Common and for some reason the
execution of the program will fail to load the
Microsoft.Practices.EnterpriseLibrary.Common assembly
whenever that assembly is loaded in the GAC ( fuslog dump below).
3) How does one get a vb6 program running in the VB6 IDE to load
assemblies in a Interop package
it uses, since the whiel under tghe IDE is something like /Program
Files/VB6 or something like that,
and the probed filepath or DotNet will not be present under program
files/vb6.
Fuslog dump ( for some reason it want to load
Microsoft.Practices.EnterpriseLibrary.Common.resources ,
I do not have any suc dll on my system).
*** Assembly Binder Log Entry (2/6/2008 @ 11:30:23 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file
specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework
\v2.0.50727\mscorwks.dll
Running under executable C:\Phase 13\CODE\UI Binaries
\TestPLWSClient.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = CSG\MHunter
LOG: DisplayName =
Microsoft.Practices.EnterpriseLibrary.Common.resources,
Version=3.1.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/Phase 13/CODE/UI Binaries/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = TestPLWSClient.exe
Calling assembly : Microsoft.Practices.EnterpriseLibrary.Common,
Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Phase 13\CODE\UI Binaries
\TestPLWSClient.exe.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET
\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference:
Microsoft.Practices.EnterpriseLibrary.Common.resources,
Version=3.1.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Phase 13/CODE/UI
Binaries/en/
Microsoft.Practices.EnterpriseLibrary.Common.resources.DLL.
LOG: Attempting download of new URL file:///C:/Phase 13/CODE/UI
Binaries/en/Microsoft.Practices.EnterpriseLibrary.Common.resources/
Microsoft.Practices.EnterpriseLibrary.Common.resources.DLL.
LOG: Attempting download of new URL file:///C:/Phase 13/CODE/UI
Binaries/DotNet/en/
Microsoft.Practices.EnterpriseLibrary.Common.resources.DLL.
LOG: Attempting download of new URL file:///C:/Phase 13/CODE/UI
Binaries/DotNet/en/
Microsoft.Practices.EnterpriseLibrary.Common.resources/
Microsoft.Practices.EnterpriseLibrary.Common.resources.DLL.
LOG: Attempting download of new URL file:///C:/Phase 13/CODE/UI
Binaries/en/
Microsoft.Practices.EnterpriseLibrary.Common.resources.EXE.
LOG: Attempting download of new URL file:///C:/Phase 13/CODE/UI
Binaries/en/Microsoft.Practices.EnterpriseLibrary.Common.resources/
Microsoft.Practices.EnterpriseLibrary.Common.resources.EXE.
LOG: Attempting download of new URL file:///C:/Phase 13/CODE/UI
Binaries/DotNet/en/
Microsoft.Practices.EnterpriseLibrary.Common.resources.EXE.
LOG: Attempting download of new URL file:///C:/Phase 13/CODE/UI
Binaries/DotNet/en/
Microsoft.Practices.EnterpriseLibrary.Common.resources/
Microsoft.Practices.EnterpriseLibrary.Common.resources.EXE.
LOG: All probing URLs attempted and failed.
|
| Author |
Message |
dune17856

|
Posted: Wed Oct 24 11:58:48 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
Hi,
Imagine:
CSomeClass* c = NULL;
c = new CSomeClass();
delete c;
c = new CSomeClass();
delete c;
So I must call delete c; to clean up memory.
However, instead of doing it like so.. isn't it equally valid to make class
self deleting?
So, if I do this:
class CSomeClass
{
CSomeClass();
virtual ~CSomeClass() { delete this; }
}
can I then simply do this?
CSomeClass* c = NULL;
c = new CSomeClass();
c = new CSomeClass();
What happens when I reassign the valiable to new instance? Will CSomeClass
self-delete itself at that point, or when application terminates?
Lisa
Visual Studio335
|
| |
|
| |
 |
Scott

|
Posted: Wed Oct 24 11:58:48 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
"Lisa Pearlson" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Hi,
>
> Imagine:
>
> CSomeClass* c = NULL;
> c = new CSomeClass();
> delete c;
> c = new CSomeClass();
> delete c;
>
> So I must call delete c; to clean up memory.
>
> However, instead of doing it like so.. isn't it equally valid to make
> class self deleting?
>
> So, if I do this:
>
> class CSomeClass
> {
> CSomeClass();
> virtual ~CSomeClass() { delete this; }
> }
>
> can I then simply do this?
>
> CSomeClass* c = NULL;
>
> c = new CSomeClass();
> c = new CSomeClass();
>
> What happens when I reassign the valiable to new instance? Will CSomeClass
> self-delete itself at that point, or when application terminates?
Afraid not. When you reassign the variable to a new instance what you get
is a memory leak. I.e., you have overwritten the pointer to the first
object, so you then have no way to delete it.
--
Scott McPhillips [VC++ MVP]
|
| |
|
| |
 |
Igor

|
Posted: Wed Oct 24 12:05:30 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
Lisa Pearlson <EMail@HideDomain.com> wrote:
> So, if I do this:
>
> class CSomeClass
> {
> CSomeClass();
> virtual ~CSomeClass() { delete this; }
> }
This makes no sense. The destructor runs _because_ the object is being
destroyed. Trying to destroy it a second time while already under
destruction will likely just crash your program.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
|
| |
|
| |
 |
Lisa

|
Posted: Wed Oct 24 12:47:48 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
Then when would one use "delete this" ?
I see it used often in MFC's PostNcDestroy();
So if you don't use MFC, at which moment is "delete this" actually called?
In destructor?
How can the destructor be called withouth calling "delete" ?
Lisa
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:%EMail@HideDomain.com...
> "Lisa Pearlson" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
>> Hi,
>>
>> Imagine:
>>
>> CSomeClass* c = NULL;
>> c = new CSomeClass();
>> delete c;
>> c = new CSomeClass();
>> delete c;
>>
>> So I must call delete c; to clean up memory.
>>
>> However, instead of doing it like so.. isn't it equally valid to make
>> class self deleting?
>>
>> So, if I do this:
>>
>> class CSomeClass
>> {
>> CSomeClass();
>> virtual ~CSomeClass() { delete this; }
>> }
>>
>> can I then simply do this?
>>
>> CSomeClass* c = NULL;
>>
>> c = new CSomeClass();
>> c = new CSomeClass();
>>
>> What happens when I reassign the valiable to new instance? Will
>> CSomeClass self-delete itself at that point, or when application
>> terminates?
>
>
> Afraid not. When you reassign the variable to a new instance what you get
> is a memory leak. I.e., you have overwritten the pointer to the first
> object, so you then have no way to delete it.
>
> --
> Scott McPhillips [VC++ MVP]
|
| |
|
| |
 |
Alex

|
Posted: Wed Oct 24 12:46:02 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
"Lisa Pearlson" wrote:
> can I then simply do this?
>
> CSomeClass* c = NULL;
>
> c = new CSomeClass();
> c = new CSomeClass();
>
> What happens when I reassign the valiable to new instance?
> Will CSomeClass self-delete itself at that point, or when
> application terminates?
Other already answered that you'll get memory leak. It is
because pointer `c' knows nothing about about class'
destructor. Pointer just holds an address to the allocated
memory, that's all.
What you need here is so called "smart pointer". Smart
pointer is a class that wraps raw pointer and ensures the
release of acquired resources. You can implement such smart
pointer class by yourself, for example:
class CSomeClassPtr
{
public:
CSomeClassPtr(CSomeClass* p = NULL) : m_p(p) {}
~CSomeClassPtr() { delete m_p; }
public:
CSomeClass* operator ->()
{ return m_p; }
const CSomeClass* operator ->() const
{ return m_p; }
CSomeClass* operator =(CSomeClass* p)
{
if(p != m_p)
{
delete m_p;
m_p = p;
}
return m_p;
}
private:
CSomeClass* m_p;
};
Then you can use `CSomeClassPtr' instead of raw pointer:
CSomeClassPtr ptr;
ptr = new CSomeClass();
ptr = new CSomeClass();
However, there is similar smart pointer already implemented
in STL - `std::auto_ptr':
typedef std::auto_ptr<CSomeClass> CSomeClassPtr;
CSomeClassPtr p1(new CSomeClass);
CSomeClassPtr p2(new CSomeClass);
...
HTH
Alex
|
| |
|
| |
 |
Alex

|
Posted: Wed Oct 24 13:05:43 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
"Lisa Pearlson" wrote:
> Then when would one use "delete this" ?
> I see it used often in MFC's PostNcDestroy();
MFC framework has its rules. One of them is that
`PostNcDestroy' will be called by the framework as last call
for window object. That's why it's possible to put there
"delete this;" statement. If you call any member after
`PostNcDestroy' call, then you'll likely get a crash, since
`this' will be garbage already.
> So if you don't use MFC, at which moment is "delete this"
> actually called?
Withiut MFC framework nobody will call "delete this;". You
will need to call it yourself,
> In destructor?
> How can the destructor be called withouth calling "delete"
> ?
It can be called like this:
CSomeClass* c = ...
c->~CSomeClass();
however, it's quite an esoteric issue to begin with and very
rarely used in everyday practice. You just don't put "delete
this;" in destructor, that's it. If you want automatic
release of allocated memory, then use smart pointers.
Alex
|
| |
|
| |
 |
Doug

|
Posted: Wed Oct 24 13:07:21 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
On Wed, 24 Oct 2007 21:47:48 +0200, "Lisa Pearlson" <EMail@HideDomain.com> wrote:
>Then when would one use "delete this" ?
>I see it used often in MFC's PostNcDestroy();
This is done for some window types so that the window can automatically
destroy itself when the user closes it, or more generally, when someone
calls DestroyWindow. It's a fragile technique, because once the object is
deleted, no one can continue to use it, hence the comment in the MFC source
to the effect that "WM_NCDESTROY is the absolute last message received by
the window"... it had better be. Moreover, none of the functions in the
call chain leading to PostNcDestroy can use the object as the stack is
unwound as they return.
>So if you don't use MFC, at which moment is "delete this" actually called?
>In destructor?
Never in the destructor!
>How can the destructor be called withouth calling "delete" ?
For a dynamically allocated object, the ordinary way is by deleting the
object. You can call it yourself, but that's an advanced technique that is
rarely needed.
--
Doug Harrison
Visual C++ MVP
|
| |
|
| |
 |
Igor

|
Posted: Wed Oct 24 13:09:47 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
Lisa Pearlson <EMail@HideDomain.com> wrote:
> Then when would one use "delete this" ?
> I see it used often in MFC's PostNcDestroy();
In this case, the lifetime of the object is tied to lifetime of another
entity, an HWND handle. The object is notified that HWND is destroyed,
and chooses to destroy itself at the same time.
> So if you don't use MFC, at which moment is "delete this" actually
> called? In destructor?
Effectively, in the window proc in response to WM_NCDESTROY message.
This message is guaranteed to be the last ever sent to a window proc for
a given window.
> How can the destructor be called withouth calling "delete" ?
A destructor will also be called when a stack-based object goes out of
scope, or for an object with static duration when the program
terminates.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
|
| |
|
| |
 |
Duane

|
Posted: Wed Oct 24 13:47:50 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
"Lisa Pearlson" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Hi,
>
> Imagine:
>
> CSomeClass* c = NULL;
> c = new CSomeClass();
> delete c;
> c = new CSomeClass();
> delete c;
>
> So I must call delete c; to clean up memory.
>
> However, instead of doing it like so.. isn't it equally valid to make
> class self deleting?
>
> So, if I do this:
>
> class CSomeClass
> {
> CSomeClass();
> virtual ~CSomeClass() { delete this; }
> }
>
> can I then simply do this?
>
> CSomeClass* c = NULL;
>
> c = new CSomeClass();
> c = new CSomeClass();
You have delete this in the dtor. When is the dtor invoked here?
If it was invoked, your "delete this" would either be redundant
or crash.
> What happens when I reassign the valiable to new instance? Will CSomeClass
> self-delete itself at that point, or when application terminates?
My quess would be that this would leak or crash. Why not just use a
smart pointer or no pointer?
|
| |
|
| |
 |
Ben

|
Posted: Wed Oct 24 14:36:06 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
"Lisa Pearlson" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Hi,
>
> Imagine:
>
> CSomeClass* c = NULL;
> c = new CSomeClass();
> delete c;
> c = new CSomeClass();
> delete c;
>
> So I must call delete c; to clean up memory.
>
> However, instead of doing it like so.. isn't it equally valid to make
> class self deleting?
>
> So, if I do this:
>
> class CSomeClass
> {
> CSomeClass();
> virtual ~CSomeClass() { delete this; }
No! Not in the destructor.
This is ok though:
virtual void Release() { delete this; }
It is often combined with reference counting, a single threaded version
might look like:
int m_useCount;
virtual void AddRef() { m_useCount++; }
virtual void Release() { if (0 == --m_useCount) delete this; }
The other advantage of a self-deleting class is that it uses the memory
manager where the class is defined. When using DLLs you should respect
memory ownership and the same library that defines an object must both
create and destroy it, usually by using a factory function and a
self-deleting member function.
> }
>
> can I then simply do this?
>
> CSomeClass* c = NULL;
>
> c = new CSomeClass();
> c = new CSomeClass();
>
> What happens when I reassign the valiable to new instance? Will CSomeClass
> self-delete itself at that point, or when application terminates?
>
> Lisa
>
|
| |
|
| |
 |
Giovanni

|
Posted: Wed Oct 24 15:25:48 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
"Ben Voigt [C++ MVP]" <EMail@HideDomain.com> ha scritto nel messaggio
news:EMail@HideDomain.com...
> It is often combined with reference counting, a single threaded version
> might look like:
>
> int m_useCount;
> virtual void AddRef() { m_useCount++; }
> virtual void Release() { if (0 == --m_useCount) delete this; }
It is like COM and ATL do (BTW: I believe they work also with
multithreading, maybe they use some multithreading-safe form of
increasing-decresing the counter, but I don't know precisely).
IMHO, the OP may consider using ATL for her development. She will have
robust classes and patterns to use to build quality apps, and not spend time
trying to kind of "reinventing the wheel" (see also another thread about
object-oriented C++ development to wrap Win32 APIs using Get/SetWindowLong,
etc.).
Giovanni
|
| |
|
| |
 |
Ben

|
Posted: Thu Oct 25 07:35:58 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
"Giovanni Dicanio" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
>
> "Ben Voigt [C++ MVP]" <EMail@HideDomain.com> ha scritto nel messaggio
> news:EMail@HideDomain.com...
>
>> It is often combined with reference counting, a single threaded version
>> might look like:
>>
>> int m_useCount;
>> virtual void AddRef() { m_useCount++; }
>> virtual void Release() { if (0 == --m_useCount) delete this; }
>
> It is like COM and ATL do (BTW: I believe they work also with
> multithreading, maybe they use some multithreading-safe form of
> increasing-decresing the counter, but I don't know precisely).
The most common method is InterlockedIncrement/InterlockedDecrement.
>
> IMHO, the OP may consider using ATL for her development. She will have
> robust classes and patterns to use to build quality apps, and not spend
> time trying to kind of "reinventing the wheel" (see also another thread
> about object-oriented C++ development to wrap Win32 APIs using
> Get/SetWindowLong, etc.).
True, but it is still important to do it once yourself so you understand how
the frameworks behave.
|
| |
|
| |
 |
Giovanni

|
Posted: Thu Oct 25 09:55:10 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
"Ben Voigt [C++ MVP]" <EMail@HideDomain.com> ha scritto nel messaggio
news:%EMail@HideDomain.com...
> True, but it is still important to do it once yourself so you understand
> how the frameworks behave.
Yes, for learning purposes, I do agree with you.
Giovanni
|
| |
|
| |
 |
Alexander

|
Posted: Thu Oct 25 11:43:20 PDT 2007 |
Top |
Visual Studio C++ >> Self deleting class
Have a look at Boost smart pointers:
shared_ptr<>
scoped_ptr<>
intrusive_ptr<>
http://www.boost.org/
You approach of "delete this;" would be used with self-reference
counting and intrusive_ptr<>. Personally I mostly use shared_ptr<>.
As others already pointed out, your approach of calling delete this
in the destructor doesn't make the slightest sense.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: EMail@HideDomain.com
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
"Lisa Pearlson" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Hi,
>
> Imagine:
>
> CSomeClass* c = NULL;
> c = new CSomeClass();
> delete c;
> c = new CSomeClass();
> delete c;
>
> So I must call delete c; to clean up memory.
>
> However, instead of doing it like so.. isn't it equally valid to make
> class self deleting?
>
> So, if I do this:
>
> class CSomeClass
> {
> CSomeClass();
> virtual ~CSomeClass() { delete this; }
> }
>
> can I then simply do this?
>
> CSomeClass* c = NULL;
>
> c = new CSomeClass();
> c = new CSomeClass();
>
> What happens when I reassign the valiable to new instance? Will CSomeClass
> self-delete itself at that point, or when application terminates?
>
> Lisa
>
|
| |
|
| |
 |
| |
 |
Index ‹ Visual Studio ‹ Visual Studio C++ |
- Next
- 1
- MFC >> Resource limit?I am having a really weird issue that I can't figure out...
I am getting a unhandled exception in my application. Also a "a resource is
unavailable..." error. It appears to be related to opening a large number
of resources. I'm not sure.
I have a CDialog derived class that is embedded in a tabbed dialog type
control which is all part of a CFormView. This dialog view has a custom
control/grid that uses CStatic controls for the cells. Each instance of
the class creates around 250 CStatic controls. This has always worked
well, but recently I modified my code so that more than one of these
CFormViews can be open at a time.
On opening the 6th instance (they all use the same MDI template), the app
blows up. I can't track it down to a single line and I think that's
because it's an application-wide issue.
I don't think it's necessarily a problem with this particular CDialog over
the other ones in the tab dialog view. I think it causes the problem
because it creates so many controls. In fact it's not even this type of
view that is the problem. After opening 5 views, if I open a normal
CDialog that embeds the same grid control it blows. I'm pretty sure the
grid isn't specifically the problem just the source of the problem.
If I debug deep into MFC code it appears the CreateCompatibleDC is failing
in different places.
Is there a limit to the number of controls that can be opened at one time
(that would be odd). Is there a conflict between using the same resource
IDs over and over between views?
I have debugged for hours on this and am baffled. Any clues or direction
would be greatly appreciated!
Thanks much.
Eric
- 2
- Visual Studio C++ >> VS 2005 Compatibility ProblemPlease point me to a more appropriate group if there is one.
Thanks.
We have a native Win32 API console program built with VC++ and VS
2005. It will run on any XP box with VS 2005 installed. Then,
we packed it and the needed DLLs up and put it on a server. It
turns out it will run fine on Windows 2000 server but won't start
at all on a Windows 2003 server. The error is "The system cannot
execute the specified program." We get the same thing when
testing on an XP box that DOESN'T have VS 2005 installed.
Any ideas?
- Arnie
- 3
- MFC >> Parent window cannot receive mouse click from child control.Hi there, that is strange. I have a form view inside a splitter window
that holds a slider bar. For whatever reason I cannot receive mouse
click messages when I click on the the control. I can receive the
messages when I click besides the control.
I was trying to look through newsgroups but I could find anything.
I know it must be something simple. Anyone that can help me out?
Christian
- 4
- 5
- Visual Basic >> Do Not Show Box AgainHi All,
I have a small form that appears at the start of my program that allows the
user to fix certain parameters that are lised in Combo boxes in the main
program before starting. This works OK but appears everytime the program is
first run.
What I would like is for there to be a Check Box that askes the question "Do
not show this box again" and fixes the selected parameters for all time in
the main programs Combo boxes, and does not appear again.
Can this be done?
Best Rgds,
Dave Robinson
- 6
- Visual Basic [VB] >> Disconnected socket still connected! - What then?Hi, I have synchronous communications between a server and client. To save bandwith the connection must persist. So the socket must stay open and only be re-opened in case of communications failure. To simulate failure, the server disconnects the socket. However, the client socket parameter shows an open socket: socket.connected is true, socket. Active is true, socket.poll(1,selectRead) is true. When checking the MS class documentation, it is stated that socket.connected reflects the LAST status of the socket. So far, I have come accross many other programmers having the same problem. Some suggested of using the exceptions errors. But when connecting to a socket which is still open (according to VB.Net) while having the plug pulled out, the excpetion error one gets is, guess.......................Trying to connect on an open socket!! Have anyone found a way out yet? (That is appart from using other objects not designed in .NET)
- 7
- MFC >> COleControl::GetDCHi,
I am attempting to create a windowless control which will be transparent,
apart from animation that it draws to the screen in separate threads. I have
successfully worked out all the thread handling and synchronization thanks
to you lot but I am a bit stuck on the bit about the windowless control
getting a device context, especially as I want to paint to a buffer device
context and then copy that to the screen to avoid problems of bits of the
animation 'getting stuck' as they do when a control draws animates directly
to the screen. I've read the information in the link at the bottom of the
page, but does anybody know the answer to the following?
1) If I use the OLEDC_OFFSCREEN flag, I'm just a bit unsure as to what takes
care of the buffer device context and the copying of it to the screen. Does
the container take care of this (as is my guess), or does MFC take care of
it, or do I have to code that myself?
2) I understand how if OLEDC_PAINTBKGND is the parameter, the container
repaints the area of the window covered by the control with its own contents
in that area before passing the device context to the control in order to
allow it to paint to it, but does this happen if I just use OLEDC_OFFSCREEN?
Can I use OLEDC_OFFSCREEN | OLEDC_PAINTBKGND, i.e. do an OR operation to
specify them both?
Thanks for the help
Regards
Ben
- 8
- MFC >> OnIdle and UI threadHi,
I have an app that the Mainframe and the View are not in the same thread.
Then I find a problem, when the mouse is inside the View, the MainFrame's
OnUpdateUI handler is not call. Then I find it's because the main thread's
OnIdle is not called.
Why this happens and how to solved it?
Any comments are appreciated
Best
Jeff
- 9
- 10
- Visual Basic >> GetDriveType problemNot really a problem but more of a question.
I see how to use the GetDriveType API to get
the type of drive for a letter such as c:\
Is there a way to get the media type inside a drive.
In particular is there a way to tell if a disc is a CDR
or a DVD-R.
Thanx
- 11
- Mcse >> InquiryI'm really interested in becoming a .com millionaire. Does anyone have any
information on this? I've only got $5.99 to my name. Do you think this is
possible?
Or a way to make $3,000 a day. That would also be swell.
Send me the sweet info ASAP: DeathFromAbove@suckasontheweb.com
Death from Above
- 12
- Visual Basic [VB] >> Reflection and Menu Merging in MDIsWe have an MDI application that looks for forms in which a common interface
has been implemented. We can instantiate the forms and display them as
children of the mdi and use the functionality on them.
The problem is that the menus from the child forms don't show up. They
don't even show up on the
form itself, much less merge with the mdiparent menus
We have changed the modifiers on the menu and on each item in the menu to
public so they can be seen outside the assembly. We have tried not making
the form an mdichild and using it as a stand-alone application (still
instantiated by the mdi, although not as a child). The child form does
appear in the 'windows' list as a child of the mdi.
Is there any way to make available to the mdi, the menu on a child form
instantiated through reflection?
- 13
- 14
- Visual Basic [VB] >> System.Diagnostics.ProcessHello All,
I have posted previously regarding the above assembly. I have created a 2
classes and an interface to mask the complexities of using the above
assembly. The purpose of the interface is to allow one to create any UI
that they wish to search for files using the program find.exe. All the user
has to do is implement the interface and instantiate the FileFinderControl.
Class: ProcessController (has two threads that montor StandardOutput and
StandardError, and two delegates and events to pass this information on to
the FileFinderControl which manipulates the IFileFinder Interface)
Class: FileFinderControl (manages the interactions between the
System.Diagnostic.Process and the IFileFinder Interface)
Interface IFileFinder (abstracts the UI implementation so multiple UIs can
be created)
My problem is that I cannot get this architecture to run without the
ProcessController stepping on memory and causing a fault. I can implement
System.Diagnostics.Process seperately but only within my GUI. In the GUI
implementation I use the Invoke method to communicate across the thread but
it does not work when implemented through an interface.
Any Suggestions?
Thanks,
Dan
- 15
- Visual Basic >> Service Pack 6I wanted to know if anyone out there had installed Visual Studio Service Pack 6 and what the consensus was on it. Any one run into problems?
|
|
|