|
well, nowe-now is -3 , then cast it to unsigned ...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
gregarion wrote: when i tried running this , i got the result displaying (4294967295 ). why is this?
Perhaps because f (and result ) is -3 .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
gregarion wrote: What i would like to do is to be able to input a number and using that number as the index
What about:
int index;
cin >> index;
string::size_type loc2 = s.find("yht", index);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thanks guys, i got it. the issue was i thought that the output will start counting from the index i told it to. it only searches starting on the index, but output will be based from counting from the start of the file. Thanks!
|
|
|
|
|
Hallo,
I need to determine the current installed language of the os in Visual C++ 6.
Can someone help me? With which class I can get this value? Is it saved in the registry?
Thank you for helping me!
|
|
|
|
|
See the section here[^] on Locales and other regional options.
MVP 2010 - are they mad?
|
|
|
|
|
|
there is a problem existed in window7 and vista, if we set the autorange for the desktop application, that we can't send LVM_SETITEMPOSITION message, or it'll always return FALSE, why? it can take effect in windows xp.
|
|
|
|
|
The MSDN documentation[^] states:
On Windows Vista, sending this message to a list-view control with the LVS_AUTOARRANGE style does nothing, and the return value is FALSE.
I think you will need to talk to Microsoft for an explanation.
MVP 2010 - are they mad?
|
|
|
|
|
|
so, i can't exchange the position of the list items with the LVS_AUTOARRANGE style, my god.
|
|
|
|
|
That sounds quite reasonable if you have specified that they should be arranged automatically.
MVP 2010 - are they mad?
|
|
|
|
|
but it can exchange items' position if you dragging the icon on the desktop within the application of explorer.exe, i want to have the utility in my own application, how can i do? thanks in advance
|
|
|
|
|
Well I guess you need to suppress the auto arrange feature and implement it within your own code so that it looks the same. I have no idea how explorer does this, you might try asking Microsoft.
MVP 2010 - are they mad?
|
|
|
|
|
thanks for your advice 
|
|
|
|
|
Hi,
I need to create a process like
LPTSTR szCmdline[] = TEXT("ffmpeg -i " + ofn.lpstrFile + " -r 1 -ss 00:00:10 -vframes 1 -f image2 " + Buffer + "\\Initframe10.bmp");
For this I will be using CreateProcess API but problem is how to convert TCHAR to a LPTSTR lpCommandLine to be passed to CreateProcess?
ofn.lpstrFile (LPTSTR type) is obtained as outcome of GetOpenFileName API Call and Buffer (TCHAR type) is obtained as GetTempPath.
I get compilation errors which I am not able to fix. (I am new to Win32 programming so this may sound naive).
Can someone please help me in fixing the errors?
Thanks
modified on Thursday, January 28, 2010 7:30 AM
|
|
|
|
|
|
Thanks, I have gone over first link and is really informative.
I will go over second link now.
|
|
|
|
|
I'm glad it helped you.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
WideCharToMultiByte() function can be used for conversion. You can also use a _bstr_t class which has an operator char* which can convert unicode to char*
|
|
|
|
|
As well as the other suggestions you should study the basics of arrays and pointers in C and how they are used.
MVP 2010 - are they mad?
|
|
|
|
|
Dear all,
I have a question about Winsock.
My program is a TCP client which manipulates lots of socket connection concurrently.
One socket for each thread.
I use blocking mode at most of time, except creating a new connection to server.
I turn socket into non-blocking mode first, then use select() to check the socket before turning back.
I really don't want to waste time on uncertain blocking timeout and make sure the connection is established in the specific time.
Everything works well when most of server are reachable.
But here comes the question.
If the number of unreachable server increases(more than 5), the rest reachable server will fail on creating connection.
In this case, select() always return 0(means timeout) even though the server is originally reachable.
Here is the portion of my program to create connection:
Open(LPCTSTR addr, int port, DWORD dwTimeout)
{
_socket = 0;
SOCKET theSocket;
int nRet;
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(addr);
if (lpHostEntry == NULL) {
return;
}
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (theSocket == INVALID_SOCKET) {
return;
}
unsigned long ul = 1;
nRet = ioctlsocket(theSocket, FIONBIO, (unsigned long*)&ul);
if (nRet == SOCKET_ERROR) {
closesocket(theSocket);
return;
}
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(port);
nRet = connect(theSocket,
(LPSOCKADDR)&saServer,
sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) {
closesocket(theSocket);
return;
}
struct timeval timeout;
fd_set r;
FD_ZERO(&r);
FD_SET(theSocket, &r);
timeout.tv_sec = dwTimeout / 1000;
timeout.tv_usec = (dwTimeout % 1000) * 1000;
nRet = select(0, 0, &r, 0, &timeout);
if (nRet <= 0 ) {
closesocket(theSocket);
return;
}
ul= 0;
nRet = ioctlsocket(theSocket, FIONBIO, (unsigned long*)&ul);
if (nRet == SOCKET_ERROR){
closesocket(theSocket);
return;
}
_socket = theSocket;
}
Is there anything wrong in this code?
Or any constraint on the number of unreachable socket select() concurrently in multithread?
|
|
|
|
|
luderjane wrote: I use blocking mode at most of time, except creating a new connection to server.
I turn socket into non-blocking mode first, then use select() to check the socket before turning back.
Just an idea, you could use a "master thread" to check for timeouts and close socket handles. This should make threads return from blocking connect() calls if necessary... and you can remove the select-timeout-code (untested).
/M
|
|
|
|
|
 I wrote a simple testbed to exclude other factor in my program as follows(builds in VC2005, must depends on Ws2_32.lib):
