|
I use Ado to connect SQL Server,when I deleted a record,the Provider report a Error Message:"Row handle referred to a deleted row or a row marked for deletion".
The following is my sample code:
pRecordset->delete(adAffectCurrent);
pRecordset->Update();
pRecordset->MoveFirst();
i=0;
while(!m_pRecordset->adoEOF)
{
varValue = pRecordset->GetCollect(long(i);
i++;
if (varValue.vt == VT_NULL)
bstrValue = "";
AfxMessageBox(bstrValue);
pRecordset->MoveNext();
}
|
|
|
|
|
This could be many things. Some people get it because they lack a primary key. Others because they are using a JOIN in their select and find they must set the UniqueTable and ResyncCommand and call Resync after a method. Others must call Refresh(). Others get it working using the SQL Command equivalents. This is just what I heard from groups.google.com, I don't use ADO.
|
|
|
|
|
I'm writing an application with Visual C++ that needs to use Window's task scheduler to launch another application at some time in the future.
My problem is that whilst I can create a task that is supposed to run in the future, the Next Run Time (when viewed through Control Panel->Scheduled Tasks) is always "Never".
I've found that if I open the task through Control Panel->Scheduled Tasks and then delete the last character of the 'Run' string and enter the character again (just so it flags the file as having changes made) then click OK, the "Next Run Time" field then has the correct date and time.
It seems that although I've been able to create the task as I need it, it needs to be 'enabled' somehow - something that happens when I save from the Windows GUI but not when its done through my code.
I've been using the example code on MSDN as a guide, however I haven't been able to find any differences that could indicate where I'm going wrong.
Does anyone have any ideas as to what I'm doing wrong?
My OS is Windows XP Professional with SP2 if thats significant.
Thanks,
Brian.
|
|
|
|
|
|
What does your code look like that creates the task?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I've pasted the contents of the file here. The scheduling code has not been integrated into my app yet - I'm trying to get it to work first.
--------------------------------------------------------------------------------------------------
#include <afx.h>
#include <objbase.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <objidl.h>
#include <wchar.h>
#include <stdio.h>
#include "AFXPRIV.H"
int scheduleTask(SYSTEMTIME Time,CString ExeAndPath,CString ArgList,CString name);
int CreateTrigger(CString name, SYSTEMTIME Time);
int main(int argc, char **argv)
{
USES_CONVERSION;
SYSTEMTIME Time;
Time.wYear = 2005;
Time.wMonth = 7;
Time.wDayOfWeek = 2;
Time.wDay= 27;
Time.wHour= 18;
Time.wMinute= 0;
Time.wSecond= 0;
Time.wMilliseconds=0;
CString ExeAndPath = "C:\\Program Files\\Exterity";
CString ArgList = "\"ExterityLimitedRecord.exe\" -a 239.192.64.105 -p 49408 -t 120 -d C:\\temp\\ScheduledRecord1.mpg";
CString name = "Scheduled Record1";
int result = scheduleTask(Time,ExeAndPath,ArgList,name);
return result;
}
int scheduleTask(SYSTEMTIME Time,CString ExeAndPath,CString ArgList,CString name)
{
HRESULT hr = S_OK;
ITaskScheduler *pITS;
USES_CONVERSION;
/////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// CoCreateInstance to get the Task Scheduler object.
/////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}
/////////////////////////////////////////////////////////////////
// Call ITaskScheduler::NewWorkItem to create new task.
/////////////////////////////////////////////////////////////////
ITask *pITask;
IPersistFile *pIPersistFile;
LPCWSTR pwszAccountName = L"";// run as local account
LPCWSTR pwszPassword = NULL;// run as local account
hr = pITS->NewWorkItem(A2CW(name),//pwszTaskName, // Name of task
CLSID_CTask, // Class identifier
IID_ITask, // Interface identifier
(IUnknown**)&pITask); // Address of task interface
pITS->Release(); // Release object
if (FAILED(hr))
{
CoUninitialize();
fprintf(stderr, "Failed calling NewWorkItem, error = 0x%x\n",hr);
return 1;
}
hr = pITask->SetWorkingDirectory(A2CW(ExeAndPath));
if(FAILED(hr)){
CoUninitialize();
fprintf(stderr, "Failed setting Working directory, error = 0x%x\n",hr);
return 1;
}
hr = pITask->SetParameters(A2CW(ArgList));
if(FAILED(hr)){
CoUninitialize();
fprintf(stderr, "Failed setting Parameters, error = 0x%x\n",hr);
return 1;
}
pITask->SetFlags(TASK_FLAG_DELETE_WHEN_DONE);
//run as local acocunt
hr = pITask->SetAccountInformation(pwszAccountName,pwszPassword);
if(FAILED(hr)){
CoUninitialize();
fprintf(stderr, "Failed setting Account Information, error = 0x%x\n",hr);
return 1;
}
/////////////////////////////////////////////////////////////////
// Call IUnknown::QueryInterface to get a pointer to
// IPersistFile and IPersistFile::Save to save
// the new task to disk.
/////////////////////////////////////////////////////////////////
hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);
pITask->Release();
if (FAILED(hr))
{
CoUninitialize();
fprintf(stderr, "Failed calling QueryInterface, error = 0x%x\n",hr);
return 1;
}
hr = pIPersistFile->Save(NULL,
TRUE);
pIPersistFile->Release();
if (FAILED(hr))
{
CoUninitialize();
fprintf(stderr, "Failed calling Save, error = 0x%x\n",hr);
return 1;
}
printf("Created task.\n");
hr =CreateTrigger(name,Time);
return 0;
}
int CreateTrigger(CString name, SYSTEMTIME Time)
{
HRESULT hr = S_OK;
ITaskScheduler *pITS;
USES_CONVERSION;
/////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// CoCreateInstance to get the Task Scheduler object.
/////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}
///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
hr = pITS->Activate(A2CW(name),//pwszTaskName,
IID_ITask,
(IUnknown**) &pITask);
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
pITS->Release();
ITaskTrigger *pITaskTrigger;
WORD piNewTrigger;
hr = pITask->CreateTrigger(&piNewTrigger,
&pITaskTrigger);
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::CreatTrigger: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
//////////////////////////////////////////////////////
// Define TASK_TRIGGER structure. Note that wBeginDay,
// wBeginMonth, and wBeginYear must be set to a valid
// day, month, and year respectively.
//////////////////////////////////////////////////////
TASK_TRIGGER pTrigger;
ZeroMemory(&pTrigger, sizeof (TASK_TRIGGER));
// Add code to set trigger structure?
pTrigger.wBeginDay =Time.wDay; // Required
pTrigger.wBeginMonth =Time.wMonth; // Required
pTrigger.wBeginYear =Time.wYear; // Required
pTrigger.cbTriggerSize = sizeof (TASK_TRIGGER);
pTrigger.wStartHour = Time.wHour;
pTrigger.TriggerType = TASK_TIME_TRIGGER_ONCE;
pTrigger.Type.Daily.DaysInterval = 1;
///////////////////////////////////////////////////////////////////
// Call ITaskTrigger::SetTrigger to set trigger criteria.
///////////////////////////////////////////////////////////////////
hr = pITaskTrigger->SetTrigger (&pTrigger);
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskTrigger::SetTrigger: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save trigger to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;
hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);
hr = pIPersistFile->Save(NULL,
TRUE);
wprintf(L"The trigger was created and IPersistFile::Save was \n");
wprintf(L"called to save the new trigger to disk.\n");
///////////////////////////////////////////////////////////////////
// Release resources.
///////////////////////////////////////////////////////////////////
pITask->Release();
pITaskTrigger->Release();
pIPersistFile->Release();
return 0;
} // End Create Trigger
Thanks,
Brian
|
|
|
|
|
At the end of CreateTrigger() right before Release() is called, have you checked with IScheduledWorkItem::GetNextRunTime() to see if a next-run time actually exists? It may just be a problem with the Scheduled Task applet not displaying it correctly.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I am new to mfc. I have created a dialog "mydlg" and want to display it in a Splitted main Frame. How can I create a simple splitted frame?
Thanks in advance
Olgun
|
|
|
|
|
How can I create a simple splitted frame?
if u want to create splitted frame
at the beginning of MFC application wizard select SDI option
and after that at step 5 of 6
select the Base class CView
and create virtual function OnCreateClient() for the class CMainFrame
and intilalize boolean variable at the class and give it false value at hte constructor
after u created it delete all the code of OnCreateClient() function and write this instead
if ( !m_mainSplitter.CreateStatic( this, 1, 2 ) )<br />
{<br />
MessageBox( "Error setting up m_mainSplitter", "ERROR", MB_OK | MB_ICONERROR );<br />
return false;<br />
}<br />
if ( !m_mainSplitter.CreateView( 0,0,RUNTIME_CLASS(CLeftView),CSize(255, 0), pContext ) )<br />
{<br />
MessageBox( "Error setting up splitter view", "ERROR", MB_OK | MB_ICONERROR );<br />
return false;<br />
}<br />
if ( !m_mainSplitter.CreateView( 0, 1, RUNTIME_CLASS(CRightView),CSize(0, 0),Context ) )<br />
{<br />
MessageBox( "Error setting up splitter view", "ERROR", MB_OK | MB_ICONERROR );<br />
return false;<br />
}<br />
m_bInitSplitter = true;<br />
return true;
MFC programmer
|
|
|
|
|
m_fuad67 wrote:
if ( !m_mainSplitter.CreateStatic( this, 1, 2 ) )
You should probably indicate that m_mainSplitter is a CSplitterWnd object.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thanks a lot for your reply.
Olgun
|
|
|
|
|
hello all ,
i have some code in MFC which i have to write it in win 32 but i couldnt find a rightway can anybody help me regarding this. My code goes like this.
in MFC code is:
typedef unsigned short mtsChar_T;
.
.
mtsChar_T* pResultText;
.
.
CString res;
for(i=0; i< 100; i++)
{
if((pResultText + i)=='\0')
break;
res =res +(pResultText+i);
}
AfxMessageBox(res);
Now i have to write it in win 32sdk application , iahve tried the same code by just replacing Cstring wirh string but it doesnt complile .plz help me abt this
Santosh
|
|
|
|
|
Hello,
Maybe a std::string[^] or a std::stringstream[^] can be of some help..
If not, you have to use strings of TCHARs (see the tchar.h header). You also have to use a lot of C string functions.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Can you please elaborate more on this Bob?
|
|
|
|
|
Hello,
See the following code examples and see the difference between the CRT and the STL:
double dValue = 99.9;
std::stringstream sstr;
sstr << _T("This is some string with a double: ") << dValue << std::endl;
double dValue = 99.9;
TCHAR szBuf[1024] = {0};
_sntprintf(szBuf, 1023, _T("This is some string with a double: %f", dValue);
Some differences of the STL compared to the CRT are:
<list> You don't have to use buffer magic, the STL does it for you
You don't have to use range checking as much as with the CRT
The syntax looks more clean
I remember now a nice CString replacement written by another CPian: CStdString[^]. You can use this class instead of the MFC CString without too much hassle.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Thanks Bob, it will really help me .
|
|
|
|
|
Note: The define UNICODE has no effect on standared streams or strings. Therefore, the _T() does not realy apply unless you do one of the following:
---------------------------------------------
#ifdef UNICODE
std::wstringstream sstr;sstr << _T("This is some string with a double: ") << dValue << std::endl;
#else
std::stringstream sstr;sstr << _T("This is some string with a double: ") << dValue << std::endl;
#endif
---------------------------------------------
#ifdef UNICODE
std::wstringstream sstr;sstr << L"This is some string with a double: " << dValue << std::endl;
#else
std::stringstream sstr;sstr << "This is some string with a double: " << dValue << std::endl;
#endif
---------------------------------------------
std::basic_stringstream<TCHAR> sstr;sstr << _T("This is some string with a double: ") << dValue << std::endl;
---------------------------------------------
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hi
I have a program with MFC that include Two panes
left pane for TreView and Right pane for List View
and there is icon at toolbar show me Dialog
after inserting data at dialog the TreeView must do refresh for data that came from database
how could i exchange data between the TreeView and Dialog(not FormView)??
MFC programmer
|
|
|
|
|
if u r reading the database in treeview, U can send a user defined message to the treeview from dialog to refresh it by reading the updated database .
Cool Ju
Dont forget to vote
|
|
|
|
|
U can send a user defined message to the treeview from dialog
this code i wrote at LeftView.cpp(TreeView):
#define WM_REFRESHTREE (WM_APP)<br />
<br />
BEGIN_MESSAGE_MAP(CLeftView, CTreeView)<br />
ON_MESSAGE(WM_REFRESHTREE,AddData) <br />
END_MESSAGE_MAP()<br />
<br />
<br />
<br />
void CLeftView::AddData()<br />
{<br />
if(db.IsOpen()==false)<br />
db.Open();<br />
db.MoveFirst();<br />
GetTreeCtrl().DeleteAllItems();<br />
while(db.IsEOF()==false)<br />
{<br />
GetTreeCtrl().InsertItem(db.m_name);<br />
db.MoveNext();<br />
}<br />
}
from MyDlg.cpp (Dialog):
void CMyDlg::OnButton1() <br />
{<br />
CLeftView *obj;<br />
obj->PostMessage(WM_REFRESHTREE);<br />
}
there is error appeared after writing code so it can't work true
so could i continue my work?
MFC programmer
|
|
|
|
|
It will definetly work...
Dont define ur message as application message (WM_APP), make it WM_USER + ..(some number). define it in both dialog as well as view header files..
Can u list out the errors..
Cool Ju
Dont forget to vote
|
|
|
|
|
Hi
i have done as u said
but there is error still appeared
and the error message told me at the memory instruction
and u must know that i have put the code of my defined windows message at the TreeView implementation file
and I posted the message from the dialog button code
I need qick solve for this problem
MFC programmer
|
|
|
|
|
I doubt the function declaration. A crash is expected when you send a message to a window that doesnt handle it. See below MSDN quote:
User Defined Windows Messages
User-defined messages may be included in a message map by using the ON_MESSAGE macro. This macro accepts a message number and a member function of the form:
// inside the class declaration
afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
For example:
#define WM_MYMESSAGE (WM_USER + 100)
BEGIN_MESSAGE_MAP(CMyWnd, CMyParentWndClass)
ON_MESSAGE(WM_MYMESSAGE, OnMyMessage)
END_MESSAGE_MAP()
WPARAM and LPARAM are required in the function declaration even though you dont use it.
Satish
|
|
|
|
|
i tried many ways and the same error
so i have uploaded the project that inculdes:
ODBC database and the connection registration where attached
if u want to test the probelm
click on the back button at the toolbar then try to test
http://www.websamba.com/mohammed_fuad[^]
and after any one solved the probelm u can send me the new code at
m_fuad67@hotmail.com
plz help me quick
MFC programmer
|
|
|
|
|
Satishkumar.B wrote:
A crash is expected when you send a message to a window that doesnt handle it.
Huh? A crash should never be expected, especially if a window receives a message that it does not handle. If a window receives a message that it does not handle, DefWindowProc() or DefDlgProc() just sends it on.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|