|
struct stTst
{
stTst(){p=NULL;}
~stTst(){
if (p!=NULL) {
delete p;
}
}
int i;
int j;
char c;
int *p;
};
void CTestdeleteDlg::OnButton1()
{
int k=123;
stTst *p=new stTst[10];
p->p=&k;
delete[] p;
}
-- modified at 1:01 Tuesday 6th September, 2005
|
|
|
|
|
followait wrote:
stTst *p=new stTst[10];
Here, you are creating 10 objects of the class.
If you need only one object, then:
stTst* p = new stTst;
...
delete p;
If you really need 10 objects, then you need to access them through a subscript, like:
stTst* p = new stTst[10];
p[0]->p = &k; //etc
p[1]->p = &k2;
...
To delete all the objects:
delete[] p;
this is this.
|
|
|
|
|
It's my careless, it should be delete[] p, but still have a error.
|
|
|
|
|
You are allocating k in the stack and then using delete on it inside the destructor of stTst . If stTst is going to assume its p member points to a heap-allocated int and that it can delete the pointer, you'd need to change your code to:
void CTestdeleteDlg::OnButton1()
{
int* pK = new int;
*pK = 123;
stTst* p = new stTst[10];
p->p = pK;
delete[] p;
}
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi,
int k=123;
stTst *p=new stTst[10];
p->p=&k;
delete[] p;
look k is allocated in the stack memory of the function OnButton1(). You are assigning the address of k to a class member variable and deleting it through dynamic deletion option. You can do that.
You cannot dynamically delete a variable which is allocated in the stack.
So you supposed not to delete the
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
|
i want to communicate with a device through LPT port, how can i do this using Win32(sdk) programming, plz help me.
|
|
|
|
|
|
how to install windows NT services?
d
|
|
|
|
|
how to install windows NT service int cmd ?
d
|
|
|
|
|
use [servicepath.exe] -service on commandline
|
|
|
|
|
prasad_som wrote:
use [servicepath.exe] -service on commandline
Sorry for correcting you, No executable sample generated through wizard's contain implementation for -service command line.
You required api call to CreateService to install service in local Service manager database
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
It will definitely work. I was answering "how to install NT serive:
And answer posted by me is right.I've used it in one of my project
Sorry for replying late to your comment. But some how i'm not getting mails from CP, even if i select checkbox "Notify me by email if..."
|
|
|
|
|
prasad_som wrote:
It will definitely work. I was answering "how to install NT serive:
---Sorry comment deleted--------------------------
actually the Service should process/acknowledge -install command line, thats not default functionality
prasad_som wrote:
anI've used it in one of my project
Thats nice and i started my career with that
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
-- modified at 4:46 Thursday 15th September, 2005
|
|
|
|
|
GflPower wrote:
how to install windows NT service int cmd ?
use CreateService api
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Read this[^] guide.
Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
I recently started exploring using an SDI interface for this app I'm trying to write and I'm currently filling out the source code to do it (which should be complicated). I started the project from the AppWizard like almost all of my apps do. It asked me for a default file extension but I didn't give one not knowing what I'd want and figured I could set it later and here I am, ready to set a default extension but I can't seem to find it. I've tried searching help files and searching for the text "ext" but nothing shows up. Does the system default to All Files since I didn't offer up an extension and I need to add in something somewhere to set the extension?
Also, how can I change what shows up in the child window? I just get a big white area. I want to take out that white area and place controls on my own in there through source code.
|
|
|
|
|
All you need do is go to Resource-->String table. There you can find entry for IDR_MAINFRAME. You can get help to fill out IDR_MAINFRAME through google.
Other see the following example.
IDR_MAINFRAME has to be set like this.
sample\n\nSample\nSample Files (*.dat)\n.dat\nSample.Document\nSample Document
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
What should i do to make the big dialog bar displayable with different resolution.
The problem i am currently facing is that the dialog bar cannot be fully displayed with low resolution even when maximized.
How to make it compatible with different resolution?
Thanks in advance...
|
|
|
|
|
I have a server and client source code and I not very understand the send and receive part of the program. After I execute the program, it show Bytes send: 21. I don't know why it is 21. Can somebody tell me?
Below is the code for the server:
#include "stdafx.h"
#include "winsock2.h"
void main()
{
// Initialize Winsock.
WSADATA wsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
{
printf("Error at WSAStartup()\n");
}
// Create a socket.
SOCKET m_socket;
m_socket = socket( AF_INET, SOCK_STREAM, 0 );
if ( m_socket == INVALID_SOCKET )
{
printf( "Error at socket(): %ld\n", WSAGetLastError());
WSACleanup();
return;
}
// Bind the socket.
sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr( "127.0.0.1" );
service.sin_port = htons( 60000 );
if ( bind( m_socket, (SOCKADDR*) &service, sizeof(service) ) == SOCKET_ERROR )
{
printf( "bind() failed.\n" );
closesocket(m_socket);
return;
}
// Listen on the socket.
if ( listen( m_socket, 1 ) == SOCKET_ERROR )
{
printf( "Error listening on socket.\n");
}
// Accept connections.
SOCKET AcceptSocket;
printf( "Waiting for a client to connect...\n" );
while (1)
{
AcceptSocket = SOCKET_ERROR;
while ( AcceptSocket == SOCKET_ERROR )
{
AcceptSocket = accept( m_socket, NULL, NULL );
}
printf( "Client Connected.\n");
m_socket = AcceptSocket;
break;
}
// Send and receive data.
int bytesSent;
int bytesRecv = SOCKET_ERROR;
char sendbuf[32] = "Server: Sending Data.";
char recvbuf[32] = "";
bytesRecv = recv( m_socket, recvbuf, 32, 0 );
printf( "Bytes Recv: %ld\n", bytesRecv );
bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
printf( "Bytes Sent: %ld\n", bytesSent );
return;
}
|
|
|
|
|
( sorry, I had two windows open, typed in the wrong one ).
Because the string you're passing in is that length, and you're passing in the result of strlen, which gives you that value.
I get the feeling you copied and pasted this from somewhere and have no real idea what it does, or even how C++ string handling works. If this is true, stop worrying about what you can cut and paste, and concentrate on learning the fundamentals of the language.
Christian Graus - Microsoft MVP - C++
-- modified at 22:04 Monday 5th September, 2005
|
|
|
|
|
Christian Graus wrote:
Because the string you're passing in is that length, and you're passing in the result of strlen, which gives you that value.
The length of the string he is sending is 21 (32 is the size of the array), I think that's why he is confsued when send returns 32?
-- modified at 7:19 Tuesday 6th September, 2005
oh forget it, he really wonders why the string length is 21.
|
|
|
|
|
Here length of the sendbuf is 21. send() function returns the number of bytes it is sended. thats why the value 21. recv() function returns the number of bytes received.
|
|
|
|
|
This is a simple socket communication program. here send() functions sends the data. and it retuns the number of bytes sended. in this length of the string sendbuf is 21. recv() function returns number of bytes received.
|
|
|
|
|
hello, i was wondering if there is an equivalent of the c# feature "properties" in c++. i.e., the client sees it as a variable, but methods are called to access it. You should understand from this c# sample:
<br />
namespace MyApp {<br />
public class TestClass {<br />
private int _item;<br />
<br />
TestClass(int tmp) {<br />
_item = tmp;<br />
}<br />
<br />
public int data {<br />
get {return _item;}<br />
set {_item = value;}
}<br />
<br />
static void Main() {<br />
TestClass x = new TestClass(17);<br />
int res = TestClass.data;
<br />
TestClass.data = 42;<br />
res = TestClass.data;
}<br />
}<br />
}
any equivalient in c++ ?
|
|
|
|