|
cedric moonen wrote:
Hhhmm, yep, but don't forget that _tcstok will modify the contains of the string !
Yeah, which is why I made a copy of it first
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I think I'm tired !
|
|
|
|
|
cheers Ryan,
works a treat
si
|
|
|
|
|
You're welcome
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Such, an Idea!
int pos=0;
int last=-1;
CString help;
while(pos!=-1)
{
pos=mystring.Find(",",last);
for(int i=last+1;i
|
|
|
|
|
I use the undocumented function AfxExtractSubString() . It's slower than a proper solution, but I haven't had to do time-critical stuff. The function is declared like:
BOOL AfxExtractSubString(CString& rString, LPCTSTR lpszFullString, int iSubString, TCHAR chSep); rString is the output stringlpszFullString is your input stringiSubString is the number of the substring you want to get (0, 1, 2...)chSep is the separator character, ',' in your case Just do something like this:
CString str;
int i = 0;
while(AfxExtractSubString(str, mystring, i++, _T(',')))
{
} Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
would it be easier to make it a vector of strings?
*.*
|
|
|
|
|
The program below compiles with no errors and seems to run ok, but it doesn't work properly. When I enter in one of the 13 digit numbers stored in the array, I get back a message saying that the number I input is NOT in the array (but it is). What do I need to change?
Thanks, Dave
-------------------------------------------------------
#include "stdio.h"
#include "math.h"
#include "iostream.h"
#include "stdlib.h"
double values[] = {5758020005287, 7937030006574, 4748020008574,
4847020007584, 9500020004758, 3849573800596 ,5758020005007,
7557030006574, 4745520008574, 4847020005584, 9585520004758,
3849573846696 ,3748596078661 , 4615243374995 , 1115364759770};
int compare (const void * a, const void * b)
{
#define ABS(a) ((a) < 0 ? -(a) : (a) )
double _a = *(double*)a;
double _b = *(double*)b;
if( ABS(_a - _b) < 0.00000001 )
return 0;
else if( _a < _b)
return -1;
else
return 1;
}
int main ()
{
double * pItem;
cout<<"please enter a number"<<endl;
double="" key;
cin="">>key;
pItem = (double*) bsearch (&key, values, 15, sizeof (double), compare);
if (pItem!=NULL)
printf ("%lf is in the array\n",*pItem);
else
printf ("%lf is not in the array\n",key);
return 0;
}
VC++ 6.0
|
|
|
|
|
|
From the documentation:
Performs a binary search of a sorted array.
|
|
|
|
|
Thanks, that did the trick.
|
|
|
|
|
How can I get a list of window handles for a running process?
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
EnumWindows, EnumChildWindows and GetWindowThreadProcessId
Magnus
|
|
|
|
|
GetWindowThreadProcessID was what I was looking for.
Thanks a lot
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
This is a pipe-like class written in standard c.Read() and Write()can critically access the inner data section.When there is no data to be read,Read() will block and wait for Write() to write some data to the pipe.Only when
it reads datas does Read() return.
The inner data section are block structures using new operator to calloc units.
/*--------------------------------------------------------
* Pipe.h: interface for the CPipe class.
*
* 2003 DJ Express Studio All rights reserved
*------------------------------------------------------*/
#ifndef _PIPE_H_
#define _PIPE_H_
/* CRITICAL_SECTION was defined in winbase.h
* possibly not compatible with stdafx.h */
#include <Winbase.h>
#define BL_ERROR -1
#define BL_OK 0
struct Block
{
PBYTE pData;
int data_len;
Block* next;
Block* pre;
};
class CPipe
{
private:
CRITICAL_SECTION cs;
HANDLE hEvent;
Block* pBuffer;
Block* pHead;
Block* pTail;
int pointer;
int nBlocks;
public:
void CPipe::EmptyPipe();
int Write(BYTE* buf, int len, int* write);
int Read(BYTE* buf, int len, int* read);
bool IsEmpty();
CPipe()
{
pHead=NULL;
pTail=NULL;
nBlocks=0;
pointer=0;
InitializeCriticalSection(&cs);
hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
};
virtual ~CPipe()
{
CloseHandle(hEvent);
DeleteCriticalSection (&cs);
};
};
#endif
/*---------------------------------------------------
* Pipe.cpp: implementation of the CPipe class.
*
* 2003 DJ Express Studio All rights reserved
*-------------------------------------------------*/
#include "Pipe.h"
int CPipe::Write(BYTE* buf,int len,int* write)
{
Block* pTem;
if(!buf || len <=0 )
goto error;
pTem=NULL;
if(!(pTem=new Block))
goto error;
if(!(pTem->pData=new BYTE[len]))
goto error;
else
{
/* lock the pipe */
EnterCriticalSection(&cs);
pTem->data_len=len;
memcpy(pTem->pData,buf,len);
nBlocks++;
pTem->pre=NULL;
if(pHead==NULL)
pTail=pTem;
else pHead->pre=pTem;
pHead=pTem;
/* unlock the pipe */
LeaveCriticalSection(&cs);
}
*write=len;
SetEvent(hEvent);
return BL_OK;
error:
*write=0;
return BL_ERROR;
}
int CPipe::Read(BYTE* buf,int len,int* read)
{
int total;
Block* tem;
if(!buf || len <= 0 )
goto error;
if( nBlocks <= 0 )
{
WaitForSingleObject(hEvent,INFINITE);
ResetEvent(hEvent);
}
/* lock the pipe */
EnterCriticalSection(&cs);
if(len < pTail->data_len )
{
pointer = len;
memcpy(buf,pTail->pData,len);
*read = len;
}
else
{
total=0;
tem=NULL;
while(len-total)
{
if(len-total >= pTail->data_len )
{
memcpy(buf+total,pTail->pData,pTail->data_len);
total += pTail->data_len;
tem = pTail;
pTail=pTail->pre;
pointer = 0;
delete []tem->pData;
delete tem;
}
else
{
memcpy(buf+total,pTail->pData,len-total);
total = len;
pointer = len - total;
break;
}
if(--nBlocks <= 0)
{
pTail=NULL;
pHead=NULL;
break;
}
}
*read = total;
}
/* unlock the pipe */
LeaveCriticalSection(&cs);
return BL_OK;
error:
*read=0;
return BL_ERROR;
}
bool CPipe::IsEmpty()
{
return nBlocks > 0 ? false : true ;
}
void CPipe::EmptyPipe()
{
Block* tem;
if(nBlocks <= 0)
return;
/* lock the pipe */
EnterCriticalSection(&cs);
while(nBlocks--)
{
tem=pTail;
pTail=pTail->pre;
delete []tem->pData;
delete tem;
tem=NULL;
}
pHead=pTail=NULL;
/* unlock the pipe */
LeaveCriticalSection(&cs);
}
/*---------------------------------------------------------*/
|
|
|
|
|
hi,
i have a program written that reads a flat text tab separated file using ODBC ,the database
contains various number and text columns.Using VC++ classwizard, i created my CRecordset derived class and the type of member-variables corresponding to the text columns is CString .My problem is that i am able to connect and open the database and fetch all the records i want by fetching the recordsets in loop, but i couldn't read all but first text columns and when i try to read them ,it gives exception.All other columns of type number are read correctly for all records.Surprisingly the first text column field is also read correctly but the subsequent fields are not.
While debugging ,when i see the value of these string member-variables of the recordset ,it says CXX0033:ERROR: error in OMF type information.
Can anybody give some suggestions.
|
|
|
|
|
|
Simply wait. Be sure that if someone has a solution, it will post it here. But do not be too insistant, this usually is the best way to get no answer.
~RaGE();
|
|
|
|
|
Hi,
In a dialog based application, i have a AfxBeginThread function
to write some data to make a multi-session CD.
between the first session and the second session i need the thread wait a some seconds until the lead-out of first session be written.
Anyone can point me which wait function is useful for this purpose? For example,
Sleep(100); or
WaitForSingleObject(pThread->m_hThread, 100)
or others.
Thanks in advance!
chen
|
|
|
|
|
If you just want to wait a number of seconds, use Sleep
If you want to wait on an event that is triggered from another thread, use CreateEvent and then WaitForSingleObject.
If you want to wait on another thread to finnish use WaitForSingleObject(pThread->m_hThread, INFINITE)
Magnus
|
|
|
|
|
If you just want to pause for a while, use Sleep() .
Your second suggestion is for waiting for the thread object to be signalled, which it is when the thread completes execution (i.e. returns from the thread function, or calls ExitThread ). In the code you've written, the call to WaitForSingleObject will return WAIT_OBJECT_0 if the thread exits before the 100ms delay is up, or WAIT_TIMEOUT if the 100ms delay expires first.
Typically you would only wait for a thread if that thread is doing something blocking that you don't want to run on the current thread. I haven't found a way, for example, of setting a timeout value for the InternetConnect function, so I launch another thread whose sole job is calling InternetConnect , then I wait on the thread handle for the desired timeout period. If the thread isn't signalled within the timeout, I assume it's going to fail and shut down the WinInet session.
Normally you'd never wait on your own thread handle, unless you're trying to use a function that requires a wait handle, but you actually want different behaviour. For example, I've needed to be able to call GetMessage with a timeout, but no such function exists. I had to call MsgWaitForMultipleObjects , but that requires at least one wait handle.
I would question whether you should be waiting: it's not really an exact science - you'll get some situations where your wait isn't long enough, due to race conditions. Is there no way to find out when the first session has been written?
--
Mike Dimmick
|
|
|
|
|
Hi, Magnus and Mike,
Thanks for reply.
I have try to the following to methods in the loop
for(session=1; session<=2; session++)
{
....
....
here a command will tell the cd-driver, the first session data finished
and then the driver write the leadout datd (now i need the thread do nothing until the leadout finished) ...
Method_1 or Method_2
}
Method_1:
while(ts->m_CD.test_unit_ready() != 1) //unit not ready
Sleep(100);
Method_2:
while(ses != 2)
{
if(WAIT_OBJECT_0 == WaitForSingleObject(ts->pThread->m_hThread, 100))
{
ResetEvent(ts->pThread->m_hThread);
}
if(ts->m_CD.test_unit_ready() == 1)
{
SetEvent(ts->pThread->m_hThread);
break;
}
}
It seems both method cannot work.
any ideas?
chen
|
|
|
|
|
Why cant Method_1 work?
If you cant tell the CD to call you back when its finnished, then you will have to do polling.
Magnus
|
|
|
|
|
Hi,
I have to develop some software wich will use the command line for input, after that the GUI will be shown with the information provided in the command line already displayed (in textBoxes etc.).
Can someone tell me how to do this?
Thank you in advance
|
|
|
|
|
Derive your own class from CCommandLineInfo. THen override ParseParam to parse the command line arguments. In your applications InitInstance write
// Parse command line for standard shell commands, DDE, file open
CYourCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
After that, you have the information in member variables of cmdInfo that you must have created. Or perhaps within ParseParam you could have stored the information wherever you want..
|
|
|
|
|