|
sorry but, when i read your code, i can't see anything beetween //#include and
, except the main header.
Visibly, you are missing some code, or the <> were understood as HTML tags by IE
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi All,
Does anybody know of any simple tools that can be used to find dead code in Visual C++ code? What I am interested in specificaly is something that could identify things like:
Member variables declared in a class that are never referenced.
Member functions declared in a class that are never referenced, ie could safely be commented outwith no effect on code.
Classes that are defined and implemented, but not referenced in a solution, which could be safely removed.
Old code has a tendency to grow by accretion, and it would be good to be able to have some tool that would help to trim dead code.
Thanks
|
|
|
|
|
I'm thinking that lint will do most, if not all, of what you require. It's been over a decade since I've used it but I remember it being a powerful ally.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
My first thought, also. I used to do just this with PC-Lint, and I think they have been keeping up with C++ and handling larger projects.
Check here: http://www.gimpel.com
I also use manual text file searching... slow but it gets the job done.
|
|
|
|
|
////////////////////////////////////////////////////////////////
code segments:
static int gnWSNotifyMsg = RegisterWindowMessage(__FILE__ ":wsnotify");
ON_REGISTERED_MESSAGE(gnWSNotifyMsg, OnWinsockNotify)
This is called when an event occurs:
OnWinsockNotify(WPARAM, LPARAM lParam)
/////////////////////////////////////////////////////////////////
I am looking at some code that gives notification when a network event occurs on a socket.
1. Can someone tell me what __FILE__ ":wsnotify" means in the code above?
2. When I get an event, a user defined function "OnWinsockNotify()" is called. What are WPARAM, LPARAM lParam in the argument list above?
Thanks.
Jerry
|
|
|
|
|
1/
__FILE__ is a macro defined by the compiler. It
will be equal to "myfile.cpp" for example.
So the command could be:
static int gnWSNotifyMsg = RegisterWindowMessage("myfile.cpp" ":wsnotify");
which is equivalent to:
static int gnWSNotifyMsg = RegisterWindowMessage("myfile.cpp :wsnotify");
which makes the string that little more likely to be unique.
2/ As it is a message defined by you, YOU tell other people / yourself what you want WPARAM & LPARAM to be!
Oftern wParam would be flags of some sort, and lParam would actually be a pointer to something. Or you may have wParam be a thread ID, lParam not used, and the message is posted when a worker thread is finished.
etc, etc.
As you know *why* a message was registered, you'll know what you want it to do!
Iain.
|
|
|
|
|
XP and 2K can display different images inside an exe icon,
do you know sizes of these images?
i.e. win 98 can display icon images in sizes of 16x16 and 32x32 pixels.
does XP and 2K support icon image of 64x64 pixels or more?
thx
includeh10
|
|
|
|
|
Hi,
How can retrieve, if the connection failed or timeout,
when I call Open method from CAsyncMonikerFile? Because
there is thrown no CFileException exception, e.g. when
I put URL, which doesn't exists.
|
|
|
|
|
How can I prevent a dialog from resize and move; and then enable.
Thanks for your responses.
|
|
|
|
|
Try processing this window message:
The WM_GETMINMAXINFO message is sent to a window when the size or position of the window is about to change. An application can use this message to override the window's default maximized size and position, or its default minimum or maximum tracking size.
If you set both sizes the same, I am pretty sure your window's size will not adjust. You just make its minimum and maximum size the same. I have not tested this exact behavior, however, it is just the first idea that came to mind.
|
|
|
|
|
Thanks for your response.
It will be very helpfull.
|
|
|
|
|
I am trying to make a map of a file ant then write it in another file
but I cannot do it I get an error when writing can you please tell me why ?
HANDLE hMapFile,hFile;<br />
<br />
hMapFile=CreateFile("c:\\fish.txt",<br />
GENERIC_READ|GENERIC_WRITE|0,<br />
FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE,<br />
NULL,<br />
OPEN_EXISTING,<br />
FILE_ATTRIBUTE_NORMAL,<br />
NULL);<br />
<br />
hFile = CreateFileMapping(hMapFile,
NULL,
PAGE_READWRITE,
0,
0,
"MyFileMappingObject");
<br />
if (hMapFile == NULL) <br />
{ <br />
MessageBox(NULL,"error","",MB_OK);<br />
} <br />
LPVOID file;<br />
<br />
DWORD length;<br />
length=GetFileSize(hMapFile,0);<br />
<br />
file=(char *)malloc(length);<br />
file=MapViewOfFileEx(<br />
hFile,
FILE_MAP_ALL_ACCESS,<br />
0,
0,
sizeof(hFile),
0<br />
);<br />
<br />
<br />
FILE *gabby;<br />
gabby=fopen("c:\\out.txt","w");<br />
fprintf(gabby,"%s",file);<br />
fclose(gabby);<br />
?????
gabby
|
|
|
|
|
You could always help us be telling us what the error you are getting is!
At a quick glance, you check the value of hMapFile after you use it to create a mapped object, but never check the return value of CreateFileMapping.
You may simply be using hFile & hMapFile the wrong way round in some places...
When you are debugging line by line, you can put
err,hr
in the watch window to see why functions are failing.
Iain.
|
|
|
|
|
man the thing is that there is a problem when trying to write , the rror is exactly when trying to write the lpvoid in the file. I don't know why?
WriteFile() also does not work.
but let me give you a hint first.
if write this line before writeing to the file
file=(char *)malloc(length); the code works fine but the file is full of null caracters
try the code yourself . . .see if you can do anyting
gabby
|
|
|
|
|
I´m writing an application that is communicating with an external device through the serial port (programming in VC++ .net with createfield etc). I am sending some characters to the device, end expect to get an answer. The problem is that I always get more characters back than I should.
I expect the characters “22001C” however, depending on the values of WriteTotalTimeoutMultiplier and WriteTotalTimeoutConstant I get replies like: “222001C” , “220001C” and “220011C” , always a character too much.
I think it is a problem with the timeout configurations, but I´m not sure, as I am just a beginner to c++.
Does anybody have a clue as to what might be the problem, and how to solve it ??
Best regards
doneirik
|
|
|
|
|
If there is a problem with the data reception, I doubt the problem has anything to do with the timeout values for writing.
If the received data differs depending on your writing timeout values it's more likely you have a timing problem accessing the port.
If you have opened the port non-overlapped a reading operation will prevent a writing operation until it reaches its timeout and vice versa.
Are you sure that no other signals have to be manipulated such as DTR and/or RTS? Usually they have, try with HyperTerminal which sets both RTS and DTR to active state if you select no handshaking.
This is easily done with the DCB struct and SetCommState.
To nail down the real problem, try this:
1. Do not use read/write timeouts. MSDN tells you how to set this up.
2. Connect to another PC or COM-port and open it with HyperTerminal, see if you can receive expected data sent from HT.
Alternate 2: create a loop-back by connecting Rx and Tx (pin 2 and 3) and see if you can read the data you are sending.
Hope this helps
--
Roger
|
|
|
|
|
Hi all,
Is it necessary to delete an object by calling
delete object;
or the object will be automatically deleted if there's no variable assigned to it?
Thanks in advance for your help.
|
|
|
|
|
yes.
if there's no variable assigned to it?
more so in that case ... me think that if you have allocated objects hanging around, you would need to clean them up.
how do you have them ? calling a function that allocates something and return it and you don't use it ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
if you use new you call delete ALWAYS.
Even better would be to do this:
Object *x = new Object();<br />
<br />
<br />
delete x;<br />
x = NULL;
This way you do not accidentally call x that points to something else than Object. (because the memory to which the pointer points to is overwritten)
good luck.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
V. wrote:
if you use new you call delete ALWAYS.
wrong. Windows can do it itself, but that's a very bad way to program...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
ok I correct myself:
If you're a good programmerand if you use new you call delete ALWAYS
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
|
toxcct wrote:
Windows can do it itself...
Only if the application exits or is terminated. Things like services are designed to run for long periods of time so a call to delete is a requirement.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thank you for your help.
Another related question..
if I have the class:
class ObjectA
{
ObjectB b;
}
ObjectA a = new objectA();
When i detele ObjectA (delete a), do I have to delete ObjectB (delete b)? or is it implicitly deleted?
|
|
|
|
|
And in the following case:
I have
ObjectA a = new ObjectA();
//...
Do I have to delete a (delete a) before I create a new ObjectA and assign it to a??
a = new ObjectA();
|
|
|
|