CCommand object serialize problem

my code like this:

  CComand<CDynamicStringAccessor> rs0;
  ...
  rs0.Open( session,sqlstr,&ps);

  CFile theFile;
  theFile.Open(curdir+"db.dat",CFile::modeWrite);
  CArchive ar(&theFile, CArchive::store);
  ar.WriteObject((CObject *)&rs0);

when it runs to ar.WriteObject((CObject *)&rs0),the system always report
error:
the memory "0x00000001" used by code "0x00000001" can not be read

what wrong with it ?

what I want is to store the rs0 from memory into hard disk,so I can use
it after then by read it from hard disk
how can I do it correctly?

who can give me some advise?


0
longying (13)
11/15/2006 1:14:14 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
540 Views

Similar Articles

[PageSpeed] 22

longying wrote:
> my code like this:
> 
>   CComand<CDynamicStringAccessor> rs0;
>   ...
>   rs0.Open( session,sqlstr,&ps);
> 
>   CFile theFile;
>   theFile.Open(curdir+"db.dat",CFile::modeWrite);
>   CArchive ar(&theFile, CArchive::store);
>   ar.WriteObject((CObject *)&rs0);
> 
> when it runs to ar.WriteObject((CObject *)&rs0),the system always report
> error:
> the memory "0x00000001" used by code "0x00000001" can not be read
> 
> what wrong with it ?
> 
> what I want is to store the rs0 from memory into hard disk,so I can use
> it after then by read it from hard disk
> how can I do it correctly?
> 
> who can give me some advise?
> 
> 

What is CComand and why are you casting to CObject* ?

If it is a CObject you would not need the cast.  If it is not a CObject 
the cast is invalid and produces undefined behavior.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
11/15/2006 1:21:18 AM
At first ,thanks for your reply
CCommand is a ole_DB consumer templates class,it is used to set and execute
a ole_db command
I think all mfc class is a CObject class
when I write ar.WriteObject(&rs0),the compiler reports error: "can not cast
atl::CCommand<TAccessor>* _w64 to const CObject *"
what I want is store the rs0 from memory to disk,and I can read the rs0
object from disk to memory
is there any other correct way to do this
thanks


"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
??????:ulzSuRFCHHA.3524@TK2MSFTNGP06.phx.gbl...
> longying wrote:
> > my code like this:
> >
> >   CComand<CDynamicStringAccessor> rs0;
> >   ...
> >   rs0.Open( session,sqlstr,&ps);
> >
> >   CFile theFile;
> >   theFile.Open(curdir+"db.dat",CFile::modeWrite);
> >   CArchive ar(&theFile, CArchive::store);
> >   ar.WriteObject((CObject *)&rs0);
> >
> > when it runs to ar.WriteObject((CObject *)&rs0),the system always report
> > error:
> > the memory "0x00000001" used by code "0x00000001" can not be read
> >
> > what wrong with it ?
> >
> > what I want is to store the rs0 from memory into hard disk,so I can use
> > it after then by read it from hard disk
> > how can I do it correctly?
> >
> > who can give me some advise?
> >
> >
>
> What is CComand and why are you casting to CObject* ?
>
> If it is a CObject you would not need the cast.  If it is not a CObject
> the cast is invalid and produces undefined behavior.
>
> --
> Scott McPhillips [VC++ MVP]
>


0
longying (13)
11/16/2006 1:41:25 AM
> error: "can not cast
> atl::CCommand<TAccessor>* _w64 to const CObject *"

ATL does not use MFC (CObject). So this conversion does not make sense.

-- 
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com



0
ajaykalra (6842)
11/16/2006 3:09:55 AM
longying wrote:
> At first ,thanks for your reply
> CCommand is a ole_DB consumer templates class,it is used to set and execute
> a ole_db command
> I think all mfc class is a CObject class
> when I write ar.WriteObject(&rs0),the compiler reports error: "can not cast
> atl::CCommand<TAccessor>* _w64 to const CObject *"
> what I want is store the rs0 from memory to disk,and I can read the rs0
> object from disk to memory
> is there any other correct way to do this
> thanks

No.  Objects that are not derived from CObject cannot be stored with 
CArchive.  You will probably have to store the simple MFC objects, such 
as the SQL string, that you use to create the CCommand, and then use 
them to recreate a CCommand after readback.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
11/16/2006 4:26:30 AM
Reply:

