|
scoroop wrote:
Is there any way to create function that can return a recordset? i tried to do it but...
But what? Show us the code that you had/have and what the problem is.
scoroop wrote:
does CRecordset have any copy constructor...
No.
scoroop wrote:
does CRecordset have any...sth?
What is sth?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
first of all ... what is sth? in every english/foreign language dictionary they use "sth" instead of "something" .
ok and now straight to the point:
i need a function that queries database and that returns results as CRecordset:
<br />
CRecordset* CDB::Query(CString path, CString SQLstring)<br />
{<br />
...some declarations... <br />
<br />
TRY <br />
{<br />
...i open database and then:<br />
<br />
CRecordset* recset = new CRecordset(&db);<br />
recset.Open(CRecordset::forwardOnly, SQLstring, CRecordset::readOnly);<br />
return recset; <br />
db.Close();<br />
}<br />
CATCH(CDBException, dbex)<br />
{<br />
AfxMessageBox("Error: " + dbex->m_strError);<br />
}<br />
END_CATCH;<br />
}<br />
Than in the other class i'd like to use it...
<br />
CDB d;<br />
CRecordset *recset = d.Query(path,sqlstring);<br />
the result is that program compiles, when i run procedure form the second code snippet it's fine but recordset is "poisoned" . when i use any method of CRecordset class i get "debug assertion failed" error. i'm not too good in pointer stuff so it's quite possible it's something trivial .
|
|
|
|
|
scoroop wrote:
in every english/foreign language dictionary they use "sth" instead of "something"
Not in any dictionary that I have ever owned or used. That must be one of those online-specific things where folks type r instead of are and ur instead your.
scoroop wrote:
db.Close();
Why are you closing the database?
scoroop wrote:
when i use any method of CRecordset class i get "debug assertion failed" error.
It would help if you indicated what line of what file fired the assertion.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Not in any dictionary that I have ever owned or used. That must be one of those online-specific things where folks type r instead of are and ur instead your.
not at all... i have oxford collocations dictionary and collins dictionary... they use it as well. check it and you'll see it's quite common .
Why are you closing the database?
shouldn't i do it at the end of a function? if you say so, i assume that returned recordset passed to another function will need access to db. anyway i don't close db now but the result is the same...
what line of what file fired the assertion.
depends on the function that i use. when i want to browse recordset
recset->GetFieldValue(1,str);
i get error in afxdb.h line 680 and when i press retry i receive window with dbcore.cpp line 1920 (so it all stops on the method i used).
|
|
|
|
|
scoroop wrote:
they use it as well
Please provide an example.
scoroop wrote:
shouldn't i do it at the end of a function?
Only if you don't want to use it any more.
scoroop wrote:
i get error in afxdb.h line 680
This must not be Visual Studio v6 because line 680 of afxdb.h nor line 1920 of dbcore.cpp are assertions.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
it's VS 2003.
infact if i don't find solution for my problem i'll change that function a bit and use it as __inline, because query and its result are proper. the only problem is passing it to another class... anyway, my code above seems to be ok? i'm affraid that there might be something wrong with pointers...
|
|
|
|
|
scoroop wrote:
the only problem is passing it to another class
What does the code look like that passes the pointer to the other class' methods? And then what do those methods look like? It's hard to offer a solution to something when not all of the pieces have been shown.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
the other class is a window (dialog) class so there's nothing special. i click a button. it launches OnClickedButton function which calls my function Query(...) which is supposed to return recordset. then i want to browse it, extract necessary data and put it into listbox. and that's all. so the code i provided is almost complete. but i'll try to give you some more...
<br />
CRecordset* CDB::Query(CString path, CString SQLstring)<br />
{<br />
CDatabase db;<br />
CString driver,dsn;<br />
<br />
driver = GetDriver();
<br />
dsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s", driver, path);<br />
<br />
TRY <br />
{<br />
db.Open(NULL, false, false, dsn);<br />
CRecordset* recset = new CRecordset(&db);<br />
recset->Open(CRecordset::forwardOnly, SQLstring, CRecordset::readOnly);<br />
return recset; <br />
}<br />
CATCH(CDBException, dbex)<br />
{<br />
AfxMessageBox("Error: " + dbex->m_strError);<br />
}<br />
END_CATCH;<br />
}<br />
and then in OnClickedButton
<br />
void CBaseWindow::OnClickedButton1()<br />
{<br />
...
CString val;<br />
CDB d;<br />
CRecordset *recset = d.Query(path,sqlstring);<br />
<br />
<br />
short fields = recset->GetODBCFieldCount();<br />
while(!recset.IsEOF())<br />
{<br />
for(short i=0;i<fields;i++)<br />
{<br />
recset->GetFieldValue(i,val);<br />
}<br />
recset->MoveNext();<br />
}<br />
}<br />
that's the whole story...
|
|
|
|
|
I suspect the problem lies with db being a local variable in the Query() method. Once it goes out of scope, the database is closed.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
thanks a million . seems to be ok now .
|
|
|
|
|
I have programmed a DLL in order to encapsulate some code that is polling data from a USB peripheral unit. The user of the DLL must be able to define his own handler for that "Snapbutton" event.
To acheive this i am passing a function pointer to the DLL. The DLL then is calling back this function every time the event is detected on the peripheral unit.
This is working ok with the except that accessing MFC member functions does NOT always work. if i pass a pointer to the following function to my DLL i hear the beep every time the DLL calls the function but the checkbox is not set:
void CDemoDlg::SnapButtonHandler()<br />
{<br />
m_check_snap.SetCheck(TRUE); <br />
Beep(4000,50);<br />
}<br />
i have tried this code in a minimalist MFC application and it worked well but within a more complex MFC application it didn't work.
i suppose that calling an MFC member function from outside the MFC framework causes some problems. does anybody have an idea how i could solve that problem?
here is the code loading the DLL and passing the function pointer to it:
<br />
CEM2800DLLDemoDlg dlg;<br />
<br />
void HandleSnapButton() {dlg.SnapButtonHandler();}<br />
<big><br />
if i directly pass a pointer to a mfc member function to the DLL,<br />
i get an "illegal call of a non-static member function" error<br />
that is why i define that global function "HandleSnapButton"<br />
</big><br />
typedef BYTE (CALLBACK* SetSnapButtonHandlerType) (void(*ptr)()); <br />
<br />
<br />
void LoadSnapButtonDLL(void (*pHnd) ())<br />
{ <br />
if (!hClcltr) hClcltr=LoadLibrary(szDLLName);<br />
<br />
if (hClcltr) <br />
{ <br />
pSetSnapButtonHandler = (SetSnapButtonHandlerType)GetProcAddress( <br />
hClcltr,"SetSnapButtonHandler");<br />
<br />
if (pSetSnapButtonHandler) pSetSnapButtonHandler(pHnd);}<br />
}<br />
The DLL is loaded and the callback function pointer is passed to the DLL by LoadSnapButtonDLL(&HandleSnapButton);
Has anybody an idea why the access to methods of the MFC member variables like m_check_snap.SetCheck(TRUE); within the callback function are without effect?
i must admit i am a still a beginner in C++ and MFC programming so i would be very thankful for every hint.
Danny Kaiser
|
|
|
|
|
in general, you can't pass pointers to non-static member functions because non-static member functions require an object to operate on.
static member functions don't need an object (that's why they get to be called static).
there are tricks around that let you simulate a function call via function pointer on a non-static member function, but all i've seen are just clever ways of packaging the function call and a pointer to an object together in some other object. there are articles here on CodeProject that describe those approaches.
but, here's what i do: in our libraries, i always define the callbacks with an extra void * (or UINT32) parameter, ex:
typedef BOOL (CALLBACK* COMPLETION_CB_PTR)(int percentDone, void * pCBData);
then i do something like this:
void CMyObject::Foo()
{
DLLCallbackSetupFunction(cbFunction, this);
}
BOOL CALLBACK cbFunction(int pctDone, void *pCBData)
{
CMyObject * pObj = (CMyObject*)pCBData;
pObj->Bar(pctDone);
}
void CMyObject::Bar(int iPctDone)
{
... whatever
}
you just need to make sure the DLL passes the cbData back to the callback function:
...
void *g_pCBData;
COMPLETION_CB_PTR g_pCB;
...
DLLCallbackSetupFunction(COMPLETION_CB_PTR pCB, void *pCBData)
{
g_pCB = pCB;
g_pCBData = pCBData;
}
then, something calls the callback
if (g_pCB)
{
(g_pCB)(iPctDone, g_pCBData);
}
-c
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Hi all,
I am trying to manipulate a Windows Security Template. I want to do it progrmatically rather than using the Security Template Snap-in. Does any one have an idea of where I can start or what COM interfaces I can use for the same.
Any resources in this regard will be helpful
Thanks
Arthi
|
|
|
|
|
Hi,
I have a virtual list-view in icon-view and want to move the items. I tried to use ListView_SetItemPosition, but it always fails. Is there a problem with virtual list-views or can I do it in a different way?
|
|
|
|
|
Hello everyone:
Now i have a modal dialog popup when i clicked a toolbar item. now i want that dialog to be embeded into the frame and cover the client area of the frame. That means the dialog i need is just like the new window popup when we click file->new.
any opinion will be appreciated ,thanx in advance!!!!!!!!!!!
|
|
|
|
|
Hi to all,
My name is Bruno and I am an Italian programmer.
I've a problem.
I need to write a program that make a map for apply texture on a various images that contains object (ex. Sofa', chairs, dressed, ...) to change his color/textures.
I've founded software. Look at this:
http://www.nedgraphics-porini.com/Default.aspx?SiteID=7&PageID=166
I've marked 3 extremely hard phases.
1: create a map for curves and angles:
- Algorithm to draw a 3d curve with GDI (2D)
- Algorithm to transform create curve
- Save the curve for future visualization
2: Map texture to curve (texture mapping)
3: Overlay original image with textured map
For the third phase I've supposed to use the base pixel brightness and draw the texture pixel with the same brightness.
The result is ok but work fine just with flat colors because if I use a texture this is so flat.
Therefore I need texture mapping.
Have you a line guide for me?
I've considered using Ray Casting technique or quite DirectX/OpenGL
Tanks for your time.
Bruno
Sorry for my terrible English
|
|
|
|
|
hi
is it is must in mfc that the new classed( own made or made by myself) should be inherited from previous calls like Cdialog, Cobject,Cfrom and cannot write own calss that is not inheried from anyone. i m using vc6.
ddd
|
|
|
|
|
Nope, not at all - a class doesn't have to be derived from anything
e.g.
class CMyClass
{
public:
CMyClass();
~CMyClass();
private:
CString m_strSomeString;
}
That uses MFC's CString, but the class doesn't inherit from anything
--
Help me! I'm turning into a grapefruit!
Buzzwords!
|
|
|
|
|
through which option present in mfc these are made. the other options are mfc appwizard,win32 console etc.
ddd
|
|
|
|
|
Those are the types of application that you can have - not specifically classes - A class needs to exist within some kind of application, otherwise it won't do you much good
--
Help me! I'm turning into a grapefruit!
Buzzwords!
|
|
|
|
|
i thing u had not understood my question. through which options those application are made.
when u open visual c++ then there are three tabs Files , project and docmtns.
throgh which option classes will me made i think project or file. now i think u understood my questions.
ddd
|
|
|
|
|
i exactly want to create this type of class but when u logon to visual c6 environamnet options are file,project,document. i think from project which thing to choose to made such a file.
ddd
|
|
|
|
|
Select Generic class option from ClassWizard!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
Select Generic class option from...
...the Insert/New Class menu option, not ClassWizard.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
DavidCrow wrote:
the Insert/New Class menu option, not ClassWizard.
Oops Sorry!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|