|
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
|
|
|
|
|
can we create that just we create in c++ file.
like
class mycalss {
int i;
public:
mufunc();
};
this type of application or the class how to create in MFC or it is not possible and strict to cobject as u told earlier.
ddd
|
|
|
|
|
tasleem143 wrote:
can we create that just we create in c++ file.
like
class mycalss {
int i;
public:
mufunc();
};
Yeah Mr. Tasleem!
You can create class as you mentioned/written above. It's not compulsary/necessary to inherit class from CObject to use that In MFC.
tasleem143 wrote:
cobject as u told earlier.
ME.. When!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
hi
i had made my application in vc using MFC application wizard. now i want when the application start the dialog should no be visible. i had used the function in the onitnitdialog function
GetDlgitem(idofdialog)->showWindow(false);
it give no compiler error but when run it gives error.
other functions are also there but they require the handle of window or dialog how to get that.
is any other function through which i can hide the dialog.
ddd
|
|
|
|
|
try just
ShowWindow(SW_HIDE);;
on it's own (in your oninitdialog)
--
Help me! I'm turning into a grapefruit!
Buzzwords!
|
|
|
|
|
i had tried it onititdialog but does not worked then i used in the event(button clicked) and it worked but i dont want to do it in the button click.i want when it start it hides himself(dialog).
ddd
|
|
|
|
|
|
does anyone know a class for beginners to get samplerate bitrate and time of a mp3?
|
|
|
|
|