Similar Artilces:

POP3 problem #2
I am Using Exchange 2003 on windows 2003 server, after completion and configuration i try to start pop3 service but didnot get any success Any errors reporting in the Application event log? Can you telnet to port 110? What happens when you try? William Mazhar wrote: > I am Using Exchange 2003 on windows 2003 server, after completion and configuration i try to start pop3 service but didnot get any success Did you start from exchange console ? Try it from Services in windows. Malinda Perera. "Mazhar" <Mazhar@discussions.microsoft.com> wrote in message news:575C2A34-D1D...

Quickbooks RMS integration problem
I am trying to figure out how to integrate Quickbooks 2005 Premier with RMS 1.2. I have 2 PCs, a POS/Server up front and a backoffice PC with Quickbooks. In Manager on the backoffice PC I have selected File, Configuration, Accounting Tab, selected Quickbooks 2003, Retrieve and it says it has successfully connected with Quickbooks. However, when I try to set up the GL Accounts by going to Journal, GL Account Setup I get the account mapping table but I am unable to select any accounts (all cells are empty and I cannot manually pick the accounts from a list, there is nothing there). What am I mis...

Log Shipping Problem -Last Backup File and Last_backup_date
The above two columns in table log_shipping_primary_database dont appear to be getting updated with the latest trans log backup information causing alerts. The trans logs are being backed up copied and restored sucessfully to the secondary database. Somethings out of sync but the information in the logshipping tables looks OK. Any ideas on how to jumstart the updating of these two columns? thanks Hi Tom, For diagnosing the cause of this issue, I need your help on collecting the following information first: 1. Your SQL Server Error Logs which are located at %ProgramFiles%\...

Problem with OutputTo in Access 2007 + Visual Studio 2005
Please forgive me if I'm posting to the wrong group. I'm converting an application I wrote in Visual Studio 2002 + MS Access 2002. It was a console application that was executed from an Access Macro. The application would open up the current Access Database, it would export a particular report to HTML, then it would call a webservice on a remote server to send out the exported file via email to a distribution list. I'm converting this to Visual Studio 2005 + MS Access 2007, so that I can export the reports to PDF. Everything converted over just fine, except that I can no longe...

Publisher Mail Merge Stapling Printer Problems
Problem: When printing a mail merged document and collating / stapling it, it puts 2 merged documents together rather than printing / folding 1 and then the next record. In Publisher 2003 / 2002 we were able to use KB article #891904 to put a registry value in to solve the problem. In Publisher 2007 however, there is not a fix posted and the previous fix does not work - at least not one that I know of. I have tried all of the usual searches, GOOGLE, MSFT KB, etc. but the articles that do acknowledge 2007 is on the market do not have a fix for it yet. Even KB891904 does not have ...

How to execute Stored Procedure from QSRules.Session object in .NE
Last time I accidently posted question under wrong subject.. My question is: I am building COM add-ins to POS with VB.NET I'd like to use QSRules.Session.Database to run stored procedure But I don't know how. Procedure has one input parameter and the other is output parameter. Can anyone know how I should do that? Thanks, Ene ...

Problem with OWA Calendar
Calendar of OWA do not show correct time of meetings on Notebook. If use OWA on another PC, Calendar show correct time. Time zone is OK. The Calendar in OWA renders based on the time settings on the PC. It doesn't use anything from the server. Are the times off by 1 hour? If so, even though the time zone may be ok, you should check and see if the "automatically adjust for daylight savings time" is checked. If it is, and you are in a location that does not observe DST, then that would be the culprit. Vice verse - if it is not checked and you do observe DST, it is ...

The operation failed. An object could not be found.
I just installed Microsoft Office 2003, and upgraded Outlook 2000 to Outlook 2003. I can no longer send or receive mail. When I try, I get the message "The operation failed. An object could not be found." I've been to http://support.microsoft.com/default.aspx?scid=kb;en-us;312354 and tried to follow the advice there without success. I *think* the problem is that the file pointed to in Tools | E-mail Accounts | "Deliver new e-mail to the following location" doesn't match the file in Control Panel | Mail | Properties | Data files, but I've been unable to find out...

