|
Take a look at the following ODBC 1.0 function:
SQLConfigDataSource()
It's exactly what you are looking for.
"Well I'm just a hard working corporate slave, my mind should hate what my body does crave.
Well I'm just a humble corporate slave, driving myself into a corporate grave"
Corporate Slave, SNOG
|
|
|
|
|
It worked!!
Thanks a lot, you really helped me a lot there
|
|
|
|
|
I'm trying to better understand how operator=() overloading works. I have the following code:
CBase* pB1 = new CDerived( 1, 2 );
CBase* pB2 = new CDerived( 10, 20 );
*pB1 = *pB2;
The first argument to the CDerived constructor is assigned to a data member in CBase and the second argument is assigned to a data member in CDerived. I have overloaded operator=() for both CBase and CDerived like this:
CBase& operator=( const CBase& src )
{
m_nBaseData = src.m_nBaseData;
return *this;
}
CDerived& operator=( const CDerived& src )
{
m_nDerivedData = src.m_nDerivedData;
return *this;
}
When I wrote *pB1 = *pB2; (like in the code above), I was expecting both operator=() functions to be called and thus both the CBase data member and the CDerived data member to be copied. However, my pointers being pointers to CBase rather that CDerived, only the CBase::operator=() function was called, resulting in a partial copy of the derived object.
I tried making both functions virtual, but the result was the same. The only way I found that resulted in a complete copy is by making my pointers CDerived pointers and adding the following line at the beginning of CDerived::operator=():
*(CBase*)this = (const CBase&)src;
Unfortunately, this is not a good solution since it is quite common that I need to store pointers to a base class without knowing exactly what the object is.
So, my question is did I miss something somewhere? Is there a way to have objects copy completely with pointers to their base class?
Thanks!
|
|
|
|
|
You *could* do a <dynamic_cast> in your operator = to see if you have a derived object and make the copy happen. But that's a little tedious and an implimentation nightmare if your class structure will be extended/changed. I'm sure there is a better solution, but it escapes me at the moment.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
It'd probably be fairly easy to make a bot that'd post random stupid VB questions, and nobody would probably ever notice - benjymous - 21-Jan-2003
|
|
|
|
|
Assignment operators are not virtual, they are looked up at compile-time. When you hold a pointer to base, pB, and tell the compiler you want to assign something to this base object, as in
*pB = whatever;
it emits a call to Base::operator=(whatever).
On your second problem; from the derived class' operator= call the baseclass' op=, as in:
CDerived& operator=( const CDerived& src )
{
Base::operator=(src);
m_nDerivedData = src.m_nDerivedData; return *this;
}
Depending on compiler (i.e. MSVC6) you sometimes have to introduce a temporary pointer, like:
Base* p = this;
*p = src;
...
++luck;
|
|
|
|
|
For classes like this, I always create a virtual function named "Copy", the operator= then calls it's open "Copy" function. If the base class has a Copy function, the derived class usually calls it, otherwise it usually calls the base class's operator= function (yes, there are times, albeit rare, I do the copy entirely in the derived class.)
(I almost always have a function equivilents to operators, though these functions may incorporate several operators, like "Compare".)
|
|
|
|
|
and by the way, disabling Alt+Enter, Alt+tab, Ctrl+Escape, when the app is fullscreen. I know the W98 screensaver trick, I tried several NT tricks but none of them apply to Windows XP. I am searching for C/C++ coding.
Thank you.
|
|
|
|
|
If you want to do programatically (I don't know any other way to do it , but I'm novice...) you must install a system wide keyboard hook.
In that hook (that must be placed in a DLL) you can handle all the key presses (except the mytical Ctrl+Alt+Del that must be handled in a GINA.DLL).
If you want to install that hook from the beggining you can install an autostart service that activates it.
Hope this helps.
|
|
|
|
|
Hello.
I need to implement a template class that would have the same functionality as std::vector plus several other functions - practically extending vector. The easiest way to accomplish this would be to publicly derive this class from vector, but from everything I know this is considered a bad thing because vector has no virtual functions, and the relation between my class and vector is "implemented in terms of" rather than "is kind of". Any advice?
|
|
|
|
|
I know for a fact that std::string has no virtual destructor to stop people from deriving from it, std::vector sounds the same, if by 'no virtual functions' you also mean no virtual destructor. You need to contain a vector and then expose the methods you want to use in your own class, adding whatever you're after. Or consider the nature of your additions, perhaps they should be function objects that rely on random access iterators ( if necessary ).
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
It'd probably be fairly easy to make a bot that'd post random stupid VB questions, and nobody would probably ever notice - benjymous - 21-Jan-2003
|
|
|
|
|
Christian Graus wrote:
You need to contain a vector and then expose the methods you want to use in your own class, adding whatever you're after.
Yes, I thought about it. However, I need "everything" from std::vector, and it would be tedious to rewrite all public methods from it. Public inheritance would allow me to reuse std::vector's interface and add my additional functions quickly. Now what practical implications would be? I mean, who would use polymorfism with std::vector?
|
|
|
|
|
So long as you don't introduce any data it should work just fine to derive from std::vector.
The only time (I can come to think of right now) when you need a virtual destructor, is when subclasses also contain data (that would otherwise not be destructed when deleting the subclass using a pointer-to-base).
|
|
|
|
|
Thanks. I think you are right.
|
|
|
|
|
Why not have a class with std::vector as a public member, and some interface functions for the other stuff you want to do? Or will that somehow defeat the purpose?
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
It would break a lot of existing code. This template class (which I need to reimplement) must have exactly the same interface as std::vector plus several extra functions.
|
|
|
|
|
I want to change the screen saver without any message to user? Can u help me out?
Mahesh
|
|
|
|
|
I've looked into this with no success....I'm not sure if it's possible....
|
|
|
|
|
Hello,
is the memory allocated by the GlobalAlloc function really global? Can different processes access the same memory block allocated by GlobalAlloc?
Thanks
-Dominik
|
|
|
|
|
No. Memory allocated by GlobalAlloc is not visible to other process. If you want to share memory across process, i sugest that you use memory mapped files.
Also, MSDN state that GlobalAlloc is not the preferred way to allocate memory. Try the heap memory function instead (HeapAlloc, HeapFree, ect,ect).
|
|
|
|
|
Ok, I will use memory mapped files.
Thank you!
-Dominik
|
|
|
|
|
When you call ::CreateFileMapping with (HANDLE) LongToHandle(-1) as the first parameter, PAGE_READWRITE as the protection and a name, which is how other applications will access it by calling OpenFileMapping . If the creator will be in one set of permissions (like a service logged in as an administrator) and the other application will have lower permissions, you'll need to create and use SECURITY_ATTRIBUTES (you can create a NULL security attribute which essentially grants global rights to the memory.)
|
|
|
|
|
Hi,
I have a problem splitting up a string.
I have a thread which will send a string to my main thread by posting a message.
I therefore create my string
<br />
CString *s = new CString();<br />
s->Format("%s#@@#%s", _T("Error"), _T("ErrorMessage"));<br />
PostMessage(UWM_SENDSTRING, (WPARAM)i, (LPARAM)s);<br />
The code is successfully received by my function.
However, here is where it goes wrong.
<br />
LRESULT CMyView::OnSendString(WPARAM wparam, LPARAM lparam)<br />
{<br />
CString *s = (CString*)lparam;<br />
TRACE0(*s);
<br />
int pos = s->Find(_T("#@@#"));
TRACE0(s->Left(pos));
TRACE0(s->Right(s->GetLength()-(pos+4)));
<br />
delete s;<br />
<br />
<br />
So basically when I show the string, compute a position or show the length of *s everything is fine.
When I just want a part of the string, the first or last, I get a lot of crap or the program just crashes.
When I do all of that splitting in a normal procedure whit normal CString (not dynamically allocated), I get the results thaat I want, namely he part before #@@# and the part after that.
Any ideas how I can let this Left/Right splitting thing work on dynamic CStrings?
tia
Wim
|
|
|
|
|
Try setting a watchpoint (breakpoint on a data address) on s after you create it, and before the PostMessage call. It sounds like something else is modifying it. Also, have you single stepped through the OnSendString function, and watched the contents of s in the Watch window?
Software Zen: delete this;
|
|
|
|
|
I don't think what you are doing is allowed, in effect posting a class, I am sure someone will confirm/deny that, so why not do:-
CString *s = new CString();<br />
s->Format("%s#@@#%s", _T("Error"), _T("ErrorMessage"));<br />
TCHAR *sz = new char[s.GetLength() + 1);<br />
strcpy(sz, s->GetBuffer(0));<br />
PostMessage(UWM_SENDSTRING, (WPARAM)i, (LPARAM)sz);
Note the code is not 100% correct, e.g. strcpy should not be used if you are using UNICODE
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
This is probablya bit late (its a public holiday down here in Australia, but I got suckered into coming into the office anyway)
anyway, see this link for an explanation and working code on posting CStrings (look for "Passing Pointers in Messages") - Note well one of Joe's comments "However, if you ever plan to use PostMessage to pass a pointer to an object, then you are constrained to always use a static or heap-based object"
http://www.pgh.net/~newcomer/messages.htm[^]
Hope this helps ...
'G' <- Grinch !!!
|
|
|
|