|
From MSDN on ReadFile() .
the return value is FALSE and GetLastError returns ERROR_HANDLE_EOF
when the file pointer goes beyond the current end of file. So, every time you get to EOF, you're generating what you perceive to be an error. Check for both instead of just the return value.
Alternatively, you could use c to check for the value of 46 (0x2E), as that's the ASCII/ANSI EOF char.
Jeremy L. Falcon
"It's in the mail."
<nobr>
Homepage : Sonork = 100.16311 Surely some striving souls survive symptomatic stress?
|
|
|
|
|
ReadFile does not return any EOF . Instead, it returns TRUE with dwByteRead being 0.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
My team is given a task of developing a chat server. Ofcourse the server will be multithreaded.But the concern here is that we do not want to develop server using MFC. Reason is that we may want to deploy this server on LINUX platform in the future.
My question is that whether multithreading is possible using standard ANSI C++. Is there any method that we can develop the chat server in C++ using multithreading and can compile the same code in compilers like VC++ and on UNIX ???
|
|
|
|
|
If you want portability, you can use the
posix functions like the c-runtime library's
beginthread & endthread etc..
These functions will be portable across platforms.
|
|
|
|
|
Look up:-
_beginthreadex
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
If you want threads and portability, then use the threads contained in BOOST.
www.boost.org
If you don't want to use BOOST, then at least look at the threads implementation in there so you can get an idea what is required to do threading using PTHREADS. Then you can design your own system. The important thing is that the OS specific calls such as CreateThread/_beginthreadex are abstracted using some type of class or library. Then you just have to adjust the class when porting to another platform.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
With GetAsyncKeyState(), GetKeyboardState() and GetKeyState(), I cannot get the global keyboard state
under Windows 2000. How can I get it and how can I set it?
Can you help me?
Thanks.
|
|
|
|
|
i don't know why you can't get it, but I can:
bool ctrl = (GetKeyState(VK_CONTROL) & 0xf000) == 0xf000;
bool shift = (GetKeyState(VK_SHIFT) & 0xf000) == 0xf000;
works fine for me.
-c
"Should you not have a ramekin of sea salt beside the stove, you don’t deserve oatmeal."
Dean Allen
|
|
|
|
|
Thank you for your replay.
My scenario is:
When message WM_HOTKEY is received, I repeatedly checks keyboard state until no key is pressed. If my program is in the foreground, GetKeyState() cannot work well. Now I has to create a worker thread to check it.
Now I has another question:
GetKeyState() should return a SHORT value which is a 16-bit integer, and only the low byte is significant. If the specific key is pressed, it returns "FF81" or "FF80". Are you sure the above code segment can work well?
|
|
|
|
|
sorry, i can't help with your first question.
2nd Q:
from MSDN:
GetKeyState:
Return Values
The return value specifies the status of the specified virtual key, as follows:
* If the high-order bit is 1, the key is down; otherwise, it is up.
* If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
-c
ABSURDITY:
A statement or belief manifestly inconsistent with one's own opinion.
|
|
|
|
|
i need to implement some search and filtering capabilites in my application.the problem is that i have to call dialog from my CRecordView class.that's OK but how to give informations for CListCtrl which is on dialog-from CRecordView
|
|
|
|
|
Remember that the list control is not created till the dialog is almost shown on screen. Most people try to access member control variables after they instantiate their dialog wrapper class. I suggest that you pass all the strings to a string array and then populate the list control in the initdialog function of the dialog using those strings in the array.
Regards
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
thanks man.i would give almost anythyng to foun out how can You possible know all those things?can You tell me where can i download (for free by all means) material (ebooks,html files,...) about MCSD 70-016 certificate?do You think that i can learn something smart from them?Also i need to ask is there any chance to study online MFC programming (again-for free) and where?code on this site is sometimes just too complex for me and i want to follow some guide to get stuck in with it graduatelly.i want to learn how to develop windows applications with MFC so bad!!! thanks for everything
|
|
|
|
|
Hello
What IOCTL codes are available to access to parallel port from an application?
I am trying to read/write from the parallel port with the file access functions but I must be missing something and it doesn´t work.
I don´t have C++ nor the SDK nor the DDk. I only have access to MSDN online help.
Thanks
Good luck
http://www.geocities.com/nafiton
|
|
|
|
|
I remember something about using "COM1" as the path name for CreateFile when wanting to access the serial COM1 port.
I guess you just have to specify the name of the port then.
"It could have been worse, it could have been ME!"
|
|
|
|
|
Hi,
im trying to set the current working directory before going in to a file dialog and then reseting it to its original value after the dialog has closed:
TCHAR strCurrentDirectory[MAX_PATH];
GetCurrentDirectory(MAX_PATH, strCurrentDirectory);
CFileDialog fileDlg(TRUE, ".dot;.doc", NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR, "Microsoft Word Templates (*.dot; *.doc)|*.dot;*.doc|HTML Templates (*.htm; *.html)|*.htm; *.html|All files (*.*)|*.*||\0", NULL);
fileDlg.m_ofn.lpstrInitialDir = "c:\\projects\\temp";
if(fileDlg.DoModal() == IDOK)
{
// Do something
}
SetCurrentDirectory(strCurrentDirectory);
But this doesnt work as next time i go in to a different file dialog the current directory is set as c:\projects\temp.
Has anyone had to cope with a similar problem before and if so how did they get around it?
Cheers,
Andy.
|
|
|
|
|
Since you have used OFN_NOCHANGEDIR, you really don't need to use Get/SetCurrentDirectory at all.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Hi Probably you are using Windows 2000.
In this OS the last opened directories thru the
application is set in the registry and the
File Dialog reads thru that.
|
|
|
|
|
hi, yes i am using windows 2000. do you know where the registry entry is stored so that i can modify that myself.
Cheers,
Andy.
|
|
|
|
|
HKCU\Microsoft\Windows\Currentversion\explorer\comDlg32\OpenSaveMRU
Its got sub keys for well known extensions and generic keys for
those not registered, see if u can crack and let me know if u do.
|
|
|
|
|
I use a dialog based application with MFC.
The dialog also has a menu attached to it.
I use a view modal dialog boxes for settings and stuff.
Opening is not a problem but when I try to close this modal dialog the complete application closes. This happens when closing with either IDOK of IDCANCEL buttons.
The problem is that this only happens in Release mode. But without throwing an exeption of some kind.
When "debugging" the release version an exeption in msvcrt.dll at address 0x0000005 is thrown. But I have no clue why this happens.
In earlier versions of the program (without menu but with lots of other extra stuff) this problem did not occur.
Anyone got a clue to this problem?
Thanks
|
|
|
|
|
There is an article here by Joe Newcomer where he explains how to debug a release build. I suggest that you read that.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Hi,
I use a stored procedure for write to a Database.
When I execute the Stored Procedure, this Stored Procedure acknoledge with a int value if all are OK.
I would like to know how can I do for reading this value.
The value must be extract from the "Status".
You find my sample code:
//Initialize the connection with the Database RTLSQL1 ARCHIVES_NUM
//COM initialization
CoInitialize (NULL);
_ConnectionPtr m_pConn2("ADODB.Connection");
_ParameterPtr pParam2,pParam3;
try
{
//Check if I can create a instance for a connection into a db
HRESULT hr = m_pConn2.CreateInstance (__uuidof (Connection));
if (FAILED (hr))
{
// Automat_LOG_WITH_TIME(_T("DB : Can't create intance of Connection"));
}
else
{
// Automat_LOG_WITH_TIME(_T("DB : I can create intance of Connection"));
}
CString strFileName = "JA001206";
//Check if I can Open a session in the RTLSQL1 ARCHIVES_TVI
if (FAILED (m_pConn2->Open("provider=sqloledb.1;database=ARCHIVES_TVI;server=1.1.1.1;uid=Automat;pwd=Automat;network=dbmssocn","","",adConnectUnspecified)))
{
// Automat_LOG_WITH_TIME(_T("DB : Can't open datasource "));
// Automat_Send_SMS(_T("DB : Can't open datasource "),_T(""));
}
else
{
//Automat_LOG_WITH_TIME(_T("DB : I can open datasource "));
CString sT;
sT.Format("%d",1);
_variant_t varLiReturn;
int liReturn = -99;
_CommandPtr pCmd2("ADODB.Command");
pCmd2->ActiveConnection = m_pConn2;
//Store procedure for the DATABASE
pCmd2->CommandText = "StartFileNumV3";
pParam2 = pCmd2->CreateParameter ( _bstr_t ("FileName"), adVarChar,
adParamInput, strFileName.GetLength (), (_bstr_t) strFileName);
pCmd2->Parameters->Append ( pParam2);
pParam2 = pCmd2->CreateParameter ( _bstr_t ("AutomatNr"), adInteger,
adParamInput, sizeof(int), _variant_t (sT));
pCmd2->Parameters->Append ( pParam2);
pParam2 = pCmd2->CreateParameter(_T("Status"),adInteger,adParamOutput,sizeof(int),varLiReturn);
pCmd2->Parameters->Append ( pParam2);
_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset = pCmd2->Execute(NULL, NULL, adCmdStoredProc);
//******************
//!!!!!!!! I don't know if it is correct to receive the return value
varLiReturn = pCmd2->Parameters->Item[_T("Status")]->Value;
Sleep(100); //ms
//Automat_LOG_WITH_TIME(_T("DB : The Store Procedure have been execute with success (StartFileNum)"));
//Close the DATABASE
if ( (m_pConn2->State & adStateOpen) == adStateOpen)
{
m_pConn2->Close();
// Automat_LOG_WITH_TIME(_T("DB : I can close datasource RTLSQL1 ARCHIVES_TVI"));
}
else
{
// Automat_LOG_WITH_TIME(_T("DB : I can't close datasource RTLSQL1 ARCHIVES_TVI"));
}
}
}
catch ( _com_error &e )
{
_bstr_t bstrSource (e.Source());
_bstr_t bstrDescription (e.Description());
CString sErrorDB;
sErrorDB.Format("DB : ERROR !!!!!\r\nException thrown for classes generated by #import\r\nCode = %08lx\r\nCode meaning = %s\r\nSource = %s\r\nDescription = %s\r\n", e.Error (), e.ErrorMessage (), (LPCTSTR) bstrSource, (LPCTSTR) bstrDescription);
// Automat_LOG_WITH_TIME(sErrorDB);
MessageBox (sErrorDB, bstrDescription,MB_OK);
}
catch (...)
{
TRACE ( "*** Unhandled Exception ***" );
}
Sleep(100); //ms
CoUninitialize();
youssef
|
|
|
|
|
I can't be arsed to read your code. But heres a snippet from some of my code that does what you want:
try {
_CommandPtr pCommand;
_ParameterPtr pRetVal;
pCommand.CreateInstance(__uuidof(Command));
pCommand->ActiveConnection = m_pConn;
pCommand->CommandText = "p_YourProc";
pCommand->CommandType = adCmdStoredProc;
pRetVal = pCommand->CreateParameter ( _bstr_t ("RETURN_VALUE"), adInteger, adParamReturnValue, 0);
pCommand->Parameters->Append(pRetVal);
pCommand->Parameters->Append ( pCommand->CreateParameter( _bstr_t ("YourParamIn"),adInteger,adParamInput,0 ,_variant_t(lTicketId)));
pCommand->Execute(NULL, NULL, adCmdStoredProc);
lSuccess = (DWORD) pRetVal->GetValue();
} catch (_com_error e)
{
}
Signature space for rent. Apply Within.
|
|
|
|
|
Hi, thank for the answer but I can't receive the return value.
lSuccess is allways null.
best Regards
youssef
|
|
|
|