|
Vaclav_Sal wrote: And it fails if the destination buffer is smaller than the source buffer.
Who'd a thunk it?
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
I wondered why it was so fast.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hi all,
i m using atoi function to convert string value to its coressponding integer value.
when i convert "22 dollar" its return 22 but when i convert "dollar 22" its return 0.
how can i get 22 also here.
please help me for this .
thank in advance.
|
|
|
|
|
Iterate through the string and check for numerals using the isdigit function.
Once you get to a digit, continue iteration and save all characters to another array till you do not find a digit.
|
|
|
|
|
The atoi() function (see the MSDN documentation[^]) will stop scanning at the first non-numeric character it encounters. In the case of the string "dollar 22" you first need to adjust your pointer to skip all the characters in front of the number.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Additionally to what the others said, you can use strpbrk[^] to find the first alphanumeric character inside your string and then use atoi on that to convert.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
I have an EXE class which contains a button resource with ID EXE_BUTTON_RESOURCE
ON_UPDATE_COMMAND_UI(EXE_BUTTON_RESOURCE, OnUpdateExeButtonResource)
void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
{
pCmdUI->Enable(exe_flag);
}
This EXE application will load another DLL class.
DLL class is having a menu item resource with ID DLL_MENU_RESOURCE.
Unfortunately, EXE_BUTTON_RESOURCE and DLL_MENU_RESOURCE is having the same resource ID. To avoid them have conflict ID is pretty difficult, as they are two separate projects.
Whenever exe_flag, which is the member for EXE turn to false, this will affect menu in DLL too. Clicking on DLL_MENU_RESOURCE menu will have no effect at all.
How can I avoid this trap? Having manual inspection on their resource.h files is not an option for me, as they are 2 separate projects, managed by 2 separate teams.
|
|
|
|
|
Try adding the following statement as the first line in every exported function of the DLL.
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
|
|
|
|
Do you mean code like this ?
void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
pCmdUI->Enable(exe_flag);
}
No. It doesn't work. Clicking on DLL's menu item will still have no effect.
Is changing
#define DLL_RESOURCE_ID 1234
to
const int DLL_RESOURCE_ID = ::RegisterWindowMessage(_T("DLL_RESOURCE_ID"));
a elegant solution (To avoid resource ID conflict)? I don't know.
|
|
|
|
|
I meant adding in the DLL's code, not the EXE's.
|
|
|
|
|
I cannot use your suggestion as I am using extension DLL.
http://support.microsoft.com/kb/161589
However, I already did a similar thing even before your suggestion.
void DLL::OnContextMenu(CWnd* pWnd, CPoint point)
{
RestoreDLLState ext;
...
}
RestoreDLLState will load global DLL resource, and load back its original resource once done.
RestoreDLLState::RestoreDLLState()
{
m_hInstOld = AfxGetResourceHandle();
AfxSetResourceHandle(g_hResource);
}
RestoreDLLState::~RestoreDLLState()
{
AfxSetResourceHandle(m_hInstOld);
}
It doesn't work.
|
|
|
|
|
The RegisterWindowMessage Function (Windows)[^] defines a new window message that is guaranteed to be unique throughout the system, and is designed to generate at runtime message IDs that could be used for inter-process communications: using it solve your problem, but it could not be a good idea if you use it extensively, because it waste system resources.
Anyway, the changement you are evaluating, requires that you manually modify the resource.h file on your project to remove the correspondant #define and produce a situation where the resource editor is not able to load and handle your resource script file (i.e. project_name.rc), then you should modify it manually.
|
|
|
|
|
Hi gang,
I've got a custom control (m_HScrollBar1Ex ) which I have made appear over a CTreeView derived interface (CLeftView ) which moves up and down with the CTreeView object's scrollbar moderately well with a call to my control-positioning function PlaceScrollBar in the OnVScroll function. However, the custom control only 'snaps' in to its final position when the left mouse button is released. Ideally I'd like the control to move in absolute synch with the graphics underneath it (ie. the tree control).
Is there another message I could respond to which will allow the custom control to draw itself in the right place before the mouse button is released?
I'm guessing that the answer is a bit more involved than this - in which case any clues that you can give me will be very much appreciated.
Very much looking forward to your replies,
Ben.
void CLeftView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if (m_HScrollBar1Ex.m_hWnd != NULL){
m_HScrollBar1Ex.ShowWindow(SW_HIDE);
}
PlaceScrollBar();
CTreeView::OnVScroll(nSBCode, nPos, pScrollBar);
}
<pre>
and
<pre>
void CLeftView::PlaceScrollBar(void)
{
if (m_bBlockScrollDraw==FALSE){
CRect parentRect;
CTreeCtrl &ctlFolders = this->GetTreeCtrl();
ctlFolders.GetWindowRect(&parentRect);
ScreenToClient(&parentRect);
CRect contRect;
HTREEITEM hRoot;
HTREEITEM hFolder;
hRoot = ctlFolders.GetSelectedItem();
CRect heightRect;
int count=0;
int yPos=0;
CRect itemRect;
if (ctlFolders.ItemHasChildren(hRoot))
{
HTREEITEM hNextItem;
HTREEITEM hChildItem = ctlFolders.GetChildItem(hRoot);
CWnd * pChild = (CWnd *) &hChildItem;
count = 1;
if (ctlFolders.IsTopParentActive()){
DWORD dwData = ctlFolders.GetItemData(hRoot);
m_dw08bCurNodeVisItems = (dwData & 0x000000FF);
m_dw24bCurNodeScrollPos = (dwData & 0xFFFFFF00) >> 8;
}
else m_dw24bCurNodeScrollPos = 99;
ctlFolders.GetItemRect(hChildItem, itemRect, FALSE);
while (hChildItem != NULL)
{
hNextItem = ctlFolders.GetNextItem(hChildItem, TVGN_NEXT);
if (hNextItem != NULL){
count++;
}
hChildItem = hNextItem;
}
}
if (m_HScrollBar1Ex.m_hWnd != NULL && m_intChildCount > m_dw08bCurNodeVisItems){
m_HScrollBar1Ex.SetScrollRange(1, m_intChildCount-m_dw08bCurNodeVisItems+1);
if (m_dw24bCurNodeScrollPos == 0)
m_HScrollBar1Ex.SetScrollPos(1) ;
else
m_HScrollBar1Ex.SetScrollPos(m_dw24bCurNodeScrollPos);
m_HScrollBar1Ex.GetWindowRect(&contRect);
ScreenToClient(&contRect);
contRect.MoveToX(parentRect.right-contRect.Width()-16);
m_HScrollBar1Ex.SetWindowPos(&wndTop,contRect.left,itemRect.top,
contRect.Width(),count*ctlFolders.GetItemHeight(),SWP_SHOWWINDOW);
}
}
}
|
|
|
|
|
Hi,
1. I have written a very simple socket server.
2. It listens in post 63254.
3. First i did a socket_create, socket_bind, socket_listen so here a connection is listening.
4. Then in a loop i do the socket accpet. so here another listen.
5. the read function reads untill i input exit.
6. after that the resource id by socket_accept closes.
7. and then the main connection closes.
when i checked this process in TCPview after closing all connections i can still see the system process showing TIME_WAIT for post 63254
if i again run the socket server program it is connecting and when one full process is over all the connection is closed and the program terminated and now i can see another TIME_WAIT for the same port. but still i could connect to the same port the third time.
in stackover question answer it is said that connection cannot be done for port which is in wait state.
I opened firefox browser it opened 4 connections. when i closed it all closed and the system process showed 4 time waits for 2 minutes. all time wait stays for 2 minutes and disappears.
so what i conclude is for every connection close the time wait is occurs and cannot be avoided.
i read many posts in stack overflow flow but still wasn't sure of it.
i run the following code in command line.
My server Code
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
$str = '';
$buff = '';
$s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if(!$s)die('Unable to create socket');
if(!socket_bind($s,'127.0.0.1',63254))
die("\nTrying to Bind: ".socket_strerror(socket_last_error()));
if(!socket_listen($s,1))
die(socket_strerror(socket_last_error()));
while(1)
{
$acc = socket_accept($s);
if(!$acc)die(socket_strerror(socket_last_error()));
if(!$acc)die(socket_strerror(socket_last_error()));
while(1)
{
$str = socket_read($acc,512);
$buff.= $str;
echo $str;
if($str===false)die(socket_strerror(socket_last_error()));
if($str=="exit\r\n")break;
}
socket_close($acc);
if(preg_match('/exit/',$buff))break;
}
socket_close($s);
The client code
set_time_limit(0);
$f = fsockopen('127.0.0.1',63254,$a,$b,10);
if(!$f)die('cannot connect');
echo "\nConnected: \n";
do{
$buff = fgets(STDIN);
fwrite($f,$buff);
}while($buff!="exit\r\n");
fclose($f);
The code is written for php but it is exactly like c so people can understand without doubts. so i posted here.
I would like to have any kind of reply related to my question.
I have also discussed about this earlier in here...
if this still exists then just have a look into it.
http://stackoverflow.com/questions/3811067/socket-program-is-able-to-connect-to-the-port-which-is-still-in-time-wait[^]
http://vikku.info/ Today's Beautiful Moments are
Tomorrow's Beautiful Memories
modified on Wednesday, October 6, 2010 2:57 AM
|
|
|
|
|
Jayapal Chandran wrote: when i checked this process in TCPview after closing all connections i can still see the system process showing TIME_WAIT for post 63254
The server socket will always show LISTENING state while running. Incoming connections, which the server has accepted and then have been closed, might end up having TIME_WAIT state for a while. This is an important part of TCP's reliability, it serves multiple purposes and should never be defeated. A networking book will give you more details why this is important. From a practical point of view, sockets are connections between two endpoints and not both socket will have the TIME_WAIT state, normally only one will enter it, it depends on which endpoint performs the active close. In my network applications I usually design the protocol so that the clients get the TIME_WAIT , by letting the clients close the connection to the server.
On Windows or Linux you can see server and client connections with:
netstat -an
The following shows a chat server, a connected client and a closed client:
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:9009 0.0.0.0:0 LISTENING
TCP 127.0.0.1:2302 127.0.0.1:9009 ESTABLISHED
TCP 127.0.0.1:2279 127.0.0.1:9009 TIME_WAIT
Here is a little tip, the connection list is easier to read if you run server and clients on two different computers.
Hope this helps!
|
|
|
|
|
ahh, there it is. now i understood about the time wait. nice. thank you.
was that stackoverflow link stating the same like your answer?
just in case if you have read that.
|
|
|
|
|
Jayapal Chandran wrote: was that stackoverflow link stating the same like your answer?
Yes, EJP gives pretty much the same answer. Happy coding!
|
|
|
|
|
That's nice of you. Thank you for your time to check that.
|
|
|
|
|
I have a Process A and a Process B. From Process A i am creating a remoteThread in Process B. Now i want to hook exitProcess function in process B.
I want to hook ExitProcess and write MyExitProcess. In MyExitProcess i want to take a decision whether to exit process B or not.
Can anyone please help me with this..
|
|
|
|
|
|
I'v downloaded "BasicExcel" to hanlder my Excel operation.But it meets some problem.
Sometimes,BasicExcel.Load collapse,it seems to have some relation with the Excel file.The file size is not the reason,because I have tested that.
If that case happened,open the file,then save,and redo BasicExcel.Load ,it's OK!
Does the BasicExcel have some bugs?
|
|
|
|
|
You should post your question in the forum at the end of the article so that the author gets notified.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
BasicExcel works best with MS Excel 2003.
If problem is not resolved then :
[1]create a new Excel file in MS Excel 2003 format.
[2]copy your content in newly created file.
[3]select all the content and choose Arial as the font type.
[4]save
[5]remove read only flag(if at all applicable)
[6]run the code.
these are the steps I followed when i faced similar problem and it worked.
Sameer();
|
|
|
|
|
Hello,
I am trying to compare 2 dates and find out which one is greater. The second date is current date.
It is not working. Below is full program code :
<br />
#include <stdio.h><br />
#include <conio.h><br />
#include <time.h><br />
<br />
void CompareDates();<br />
<br />
void main()<br />
{<br />
CompareDates();<br />
getch();<br />
}<br />
<br />
<br />
void CompareDates() <br />
{<br />
int year = 2010;<br />
int month = 12;<br />
int day = 31;<br />
<br />
time_t rawtime1;<br />
time(&rawtime1);<br />
time_t rawtime2;<br />
time(&rawtime2);<br />
<br />
struct tm * timeinfo1;<br />
timeinfo1 = localtime(&rawtime1);<br />
struct tm * timeinfo2;<br />
timeinfo2 = localtime(&rawtime2);<br />
<br />
timeinfo1->tm_year = year - 1900;<br />
timeinfo1->tm_mon = month - 1;<br />
timeinfo1->tm_mday = day;<br />
mktime (timeinfo1);
<br />
char buffer1 [80];<br />
strftime (buffer1,80,"timeinfo1 : %c.",timeinfo1);<br />
puts (buffer1);<br />
<br />
char buffer2 [80];<br />
strftime (buffer2,80,"timeinfo2 : %c.",timeinfo2);<br />
puts (buffer2);<br />
<br />
if(timeinfo1 > timeinfo2) <br />
{<br />
puts("more");<br />
}<br />
else <br />
{<br />
puts("less");<br />
}<br />
}<br />
Your guidance is very much appreciated.
Thanking you in advance,
Goutam
|
|
|
|
|
ggoutam7 wrote: if(timeinfo1 > timeinfo2)
You are comparing pointers ("timeinfo1" & "timeinfo2") and not the actual content pointed to by these pointers.
|
|
|
|