|
right
|
|
|
|
|
Still it crushes
oam
because i have made the changes you suggested.
<br />
#include "stdio.h"<br />
<br />
<br />
int main(int argc, char* argv[])<br />
{ <br />
FILE* fp;<br />
char fname[30];<br />
<br />
printf("Enter the file name: ",fname);<br />
scanf ("%s",fname);<br />
<br />
<br />
fopen(&fname,"wt");<br />
if( fp )<br />
{ <br />
int i;<br />
for( i=0; i<10; ++i ) <br />
fprintf(fp,"Line %d\n",i); <br />
<br />
fclose(fp); <br />
} <br />
return 0;<br />
}<br />
|
|
|
|
|
you still have yet to assign fp as was stated above
|
|
|
|
|
Well it works now.
Thanks
oam
|
|
|
|
|
mpapeo wrote:
if( fp )
fopen("&fname","wt");
{
Should be:
fp = fopen(fname, "wt");
if (NULL != fp)
{
...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
|
Is there a way to determine if a socket that is connected to my CSocket has been closed (without overriding onClose function in class derived from CSocket)?
My function:
CString Connection::read()
{
CString out;
DWORD numRead;
do
{
::Sleep(100);
socket->IOCtl(FIONREAD, &numRead);
} while(numRead == 0);
int count = socket->Receive((void*)out.GetBuffer(numRead), numRead);
out.ReleaseBuffer(numRead);
out.TrimRight();
cout << "Connection->reading: index: " << index << ", count: " << count << ", msg: " << (LPCTSTR)out << endl;
return out;
}
I'm using this function in multithread server application. Threads are waiting for new messages and processing them sometimes requires writing to other threads' sockets.
|
|
|
|
|
Hi,
Here is useful link(especialy the examples):
http://tangentsoft.net/wskfaq/[^]
Are you using P2P or broadcast or multycast connection?
I'm not using CSocket , I'm using SOCKET with all WinSock function,
and if recv() return 0 so the client closed the connection,so i guess it's the same with CSocket.
Good luck,
Eli
|
|
|
|
|
Thanks for Your response.
socket->Receive returns 0 if socket is closed, but the problem is, that I'm using socket->IOCtl to check if I can read data from socket (and not to block socket with socket->Receive, because other thread may be trying to send something to the same socket).
socket->IOCtl returns 0 when there is nothing to read (so when socket is closed it also returns 0), and code with socket->Receive won't be executed.
I'm looking for simple method to check if socket was closed by client.
Lets say I'm lazy and I don't want to rewrite my code
|
|
|
|
|
In order to use non blocking socket,try this:
unsigned long argp = 1;
ioctlsocket(YourSocket , FIONBIO , &argp);
and it's should solve your problem of blocking socket.
About your's socket->Receive()->i've searched MSDN for CSocket functions and there is no Receive() in CSocket class,so how do you use that function?
Good luck with the Non blocking socket,
Eli
|
|
|
|
|
I did as You suggested, only in CSocket style:
DWORD ctl = 1;
socket->IOCtl(FIONBIO, &ctl);
I've rewritten my code:
CString Connection::read()
{
TCHAR c;
CString out;
DWORD numRead;
do
{
::Sleep(100);
socket->IOCtl(FIONREAD, &numRead);
if(numRead == 0)
{
int ret = socket->Receive(&c, 1);
if(ret == 0) valid = FALSE;
if(ret == SOCKET_ERROR)
{
if(socket->GetLastError() == WSAECONNRESET)
valid = FALSE;
}
if(!valid) return CString();
}
} while(numRead == 0);
int count = socket->Receive((void*)out.GetBuffer(numRead), numRead);
out.ReleaseBuffer(numRead);
out.TrimRight();
cout << "Connection->reading: index: " << index << ", count: " << count << ", msg: " << (LPCTSTR)out << endl;
return out;
}
void Connection::write(CString s)
{
CSingleLock singleLock(§ion);
singleLock.Lock();
s += "\n";
if(socket->IsBlocking()) socket->CancelBlockingCall();
int count = socket->Send((void*)s.GetBuffer(10), s.GetLength());
cout << "Connection->writing: index: " << index << ", count: " << count << ", msg: " << (LPCTSTR)s;
if(count == 0)
cout << "Error: " << socket->GetLastError() << endl;
}
I'm no so sure about the line: if(socket->IsBlocking()) socket->CancelBlockingCall(); but I was forced to add this, because with two clients connected to server, writing to one of them was generating error WSAEINPROGRESS.
socket->Receive() is function of CSocket base class: CAsyncSocket.
Thanks again.
|
|
|
|
|
I want to get memory usage information of one process.
Looking at the old threads, I have been told to execute the following codes.
#include <windows.h>
#include <stdio.h>
#include "psapi.h"
void PrintMemoryInfo( DWORD processID )
{
HANDLE hProcess;
PROCESS_MEMORY_COUNTERS pmc;
// Print the process identifier.
printf( "\nProcess ID: %u\n", processID );
// Print information about the memory usage of the process.
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL == hProcess)
return;
if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) )
{
printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
printf( "\tPeakWorkingSetSize: 0x%08X\n",
pmc.PeakWorkingSetSize );
printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n",
pmc.QuotaPeakPagedPoolUsage );
printf( "\tQuotaPagedPoolUsage: 0x%08X\n",
pmc.QuotaPagedPoolUsage );
printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n",
pmc.QuotaPeakNonPagedPoolUsage );
printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n",
pmc.QuotaNonPagedPoolUsage );
printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage );
printf( "\tPeakPagefileUsage: 0x%08X\n",
pmc.PeakPagefileUsage );
}
CloseHandle( hProcess );
}
void main( )
{
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the memory usage for each process
for ( i = 0; i < cProcesses; i++ )
PrintMemoryInfo( aProcesses[i] );
}
then create a console application, copy above code, compile and run.
my question is :
when runing the program , one condition function OpenProcess( PROCESS_QUERY_INFORMATION |PROCESS_VM_READ, FALSE, processID ) return NULL, the other condition function GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) return FALSE, so I can't get anything about the memory usage information per process.
can anyone help ?
|
|
|
|
|
Are you passing a valid process ID to the function?
"Aerodynamically, the bumble bee shouldn't be able to fly, but the
bumble bee doesn't know it so it goes on flying anyway." - Mary Kay Ash
My Articles
|
|
|
|
|
Try:
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID );
if (NULL == hProcess)
{
DWORD dwError = GetLastError();<big>
return;
}
...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
uuid.lib provided with Visual Studio .NET isn't good for project written in VC6 when compiling in debug mode. Can you please tell me where to download or send me uuid.lib for Visual Studio 6 (debug) ?
Thanks!
|
|
|
|
|
|
Sorry , forgot to mention - i need it for "IFontLink2". I have uuid.lib from latest SDK , but if i compile my project in VC6 in debug mode it says "corrupted lib" and as far as i know this is because uuid.lib from letest SDK doesn't have debug version of uuid.lib (it's only release).
|
|
|
|
|
I've hooked keyboard globally. And I can change the key code like a->b and b->a using post / send message and it works nicely in note pad, word pad or any other text editor except MSWord. In MSWord it shows nothing while I keep pressing any of the keys in the keyboard. Another problem is I can't post or send unicode through wparam even though I've mentioned the message type as WM_UNICHAR. But I got an error when I complied it: "WM_UNICHAR is not defined". But as far as I know this is defined in windows.h and I've included that header in my dll. So what should I do?
A programmer of New Horizon
|
|
|
|
|
pavel0705 wrote:
But I got an error when I complied it: "WM_UNICHAR is not defined".
WM_UNICHAR is defined in WinUser.h. If you look it up in that file you will see there is an #if line just before it
#if(_WIN32_WINNT >= 0x0501)
#define WM_UNICHAR 0x0109 As that message is only available in XP+ you have to define _WIN32_WINNT as 0x501 in order to use it.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Thank you PJ Arends for your kind cooperation.
I've used VC++6 but I've not found WM_UNICHAR defined in anyone of windows.h, winbase.h and winuser.h files. not even after the if statement that u mentioned
in fact I could not find any line like
#if(_WIN32_WINNT >= 0x0501) ..but i found serveral conditions like
#if (_WIN32_WINNT >=0x0500) or #if(_WIN32_WINNT >=0x0400) like this...but nowhere i've seen WM_UNICHAR, ...Could you please suggest me what should I do in this circumstances??
A Programmer of New Horizon
|
|
|
|
|
|
Thank you Alok, But still it doesn't work...still i'm getting the same error message: WM_UNICHAR undeclared!!!
A Programmer of New Horizon
|
|
|
|
|
|
Hi,
I have a program which consists of a exe and a dll (there are some additional static librarys). Well, everything is ok - until I press F5 to start the app. Visual C++ then will ALWAYS recompile the whole program, even if I made no changes at all! What I think is also very strange, is that when I make a few changes in a resource that is in the dll (for example remove some controls from a dialog) the old dialog is shown when starting the program. There are some other weird things with resources but I think all these problems are somehow connected...
does somebody know this problems and how to solve them? the project is a normal win32 application + win32 dll. I don't use MFC, instead I'm using win32gui lib, but I think that won't be the reason for this strange compilation behaviour...
my IDE is vc.net 2003 with the toolkit 2003. btw i tried a complete rebuild of the whole app but the problem persisted
mfg steven
|
|
|
|
|
It sounds like the copy of the DLL in the EXE's compiler output directory is out of date. Unlike the VB and C# compilers, the C++ compiler/project system does not copy dependencies into target directories.
I normally set up the build process so that the binaries are output into the same directory - if you created a folder for the solution, the project's Output Directory could be set to '../Debug', which would create a Debug folder under the solution's folder (i.e. a sibling of the projects' folders). You should instruct the linker to find the DLL's import library in this directory: include e.g. '../Debug' in the Additional Libraries under Linker > General in Project Properties for the EXE project. You should also ensure that your dependencies (in Project > Project Dependencies) are set up correctly: the EXE project should depend on the DLL project.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|