Money 2004 Upgrade Problem
I've been using Money 2003 small business. When I put in Money 2004 Standard it converted my files to 2004. I want the full small business functionality but now cannot open my files in 2003. The error reads: "Money cannot locate '(file name)' or cannot open it, possibly because it is a read-only file or you do not have permission to change it or your disk drive is write protected." I know the file is not read-only and is not open in another program. I also have the permission to change files on my computer. Does anyone have any suggestions for what to do? I'm prett...

Problem with POP
I have a Purchase order in change order, this PO must to closed because; y generated a receiving for that order then i posted that transactions. But, with PO don´t change to close, how to do ?????----. If you're asking why the PO didn't change to a closed status after the receipt was processed; once the PO has been fully received and invoiced then the status will change to closed. If you're not expecting an invoice to match to the receipt then you can use the Edit PO window to change the PO status to closed. Doing this should also reverse the GL accrual entry made aft...

Problem with Asset Allocator pie charts
Everything "seems" to be working fine with Money 2005 Premium (after restarting the program multiple times). I'm having a problem with many of the pie charts. They do not show up at all. I upgraded from Money 2004. Any ideas? I'm running Windows XP Professional if that's of any help. Thanks, Patrick I've seen them going on a new file on Win XP Pro - do you get them on a new file, or do they not appear on both a new and old one? -- Glyn Simpson, Microsoft MVP - Money http://money.mvps.org Check http://support.microsoft.com/default.aspx?scid=fh;EN-GB;...

mail problems after synch with pocket pc
This problem happened with an autoiovox ppc and now my ipaq ppc too. Using outlook 2003 and the 2003 version of ppc; windows 98. I'm trying to use the same email account on the ipaq as well as in outlook, so I can retrieve email outside of the office on my ipaq. Both work fine independently. But after a synch, the outlook 2003 email will not work until I take the ipaq out of the cradle and both reset the email info in outlook, and erase the email inbox settings on the ipaq. HP suggested that I reset the ipaq before I place the unit in the cradle for a synch, each time. T...

Problems with reports on Money 2004
I am having problems getting onto the reports page as everytime it crashes. I have tried to repair using the disk and uninstalled and re-installed and it still doesn't work. I am told that there isn't a new UK version available so I cannot upgrade. Can anybody help In microsoft.public.money, Jayne Morris <Jayne Morris@discussions.microsoft.com> wrote: >I am having problems getting onto the reports page as everytime it crashes. I >have tried to repair using the disk and uninstalled and re-installed and it >still doesn't work. I am told that there isn't a ne...

OPOS Line Display Service Object
Hi, I am a newbie in OPOS. I am developing a service object for OPOS line display. When trying to use it through the MonroeCS CO control (OPOSLineDisplay.ocx, version OposCCOs-1_11_001), Open gives code 104 (=OPOS_E_NOSERVICE), and get_OpenResult() gives code 305 (=OPOS_OR_BADIF). What these return codes really means ? In Control Programmer's Guide (OLE for Retail POS, Release 1.6) this is said in page 18, item 5: CLIP --> .... (This ensures that the Service Object supports at least the minimum methods of a valid Service Object for the device class, before calling any of its methods...

Exchange doesnt start at boot up problem.
Hi well here we go today for some reason exchange stopped and i mean totally we found out that asp and iis had totally disappeared?. So we re-install them and then re ran exchange with the disaster recovery switch. And everything seemed fine but how wrong i am. Ok so here we go:- Around 50 % of the users get an error message after send and recive 0x80040111 they recieve and send emails but the error appears these users are unable to send email through owa either. All other users are unaffected except for mac users using entourage they are unable to do anything at all (pop3). Also GFI stop...

Problem Inserting Images
Whenever I use Word or Powerpoint 2007, and I insert either a jpg or png, I get a line around the top and left side of my images. Like a border. This line sometimes prints, but it shows up online. It mostly happens after I will save the file or move throughout the document. I have no borders, no bevelled edges etc. I can't understand why this keeps happening? are you inserting the pictures into a placeholder on the slide? (where it says "click to add text.") If there's an empty one on the slide, the picture will insert into it automatically. As a test, inse...

