|
Any of the four I've added, I've tried them all. Yes, the fields are spelled right, I've checked a bajillion times.
The following code is how the information got put into the database in the first place, and it's there and fine.
spFields->Item["FileName"]->Value = (bstr_t) temp;
spFields->Item["FilePath"]->Value = (bstr_t) bstrPath;
spFields->Item["FileLength"]->Value = (*it)->m_FileLength;
spFields->Item["LastModified"]->Value = (*it)->m_LastModified;
spFields->Item["TimesDownloaded"]->Value = (long)0;
spFields->Item["Frames"]->Value = lFrames;
spFields->Item["Seconds"]->Value = lSeconds;
spFields->Item["Width"]->Value = Width;
spFields->Item["Height"]->Value = Height;
What I don't get is how come it crashes when I add ->Value, otherwise it just returns 1 ? I mean, I know ADO crashes at the drop of a pin and gives you no debugging help, but still.
I don't know how to access by position ( and I'd really like to make this work both ways if I can ), because the whole point of this project is to learn more ATL and some ADO. Please ellucidate.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Well, ADO isn't something I've done a lot with so it could be a case of the blind leading the blind
the spFields collection has a Count property
long nRecordCount = pRst->Fields->Count
how many fields does it say your recordset has?
you could try looping through a record like below and see if it displays all your data (I've hacked this from one of the platform sdk samples)
FieldPtr pFld = NULL;
_variant_t vIndex;
pRst->MoveFirst();
long limit = 0;
limit = ((pRst->Fields->Count) - 1);
for (short iIndex = 0; iIndex <= limit; iIndex++)
{
vIndex = iIndex;
pFld = pRst->Fields->GetItem(&vIndex);
printf("Field %d : Name = '%s', ", iIndex,
(LPCSTR)pFld->GetName());
_variant_t FldVal = pFld->GetValue();
}
|
|
|
|
|
I've solved it, thanks. I read my recordset in like this:
_RecordsetPtr records = NULL;
records.CreateInstance(__uuidof(Recordset));
try
{
records->CursorType = adOpenStatic;
records->CursorLocation = adUseClient;
records->Open("SELECT * FROM FileDatabase",
_variant_t((IDispatch*)m_Connection, true), adOpenKeyset, adLockOptimistic,
adCmdUnknown);
}
catch(...)
{
}
and if the database file in empty it crashes big time. Do you know why that might be ? Anyhow, as a result the first record is a dummy record. I needed to reread some ADO stuff to get clear in my mind what I was manipulating, then I checked the VARIANT coming back from ->Value and found it was VT_NULL, because when I added those four fields, I didn't add dummy values for the dummy record.
I'd love your insight on my empty DB problem though, and on accessing values by position, if you don't mind.
Thanks for the help.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
|
You should put try...catch blocks around your spFields->Item["field"]; statements because this call could throw exceptions. The exception you find might give you an indication on why it is failing.
Jeremy.
|
|
|
|
|
Thanks - I came to that conclusion last night ( I'd actually taken a book to bed, and was thinking about what I'd read when I bounded out of bed to solve the problem ). However, in my experience the exception for ADO is *always* unknown error and ADO flags don't offer much help either. I've grown to hate ADO with every failed attempt to pass perfectly valid SQL to it.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I have an IEnumXXX class, and another class which contains my database methods. Tonight I removed some unwanted methods from the database class based on help I got earlier today - no problems.
However, I started work on my MFC client for the database and discovered that now when I get any numeric data from my enumeration, the values are all garbage. Everything comes out with a value of 1. The database is fine, and the program used to return real values. Can anyone suggest what may have gone wrong ? I deleted the methods from the idl, .h and .cpp files, renumbered the methods so they ran from 1 with no gaps and rebuilt all. I had no errors or warnings.
#ifndef __SAFILEENTRY_H_
#define __SAFILEENTRY_H_
#include "resource.h"
class ATL_NO_VTABLE CSAFileEntry :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CSAFileEntry, &CLSID_SAFileEntry>,
public IDispatchImpl<ISAFileEntry, &IID_ISAFileEntry, &LIBID_SADATABASELib>
{
public:
CSAFileEntry()
{
}
CComBSTR m_FileName;
CComBSTR m_FilePath;
long m_FileLength;
long m_DownloadCount;
long m_LastModified;
long m_Frames;
long m_Seconds;
long m_Width;
long m_Height;
DECLARE_REGISTRY_RESOURCEID(IDR_SAFILEENTRY)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CSAFileEntry)
COM_INTERFACE_ENTRY(ISAFileEntry)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
public:
STDMETHOD(get_Height)( long *pVal);
STDMETHOD(get_Width)( long *pVal);
STDMETHOD(get_Seconds)( long *pVal);
STDMETHOD(get_Frames)( long *pVal);
STDMETHOD(get_Modified)( long *pVal);
STDMETHOD(get_DownloadCount)( short *pVal);
STDMETHOD(get_FileLength)( long *pVal);
STDMETHOD(get_FilePath)( BSTR *pVal);
STDMETHOD(get_FileName)( BSTR *pVal);
};
#endif //__SAFILEENTRY_H_
Only get_FilePath and get_FileName are working, and I've traced in to make sure the values in the class are indeed kaput.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
What is the code like for functions, get_Height for instance.
I guess it is a simple
(*pVal) = m_Height;
Or are you doing something else?
Michael
|
|
|
|
|
That is precisely what my GetHeight function looks like and the thing is, it used to work, but now if I break in the function, m_Height always equals 1. I know from opening it in access that the actual values are fine in the database, but now only the string values come out fine.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
What function fills the class variables with data? Does the data go into the class variables okay?
What happens if your initialise m_Height to 255 in the constructor? Does it still give 1?
Michael
|
|
|
|
|
If I make it 255 in the constructor, it still comes out as 1. If I make it 255 in the function, it comes out 255. I traced into my function that reads the data:
try
{
records->CursorType = adOpenStatic;
records->CursorLocation = adUseClient;
records->Open("SELECT * FROM FileDatabase",
_variant_t((IDispatch*)m_Connection, true), adOpenKeyset, adLockOptimistic,
adCmdUnknown);
}
catch(...)
{
}
records->MoveFirst();
vector<ISAFileEntry*> vecDatabase;
do
{
CComObject<CSAFileEntry>* pFileEntry = NULL;
CComObject<CSAFileEntry>::CreateInstance(&pFileEntry);
if (pFileEntry)
{
FieldsPtr spFields = records->GetFields();
string s = (bstr_t) spFields->Item["FileName"]->Value;
for (string::iterator it = s.begin(); it != s.end(); ++it)
if (*it == '?') *it = '\'';
pFileEntry->m_FileName = s.c_str();
pFileEntry->m_FileLength = spFields->Item["FileLength"];
pFileEntry->m_DownloadCount = spFields->Item["TimesDownloaded"];
pFileEntry->m_LastModified = spFields->Item["LastModified"];
pFileEntry->m_Width = spFields->Item["Width"];
pFileEntry->m_Height = spFields->Item["Height"];
pFileEntry->m_Frames = spFields->Item["Frames"];
pFileEntry->m_Seconds = spFields->Item["Seconds"];
and when the data comes out of the database and into the pFileEntry, it is already corrupted, they are already all 1's.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I'm not familiar with the database calls so this may be a stab in the dark,
your string is accessed via
string s = (bstr_t) spFields->Item["FileName"]->Value
yet your numbers are dont use the Value variable. Is this right
pFileEntry->m_Height = spFields->Item["Height"];
Michael
|
|
|
|
|
Well, how about that ? Thanks so much. I'm half way there now. The File Lengths are loading fine, but the properties I added most recently crash if I put ->Value after them. I guess it's back to the drawing board to try and figure out why.
Thanks again for all the help.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I needed to handle dialog button's events like WM_MOUSEMOVE and WM_RBUTTONDOWN, so i created a new class inherited form CButton and handled the events easily but the problem is that i couldn't find a way to access the parent dialog's functions so that i can change the dialog's properties, like for example changing a static text. Is there any way to hadle button's events and enable data exchange with the parent dialog?
|
|
|
|
|
GetParent will give you a pointer to the parent dialog CWnd class. You can then cast it to your dialog class.
CParentDialog* pParent = (CParentDialog*) GetParent();
|
|
|
|
|
I am trying to find some code which will enable me to find out what domain or workgroup a given host is in.
There is a function for this on Win2000, but I need it on NT4.
Does anyone have any ideas?
---
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
|
Nearly.
The link you posted (to NetWkstaUserGetInfo) gets info about the user's log-on domain info. However, just near this on MSDN was NetWkstaGetInfo which does the trick.
Thanks,
Paul.
---
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
When I created my SDI aplication it gives you the choice of having a status bar, if you select yes to this, when your program is created it creates a View menu with a status bar option inside. When you click on this option, a tick appears next to this if the status bar is shown and disappears if not. I wish to copy this functionality with another menu item but cannot work out how it does this in my program, any ideas?
Thanks in advance for any help,
Nick
|
|
|
|
|
On your OnUpdate handler
use
pCmdUI->SetCheck(m_bCondition);
|
|
|
|
|
In ClassWizard, select the command ID. Then, from the list on the right side, select UPDATE_COMMAND_UI. Create the handler. Inside the handler, call pCmdUI->SetCheck with TRUE or FALSE.
BTW: you should have a look on any MFC tutorial, like Scribble.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
thanks, that worked and I have been able to open and close this dialog from the view menu with the tick being displayed/hidden but how do I get the tick in the menu to disappear when the dialog is closed using the close button on the top-right of the screen. I can handle it using OnClose() in the dialog's class but how do I link it to the menu.
thanks for your help so far,
Nick
|
|
|
|
|
ON_UPDATE_CMD_UI handler is called whenever user opens the menu. You have to check the state of the program and pass correct value to CCmdUI::SetCheck.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I have an application, with several functions, and one of these have to return a pointer on COleDateTime. I know the size of the "array" of COleDateTime dates, 2, but i meet a problem when i start debugging when i look in the debug window.
When i declare in the function a COleDateTime pointer i could use 2 way to do that.
Firstly, i just could write:
COleDateTime pDates[2]; and in the debug window i could see:
pDates
[0]->m_dt
->m_status
[1]->m_dt
->m_status
and in another way i could do it:
COleDateTime *pDates=new COleDateTime[2];
and in debug window i only see that:
pDates
->m_dt
->m_status
So, what is the good way if i want to return 2 dates different?
Thanks in advance
gerald
|
|
|
|
|
You should be able to see the two dates in the debug window by modifing the debug view to look at,
pDates[0] and pDates[1].
There is no real difference between COleDateTime Dates[2] and COleDateTime* pDates = new COleDateTime[2] (apart from where the allocate memory goes)
Michael
|
|
|
|