#include <stdio.h>
#include <tchar.h>
#include <Winsock2.h>
typedef struct ServerInfo {
char sIP[32];
int iPort;
DWORD dwTimeout;
BOOL bPrintable;
} ServerInfo, *pServerInfo;
DWORD WINAPI OpenThreadProc(void* lpParam);
void BlockingOpen(pServerInfo pServer);
void NonBlockingOpen(pServerInfo pServer);
int _tmain(int argc, _TCHAR* argv[])
{
int iNumOfURServer = 0;
char sIP[32];
int iPort = 80;
DWORD dwTimeout = 5000;
printf("Number of unreachable server: ");
scanf("%d", &iNumOfURServer);
printf("Reachable server IP: ");
scanf("%s", sIP);
printf("Reachable server port: ");
scanf("%d", &iPort);
printf("Timeout(in millisecond, 0 indicates blocking mode): ");
scanf("%u", &dwTimeout);
WSADATA wsaData;
WORD version = MAKEWORD(2,2);
WSAStartup(version, &wsaData);
pServerInfo ServerArray = new ServerInfo[iNumOfURServer+1];
char sURIP[32];
for (int i = 0; i < iNumOfURServer; i++)
{
sprintf(sURIP, "192.168.1.1%02d", i);
strcpy_s(ServerArray[i].sIP, sURIP);
ServerArray[i].iPort = 3456;
ServerArray[i].dwTimeout = dwTimeout;
ServerArray[i].bPrintable = FALSE;
CreateThread(NULL, 0, OpenThreadProc, &ServerArray[i], 0, NULL);
}
strcpy_s(ServerArray[iNumOfURServer].sIP, sIP);
ServerArray[iNumOfURServer].iPort = iPort;
ServerArray[iNumOfURServer].dwTimeout = dwTimeout;
ServerArray[iNumOfURServer].bPrintable = TRUE;
CreateThread(NULL, 0, OpenThreadProc, &ServerArray[iNumOfURServer], 0, NULL);
scanf("%d", &iPort);
return 0;
}
DWORD WINAPI OpenThreadProc(void* lpParam)
{
pServerInfo pServer = (pServerInfo)lpParam;
while (true)
{
if (pServer->dwTimeout == 0)
{
BlockingOpen(pServer);
}
else
{
NonBlockingOpen(pServer);
}
Sleep(1000);
}
return 0;
}
void BlockingOpen(pServerInfo pServer)
{
SOCKET theSocket;
int nRet;
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(pServer->sIP);
if (lpHostEntry == NULL) {
return;
}
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (theSocket == INVALID_SOCKET) {
return;
}
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(pServer->iPort);
DWORD dwStartTime = GetTickCount();
nRet = connect(theSocket,
(LPSOCKADDR)&saServer,
sizeof(struct sockaddr));
if (pServer->bPrintable)
{
if (nRet == SOCKET_ERROR)
{
printf("%s:%d blocking open failed takes %d ms\n", pServer->sIP, pServer->iPort,
GetTickCount()-dwStartTime);
}
else
{
printf("%s:%d blocking open successful takes %d ms\n", pServer->sIP, pServer->iPort,
GetTickCount()-dwStartTime);
}
}
closesocket(theSocket);
}
void NonBlockingOpen(pServerInfo pServer)
{
SOCKET theSocket;
int nRet;
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(pServer->sIP);
if (lpHostEntry == NULL) {
return;
}
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (theSocket == INVALID_SOCKET) {
return;
}
unsigned long ul = 1;
nRet = ioctlsocket(theSocket, FIONBIO, (unsigned long*)&ul);
if (nRet == SOCKET_ERROR) {
closesocket(theSocket);
return;
}
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(pServer->iPort);
nRet = connect(theSocket,
(LPSOCKADDR)&saServer,
sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) {
closesocket(theSocket);
return;
}
struct timeval timeout;
fd_set r;
FD_ZERO(&r);
FD_SET(theSocket, &r);
timeout.tv_sec = pServer->dwTimeout / 1000;
timeout.tv_usec = (pServer->dwTimeout % 1000) * 1000;
DWORD dwStartTime = GetTickCount();
nRet = select(0, 0, &r, 0, &timeout);
if (pServer->bPrintable)
{
if ( nRet <= 0 )
{
printf("%s:%d non-blocking open failed takes %d ms\n", pServer->sIP, pServer->iPort,
GetTickCount()-dwStartTime);
}
else
{
printf("%s:%d non-blocking open successful takes %d ms\n", pServer->sIP,
pServer->iPort, GetTickCount()-dwStartTime);
}
}
closesocket(theSocket);
}
This testbed simply creates multiple thread which opens a socket repeatedly.
There is only one reachable server and the rest are unreachable.
When I use non-blocking mode(timeout = 5000) and 2 unreachable servers, the open procedure takes 0 ms at most of time.
If I gradually increase the number of unreachable server and keep the same timeout, the open procedure takes more and more time.
In the end(about 16 unreachable servers), the open procedure failed every time(except first 5 times).
Even in blocking mode(timeout = 0), the opening time consuming will increase with the number of unreachable server.
There seems to be a constraint on the socket connection in multithread.
But I cannot google any official document about it...
|
|
|
|
|
hello everybody,
Have gone through some application made in WPF and saw their painting means, drawing of controls, image etc..
They were just amazing.
One thing to be asked is how internally they are managing such fast, flicker free painting.
I tried to achieve such kind of optimized painting in Win32 or MFC applications, but to no success.
Please tell me which all points I am missing. Where I should look for concerned resources.
Thanks for your time.
|
|
|
|
|