Equation editor problem.
I have a document created under powerpoint X with equations created by the equation editor. If I open this file with powerpoint 2004, the equations appear as black boxes. However, I can create new equations that look ok. Can anyone suggest a solution to this problem? Thanks. - Mark Are they also black boxes when you run the slide show? If you double-click one of the black boxes, what happens? -- Bob Mathews Director of Training Design Science, Inc. bobm at dessci.com http://www.dessci.com/free.asp?free=news FREE fully-functional 30-day evaluation of MathType MathType, MathFlow, Ma...

HPEN and Rectangle() on Contantly refeshing window object
Hello, Well, I am totally stumped on this one. VC++ 6.0: I have an app that has a video window playing. What I need to do is to be able to draw a rubberbanded rectangle around an area within this screen. Well, the rubberband stuff works until it stretches over the video part of the window -- you will see the rubberbanded Rectangle for a split second on every mouse move, but as soon as motion stops, the rubberbanded rectangle line will be overwritten with the animated video screen. Is there a trick to set an HPEN object to be the top Z order so that it doesn't disappear when ove...

How can i null out a field going through CRM Update object
I have a custom field that i want to set back to null. Any ideas how i can do this through the object.update function? thanks ...

Update Problems
I have encountered repeated problems when I try to update my accounts online. Initially, the updates failed about a week ago. I have since "stopped using online services" and then re-started the online services (re-entering my information for each account) in the "Manage Online Services" window. When I do that, I have only been able to successfully update the accounts in Money that initial time. Every subsequent update fails. To make this even more strange, I noticed that my accounts in the Money.msn page update when I click "Update Now" in Money, but ...

problem opening word 07
When I open word, a dialog box comes up which contains. among other things, the following instructions which I follow up to step 4 then I hit a snag as noted below. >The document contains macros. Macro language support for this application is disabled. Features requiring VBA are not available, Would you like to open this document read-only? Hide Help Open in Help Window • Microsoft Office Access, Microsoft Office Excel, Microsoft Office PowerPoint, or Microsoft Office Word -¬To check your macro security settings, click the Microsoft Office Button, click <program nam...

Problems shelling another application
I am not sure what is going on with this so I am not sure what to ask. I'll just share my experience and maybe somebody can point out what I am doing wrong. I am attempting to launch another application from my VB app. The code to launch the other app is just a simple shell call (lngProcID = Shell(strAppPath)). The call to Shell does return a value but the app does not appear to have been started (does not show up visually and is not in task manager). Using the value held in strAppPath in the Run dialog (Start->Run) starts the app just fine. I figure this has to be some ...

exchange store backup problem
I have a job slotted for every night. It does the following 1. ntbackup server state to a backup file A on harddriv 2. ntbackup exchange store to a backup file B on harddriv 3. ntbackup entire server (excluding server state and exchange store) to 8mm mammouth driv This works great most of the time. My problem is, about once a week when it gets mid way through step 2 the server will just shutdown. It almost feels like a hardware problem but that it does not do it all the time. In fact it did it this last weekend and that was the first time it had done it in about 3-4 weeks.. but ...

problems sending email with crm 1.2
Anybody please help me, i installed the MS CRM 1.2 like 2 months ago, it was working just fine, today my boss wanted to send an email with crm and the following message appear "An error has occurred. For more information contact your system administrator.",every user when is trying to send an email the same message appear even with the administrator account. WHAT TO DO PLEASE HELP Did you install the CRM Exchange E-Mail router? "Nepdy" wrote: > Anybody please help me, i installed the MS CRM 1.2 like 2 months ago, it was > working just fine, today my boss wan...

XSLT, XPath, and XSL Formatting Objects (XSLFO)
does dot net support apis for XSLFO in addition to XSLT? Thanks In data Tue, 13 Jul 2004 11:47:40 -0500, David Laub ha scritto: > does dot net support apis for XSLFO in addition to XSLT? AFAIK no, you have to use nfop: http://nfop.sourceforge.net/ -- Lawrence "In IE we trust" Lawrence Oluyede wrote: >>does dot net support apis for XSLFO in addition to XSLT? > > > AFAIK no, you have to use nfop: > http://nfop.sourceforge.net/ You can, but you don't have to. There are plenty of production quality XSL-FO formatters supporting .NET. Most of them ar...