Click here to Skip to main content
15,915,508 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Help File Pin
act_x6-Dec-02 9:43
act_x6-Dec-02 9:43 
GeneralRe: Help File Pin
Paul M Watt6-Dec-02 10:27
mentorPaul M Watt6-Dec-02 10:27 
GeneralThank you all Pin
act_x6-Dec-02 10:39
act_x6-Dec-02 10:39 
GeneralRe: Help File Pin
Gaul7-Dec-02 19:14
Gaul7-Dec-02 19:14 
GeneralRe: Help File Pin
lucy9-Dec-02 2:21
lucy9-Dec-02 2:21 
GeneralHWND to a UIThread Pin
David_Leikis6-Dec-02 8:35
David_Leikis6-Dec-02 8:35 
GeneralRe: HWND to a UIThread Pin
KaЯl7-Dec-02 1:59
KaЯl7-Dec-02 1:59 
GeneralProblem with auto_ptr !!! Pin
Luc Bergeron6-Dec-02 8:30
Luc Bergeron6-Dec-02 8:30 
Hello to all.

I've checked this following article (http://www.cuj.com/experts/1906/hyslop.htm?topic=experts) at CUJ web site and decided to use it in my own application.


So here we go. I have managed to implement the factory inside a windows DLL. But i'm having weird problems with it. Mainly the genericFactory::create method.

This is how i've implemented it (with the modification that I use a pointer to a function with three std::string parameters) :
template <class manufacturedobj,="" typename="" classidkey="">
std::auto_ptr<manufacturedobj>
genericFactory<manufacturedobj, classidkey="">::create(const classIDKey &className,
const std::string& p1,
const std::string& p2,
const std::string& p3) const
{
std::auto_ptr<manufacturedobj> ret(0);
FN_REGISTRY::const_iterator regEntry=registry.find(className);
if (regEntry != registry.end())
{
ret = regEntry->second(p1, p2, p3);
}

return ret;
}

And in my client code this is how I call it :
std::auto_ptr<mysqltable> tbl(0);
tbl = genericFactory<mysqltable>::instance().create("HistoricalDataTbl", host, user, pwd);
-----------------------------------------------------------------------------------------------

When I trace inside the create method, the "ret" variable is fine and points to a valid MySQLTable object. BUT, when the function returns to the client code... I get an unhandled exception error. This error is generated inside the auto_ptr<>::reset() method. To be more precise, the "tbl" auto_ptr in the client code is supposed to be initialized with a NULL pointer but when getting back from genericFactory::create method the "tbl" pointer points to an invalid MySQLTable object.

The quilty code inside auto_ptr :
void reset(_Tp* __px=0) {
_Tp* __pt = this->get();
if (__px != __pt)
delete __pt; //offending line...
this->__set(__px);
}

So i'm currently puzzled has to why the "tbl" variable points to a bad MySQLTable object!?!?!?!

Any help would be greatly appreciated Big Grin | :-D

Luc.
GeneralRe: Problem with auto_ptr !!! Pin
Alvaro Mendez6-Dec-02 9:50
Alvaro Mendez6-Dec-02 9:50 
GeneralRe: Problem with auto_ptr !!! Pin
Luc Bergeron6-Dec-02 10:01
Luc Bergeron6-Dec-02 10:01 
QuestionDynamic CEdit can't call DoDataExchange()? Pin
dazinith6-Dec-02 8:20
dazinith6-Dec-02 8:20 
AnswerRe: Dynamic CEdit can't call DoDataExchange()? Pin
Sara Burns6-Dec-02 11:00
Sara Burns6-Dec-02 11:00 
AnswerRe: Dynamic CEdit can't call DoDataExchange()? Pin
worm7-Dec-02 14:43
worm7-Dec-02 14:43 
GeneralChange window style Pin
Member 997186-Dec-02 8:19
Member 997186-Dec-02 8:19 
GeneralRe: Change window style Pin
Maximilien6-Dec-02 8:30
Maximilien6-Dec-02 8:30 
GeneralRe: Change window style Pin
Member 997186-Dec-02 9:29
Member 997186-Dec-02 9:29 
GeneralHovering text... Pin
Maximilien6-Dec-02 8:01
Maximilien6-Dec-02 8:01 
GeneralDetected memory leaks! :( Pin
lucy6-Dec-02 7:04
lucy6-Dec-02 7:04 
GeneralRe: Detected memory leaks! :( Pin
Roger Allen6-Dec-02 7:23
Roger Allen6-Dec-02 7:23 
GeneralRe: Detected memory leaks! :( Pin
lucy6-Dec-02 7:32
lucy6-Dec-02 7:32 
GeneralRe: Detected memory leaks! :( Pin
lucy6-Dec-02 7:37
lucy6-Dec-02 7:37 
GeneralRe: Magic of StdAfx.h?? Pin
lucy6-Dec-02 8:00
lucy6-Dec-02 8:00 
GeneralMFC Controls and Thread Safety :: MFC Pin
valikac6-Dec-02 6:38
valikac6-Dec-02 6:38 
GeneralGerman characters Pin
RAZ6-Dec-02 6:06
RAZ6-Dec-02 6:06 
Questionhow to get the data of video card to store as BMP? Pin
jarred6-Dec-02 6:07
jarred6-Dec-02 6:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.