|
Is this a good way of implementing what you have suggested?
DeleteFile("Source.txt");
DeleteFile("Time.txt");
DWORD dw = GetLastError();
if(GetLastError() != FALSE)
{
MessageBox("File Not Found!","Error", MB_OK);
}
It seems to work ok.
Thanks
Rob
|
|
|
|
|
Is this a good way of implementing what you have suggested?
No, it is not. DeleteFile() returns either TRUE or FALSE , and only in the latter case can you use GetLastError() to know the detailed cause of the failure:
BOOL bResult=DeleteFile("Source.txt");
if(!bResult){
DWORD dw=GetLastError();
if(dw==ERROR_FILE_NOT_FOUND){
MessageBox("File Not Found!","Error", MB_OK);
}
else{
}
}
This way of signaling errors (i.e., returning a BOOL and storing in case of failure an error code to be retrieved with GetLastError() ) is typical of many Win32 functions, so you might find it useful to get acquantied with it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you very much! I'm pretty new to programing and this kind of information helps alot!!!
Thanks again for you time,
Rob
|
|
|
|
|
http://www.codeproject.com/useritems/cwin32error.asp
that's an article bout how you can handle GetLastError Message.. i think it is a really interesting discussion in the discussion below the article.. maybe your interested..
happy learning
bernhard
stolen sig #15:
"The content of this post is not necessarily the opinion of my yadda yadda yadda."
|
|
|
|
|
Thanks!!
I will take a look at the article.. I'm very interested in learning anything new.
Thanks again,
Rob
|
|
|
|
|
I have a subroutine in a Visual C++ program using Microsoft's MCI that
records to a file named dummy.wav that already exists on C drive. If the
program is also on C drive all works well. However, if I put the program
on D drive, but still leave dummy.wav on C drive, the subroutine opens
c:\dummy.wav but will not save to it the first time the subroutine is
called. Instead it writes a temporary file of the type ~$mc331C.tmp to the
root of C. On calling the subroutine a second time, it works properly. MCI
does not report any errors when the subroutine is run. Can anyone explain
why it doesn't work the on the first call?
char strcmd[100];
wsprintf(strcmd,"open %s %s","c:\\dummy.wav","wait");
if (mciSendString(strcmd,NULL,NULL,NULL))
AfxMessageBox("error opening dummy.wav",MB_OK,NULL);
wsprintf(strcmd,"record %s %s %s","c:\\dummy.wav","from 0 overwrite to 1000","wait");
if (mciSendString(strcmd,NULL,NULL,NULL))
AfxMessageBox("error recording dummy.wav",MB_OK,NULL);
wsprintf(strcmd,"save %s %s","c:\\dummy.wav","wait");
if(mciSendString(strcmd,NULL,NULL,NULL))
AfxMessageBox("error saving dummy.wav",MB_OK,NULL);
wsprintf(strcmd,"close %s %s","c:\\dummy.wav", "wait");
if (mciSendString(strcmd,NULL,NULL,NULL))
AfxMessageBox("error closing dummy.wav",MB_OK,NULL);
Note: if I execute the program with a .pif style shortcut, the behaviour is
as described above, except that when I quit the program and then restart it,
it works properly on the first call to the subroutine, unless I reboot the
computer. However, if I execute the program with a standard Win98 or Me
shortcut, the call to the subroutine fails on the first try and succeeds on
subsequent calls every time the program is executed from the shortcut icon.
|
|
|
|
|
I would like to be able to programmatically query a process' opened files (don't confuse with EnumProcessModules). I know it is possible (TaskInfo2000 does it). Can I do that using a Win32 or Shell function/object? I wasn't able to figure out yet.
Tx
|
|
|
|
|
Hi,
I Use Visual C++ 6.0 and an access Database.
I want to execute a SQL statement with CDaoRecordset. This error message occurs : "Too few parameters. Expected 1" when i use Open method.
My SQL statement is longer than 256 characters ( about 1100 ). The problem is here it seems.
If i run This query directly in Microsoft Access, it work.
Is there any method to execute un SQL Statement like this in DAO ( CDaoDatabase ) ???
Thanks in advance
Regards,
|
|
|
|
|
Show me the line....
Cheers!!!
Carlos Antollini.
|
|
|
|
|
I use CFtpConnection to process FTP connections. But how can I check whether the connection is still opened when I get a CFtpConnection pointer? There will be many accidents to break the connection(The master closed the FTP server, net-wire broken, etc.). X|Show me some solutions, please.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
I had the same Problem, I found a solution, doing something over the FTP Server, like a change Dir, or a FindFile, etc...
Cheers!!!
Carlos Antollini.
|
|
|
|
|
In an Mfc programm ( dialog based) i created a thread through the AfxBeginThread function .
I need that the specific class that was created will
get access to another class ( the main Dlg class)????
(i tried to use pointer but no good !)
meirav
|
|
|
|
|
You should not pass dialog pointer to the thread because it may be invalid. I think you can use GetSafeHwnd() to get the handle of the main dialog and pass it to the thread. In the thread you can use FromHandle() to get back the main dialog pointer and then you can access the main dialog class.
Here is an example:
UINT ThreadProc(LPVOID);// the thread proc
HWND hWnd; // for handle of main dialog
BOOL C???Dlg::OnInitDialog()
{
...// some codes
hWnd=GetSafeHwnd();
...// other codes
}
void C???Dlg::OnButton1() // Button1 is a sample button
{
AfxBeginThread(ThreadProc,NULL);
}
UINT ThreadProc(LPVOID lpData)
{
C???Dlg *pDlg=(C???Dlg*)C???Dlg::FromHandle(hWnd); // get the main dlg pointer
...// do what you want to do
}
You can also pass the handle through the thread proc's lpData pointer, then you don't have to declare the hWnd as a external variable.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Thank you for your answer,
i tried what you suggest me , but there is one problem:
when i pass the LPVOID to the ThreadProc (I did it on ThreadProc::InitInstance) using the debug i saw that he never get at all to this Function .
(without the LPVOID it did get there )
it will be a great help if you can help me.
|
|
|
|
|
Could you show me your codes? I think that would be a great help.;)
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Hi,I did exacly the code you suggested in your reply above.
I can send the programm i did (it is very short ) if it is needed.
|
|
|
|
|
OK, you can either paste it or send it to my mailbox.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Hi,
I am having a whirl of a time using MSComm, what I thought would take me 10 mins, has now taken me days not to mention my frustration level is high.. anyway here is my question, I'm hoping someone will please help me.
I am using mscomm and I need to transmit and receive binary data to my device on com 1. I am assuming that because my data consists of all unsigned characters that I can't use CString, it this correct?, I'm assuming that I must use CByteArray and then convert this to a VARIANT of which I will pass to SetOutput, How do I do this conversion?, also what is really strange is that when I am viewing my VARIANT via the debugger on my Windows 2000 machine, it appears to have the correct value within, however when I view the same on my windows ME machine it does not...
thanks for any help in advance...
|
|
|
|
|
I am looking for a "unmanaged" implementation of the .NET DataSet and its
associated objects that is written in Visual C++ (with source if possible).
I need an implementation that does not rely on the .NET FrameWork, yet is
compatible with the .NET DataSet's so I can share the XML form of the
DataSet between unmanaged clients (.NET is not installed on the clients) and
a .NET web service. We will be using the DataSet's as our universal
datapacket to pass data between the client and server.
I am trying to put off having to implement a solution myself in ATL so I am
doing some research first.
Thanks in advanced for any information or assistance.
Send Replies to jwilliams@paymetric.com
|
|
|
|
|
Hi,
I'm tying to implement a FORTRAN application (that i've gradually written over the last 12 or so years) in windows. I'm getting the hang of VC, but need some advice...
My plan is to implement all the "work" of the application (a lot of complex maths) in fortran, in a Fortran Powerstation 32 compiled DLL, and then use VC to create the WIndows UI of my application.
The input for the application is a matrix of numbers. The obvious, ideal UI implementation of a way of getting this input data is to implement something with a Microsoft Excel style grid. It would need 5 columns, and n rows (ie. user would be able to insert new rows).
Anyway, I've been hunting down methods of doing this by trawling through MSDN. The only way I've found is to use the MSFlexGrid Object. But this doesn't really appeal: it seems to be a bit of an over-the-top approach, and it's programming interface is a bit awkward.
So, my question is: Is there a better way to implement a simple, excel style grid? and where can I find out about it.
Thanks in advance for your help
Richard Neilson
|
|
|
|
|
There's a MFC-based grid right here at CodeProject; go to Controls/Misc section. I think it has all the features you need.
And if you want to spare some money, there are at least two commercial packages: Objective Grid from Stingray and Ultimate Grid from Dundas.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I feel a right fool now... I just found that grid myself!
Thanks for your help anyway!
I eyed up that DUndas software one, but I can't really afford it since this is just a pet project and not associated with work at all.
And the software won't be commercial anyway: how many people would want an application which plots grapic natural harmonics of turbines? not very many.
Thanks again
Richard
|
|
|
|
|
search for Grid on the home page, Chris Maunder (site administrator) has written a grid for VC.
Norm Almond
Chief Technical Architect
FS Walker Hughes Limited
|
|
|
|
|
Does anyone know how to prevent the really annoying compiler
warning C4768 ('identifier' : identifier was truncated to 'number' characters in the debug information)? (normal when working with STL)
I want to use warning level 4 and the
#pragma warning(disable: 4768) doesn't work, or not everytime.
thanks
zack
|
|
|
|
|
The #pragma works, at least for me. You just have to put it before #including STL headers. Usually, I place it at the top of stdafx.h
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|