|
Hi all,
Explanation :
1. I add a new record to an Access table;
CMyTable test;
test.Open();
test.AddNew();
...
test.Update();
test.Close();
2. then, I want to fill a ListCtrl with ALL the record from this table
--> problem, the new record isn't present !
if I wait a little with a loop :
for(long i=0; i<1000000; i++); )
then the new record is here.
Is there another thing better ?
How can I do to be sure that the new Recordset will contain the new record ?
|
|
|
|
|
Without seeing the actual code, it's very hard to tell. Assuming your code is correct, it sounds like it might be a caching problem. Use
CDatabase db;
CMyTable test(&db);
TRY
{
test.Open();
test.AddNew();
...
if (test.Update() != FALSE)
{
test.Requery();
test.MoveFirst();
while (! test.IsEOF())
test.MoveNext();
}
}
CATCH(CDBException, pDBException)
{
AfxMessageBox(pDBException->m_strError);
}
END_CATCH
test.Close(); to see if any DB exceptions are lying in wait.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I do something like this, but there is no CException generated; it's just that the last Record isn't in the Recordset when I re-open it.
CMyRecordset MyRecord;
try
{
MyRecord.Open();
MyRecord.AddNew();
...
MyRecord.Close();
// then I call a function to fill a ListCtrl with all the data from the table
MyRecord.Open();
while(MyRecord.IsEOF() == FALSE)
{
MyListCtrl.Add();
MyRecord.MoveNext();
}
MyRecord.Close();
}
catch(CException *e)
{
...
}
--> I have to do a loop before I re-open the Recordset in the FillListCtrl() function otherwise the new Record isn't in the Recordset !
???
BrutalDeath0
|
|
|
|
|
Set a breakpoint on the MyRecord.Open() statement. Then open the .mdb file and see if the record has been added. Otherwise, see if either of these MSDN articles help:
Q153491
Q153046
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
hi,
I've been working on a project with two documents types (one controlling a pair of cameras & their capture, one for DIBs). Implementation of the first document type (cameras) seemed to go smoothly, with its own;
- menu
- icon
- string table entry
- CDocument derived class
- CView derived class
- CMDIChildWnd derived class
This class also handles one message from a button on the toolbar. I've also set-up all aspects of the second document type (apart from it uses a standard ChildWnd at the mo) but as soon as I add it to the document template neither document type will start up. i.e. I'm not presented with an dialog option for which document type I want to start with. Has anyone got any ideas why this might be?? does it sound like I've put in dodgy string table entries or is it likely to be something else??
Cheers for any help
Dave
|
|
|
|
|
Dont worry about answering this post. I've found that the quickest & simplest way to fix the problem in my case was to just start again and re-import all the classes I've created. I'm gonna put it down to me messing with the string table entries and 'resource.h' but if I find a more specific reason will post it here.
|
|
|
|
|
I have the following code, which causes a problem on some mashines where I tried to install and run the program which uses it:
CColorDialog dlg;
COLORREF selectedColor;
if (dlg.DoModal() == IDOK) {
selectedColor = dlg.GetColor();
//..
}
//..
Now, the problem occours while the ColorDialog is modaly opened. On some installations it will cause various part pallets and error messages relating to a "missing resource", at which point the system tends to lock up and Ctrl/alt/del is the only way out.
I do use the MFC Library in a shared DLL. My first guess was that it may be because of that, but I do not think so now.
I do not know which step to go next!?
Thanks for any help!
Miki
|
|
|
|
|
The code works fine on Windows 2000 and Windows XP, but causes this problems on Windows 98 and ME.. hm..
|
|
|
|
|
The following code always fails
// get service information
int nSel = m_ctlListServices.GetSelectionMark();
if(nSel == -1)
{
return;
}
else
{
TCHAR szService[BUFF_LEN];
// get the text of second column
m_ctlListServices.GetItemText(nSel, 1, szService, BUFF_LEN);
SC_HANDLE hSCM = OpenSCManager(m_strPCName, NULL, SC_MANAGER_ALL_ACCESS);
SC_HANDLE hService = OpenService(hSCM, szService, SERVICE_ALL_ACCESS);
// stop service
if(ControlService(hService,SERVICE_CONTROL_STOP,NULL)==0)
{
m_strMessage.LoadString(IDS_SERVICE_STOP_ERROR);
m_strTitle.LoadString(IDS_ERROR);
MessageBox(m_strMessage, m_strTitle, MB_OK|MB_ICONERROR);
}
// refresh
OnBrefresh();
CloseServiceHandle(hService);
CloseServiceHandle(hSCM);
}
The service can accept stop, the program is running on administrator account, I just don't have idea why the stop function is failing
Help!
|
|
|
|
|
First of all, you should be calling GetLastError to figure out why the call to ControlService fails (note that it is important to call GetLastErorr *immediately* after the ControlService call):
if(ControlService(hService,SERVICE_CONTROL_STOP,NULL)==0)
{
DWORD error = ::GetLastError();
...
}
Then either step through with a debugger, or output the error code in the message box, and see what it is. You can look it up in Visual Studio (there is an "Error lookup" in the "Tools" menu) and get more info.
Remember, even if you win the rat race, you're still a rat.
|
|
|
|
|
Thanks for the reply,
the error that I get for every attempt to close any service is "Attempt to access invalid address". What am I doing wrong?
Thanks!
|
|
|
|
|
Good question - maybe your handle is invalid?? You can use the GetLastError trick on *all* the calls, including the ones to open the service. Maybe it's something as simple as not passing in the right service name.
Remember, even if you win the rat race, you're still a rat.
|
|
|
|
|
The following code always fails
// get service information
int nSel = m_ctlListServices.GetSelectionMark();
if(nSel == -1)
{
return;
}
else
{
TCHAR szService[BUFF_LEN];
// get the text of second column
m_ctlListServices.GetItemText(nSel, 1, szService, BUFF_LEN);
SC_HANDLE hSCM = OpenSCManager(m_strPCName, NULL, SC_MANAGER_ALL_ACCESS);
SC_HANDLE hService = OpenService(hSCM, szService, SERVICE_ALL_ACCESS);
// stop service
if(ControlService(hService,SERVICE_CONTROL_STOP,NULL)==0)
{
m_strMessage.LoadString(IDS_SERVICE_STOP_ERROR);
m_strTitle.LoadString(IDS_ERROR);
MessageBox(m_strMessage, m_strTitle, MB_OK|MB_ICONERROR);
}
// refresh
OnBrefresh();
CloseServiceHandle(hService);
CloseServiceHandle(hSCM);
}
The service can accept stop, the program is running on administrator account, I just don't have idea why the stop function is failing :
|
|
|
|
|
Hi, I am trying to write/read a large double matrix (vector of vectors) to file as fast as possible.
My first attempt uses STL ofstream_iterator, vector, and copy() and takes approx 95 seconds to write a 140Mb CSV file. This is 1,900 rows and 10,000 columns.
I need to reduce this time substantially, as the matrix could be as many as 40,000 columns.
I want to use Win32 API WriteFile() and ReadFile() to write/read the raw BYTE representation of my double matrix, but I am unsure how to go about it.
Could someone who knows point me in the right direction, or suggest a better alternative to this approach?
Thanks,
Christopher
The bomb lives only as it is falling
|
|
|
|
|
Write your own, special operator<< , operator>> for your matrix class. If you want really fast implementation, use the low-level IO functions there as much as possible (instead of the STL methods)
Robert-Antonio
"A flower walked around a meadow. She saw a beatiful human and plucked off his head."
|
|
|
|
|
At the moment the matrix is only a typedef unfortunately.
I am trying this out, which seems to work. now all i have to do is read it back in using the same technique.
DWORD nSize = spreads.size() * spreads[0].size() * sizeof(double);
BYTE* buff = new BYTE[nSize+1];
double *pd = (double*)buff;
for (unsigned int row = 0; row < issuerSize; row++)
{
for (unsigned int col = 0; col < spreadCols; col++)
{
*pd++ = spreads[row][col];
}
}
DWORD nBytes;
HANDLE hFile = CreateFile("SpreadCache.dat", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
WriteFile(hFile,(LPCVOID)buff, nSize,&nBytes, 0);
CloseHandle(hFile);
This should be pretty fast i think...
Christopher
The bomb lives only as it is falling
|
|
|
|
|
Well, since the contract/specification of STL's vector states that is has to use a contigious block of memory, you could write out the # of elements in one of the vector s and write out the entire block in one WriteFile(...) operation.
The address of the first element of the vector would be the start of the memory block allocated to it.
Peace!
-=- James (Sonork:100.21837)
[Tip for SUV winter driving survival: "Professional Driver on Closed Course" does not mean "your Dumb Ass on a Public Road"!] [Get Delete FXP Files Now!]
|
|
|
|
|
Hi.
I have very wierd problem with this common dialog. If i call it in my program it works fine, kind of. I get path's & filenames and everything. No problems at all, but after calling the MFC-version or the WINAPI-version of the dialog all other file IO's will fail for no reason. Just simply fails. For example fopen() fails every time after one filedialog-call. Without that call fopen works fine.
I have no idea why this happens. 
|
|
|
|
|
I guess something is trashing the memory, are you supplying a correct buffer for the files?
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
I call it like this:
char strFilter[] = "JPEG image|*.jpg||";
CString pathName;
CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, strFilter);
if (dlg.DoModal() == IDOK)
pathName = dlg.GetPathName();
Then i set up my image class with the filepath, but file open fails, because of filedialog. (or so it seems)
if i hardcode the path to imageclass everything runs smoothly...
Im just interested about the path of the file.
|
|
|
|
|
Hi All,
I want to Play an EMF file to a memoryDc & then display it to the screen using the BitBlt function.
Iam doing it as follows: ,but I dont see anything on screen.
I guess its because,I have to select the Emf Object into the MemoryDc.Is that So?
If yes,How could I select the Emfhandle into the memoryDc,as "SelectObject" takes only things like CBrush,Cpen,Cfont Etc...
CDC dcMemory;
//m_deviceContext is the destination device Context.
//meta_handle,Handle to MetaFile.
dcMemory.CreateCompatibleDC(m_deviceContext);
PlayEnhMetaFile(dcMemory,*meta_handle,&rect);
m_deviceContext->BitBlt(0,0,rectwidth,rectheight,&dcMemory,0,0,SRCCOPY);
Hoping for a Reply
Thanks....
|
|
|
|
|
add this line before PlayEnhMetaFile
CBitmap memBitMap;
memBitMap.CreateCompatibleBitmap( &dcMemory, 400, 400 );
dcMemory.SelectObject(&memBitMap);
|
|
|
|
|
I did as follows,but still I cant see anything on screen..
CDC dcMemory;
dcMemory.CreateCompatibleDC(m_deviceContext);
CBitmap memBitMap;
memBitMap.CreateCompatibleBitmap( &dcMemory, 400, 400 );
dcMemory.SelectObject(&memBitMap);
PlayEnhMetaFile(dcMemory,*meta_handle,&rect);
m_deviceContext->BitBlt(0,0,rectwidth,rectheight,&dcMemory,0,0,SRCCOPY);
|
|
|
|
|
does PlayEnhMetafile works in OnPaint event without using the memory DC i.e directly drawing on the screen??
is the rect properly set, 400x400 is the dimention of the screen, the rect should fall in that only, i guess 0,0,400,400
|
|
|
|
|
Yes,Its is playing the EMF to screen directly with out memoryDc.
Iam giving a different size in the bitBlt function ,which is the width & height of the EMF fILE
|
|
|
|
|