new Win32Exception(win32ErrorCode).Message
Martijn van Kleef
Posts
-
How to translate Win32 error codes -
remoting and client devices that switch network cards on the flyHi, I'm really hoping for an easy answer to this issue. I have a client device that uses a hardwired connection to communicate with its server if it is in a docking station. If lifted from the docking station the hardwired connection is disabled and it switches to its wireless connection. This is where remoting stops working on the serverside. The client device has 2 network cards with different IPs, one for the hardwired connection and one for the wireless connection. When switching to wireless/hardwired the client is still able to send messages to the server, but apparently the server is still trying to reach the client on the connection it initially used so the return messages fail. How is this fixed? Where is this fixed? I've tried to call RemotingServices.Configure again but it seems you can only call that once. Unregistering and re-Registering channels doesn't seem to work either. Any ideas would be greatly appreciated! Solutions even more!
-
remoting and client devices that switch network cards on the flyHi, I'm really hoping for an easy answer to this issue. I have a client device that uses a hardwired connection to communicate with its server if it is in a docking station. If lifted from the docking station the hardwired connection is disabled and it switches to its wireless connection. This is where remoting stops working on the serverside. The client device has 2 network cards with different IPs, one for the hardwired connection and one for the wireless connection. When switching to wireless/hardwired the client is still able to send messages to the server, but apparently the server is still trying to reach the client on the connection it initially used so the return messages fail. How is this fixed? Where is this fixed? I've tried to call RemotingServices.Configure again but it seems you can only call that once. Unregistering and re-Registering channels doesn't seem to work either. Any ideas would be greatly appreciated! Solutions even more!
-
generate a Console.ReadlineHello, I have an application that has a thread waiting on a Console.Readline to finish. Aborting the thread using Thread.Abort won't work. But if I could generate a Console.Readline the thread would end in a controlled fashion. But, how do I generate something that triggers a Console.Readline from within my application? Please help.
-
Multicolumn CListCtrl & custom DrawItemHi, Can anyone please help me implement a custom (override) DrawItem method for a multicolumn CListCtrl, in particular for the individual columns / subitems? Here's what I have so far:
void CColoredListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CString csItemText = GetItemText(lpDrawItemStruct->itemID, 0); CDC dc; dc.Attach(lpDrawItemStruct->hDC); // Save these value to restore them when done drawing COLORREF crOldTextColor = dc.GetTextColor(); COLORREF crOldBkColor = dc.GetBkColor(); if (lpDrawItemStruct->itemData != NULL) dc.SetTextColor((COLORREF)lpDrawItemStruct->itemData); if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) { dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT)); } else { if ((lpDrawItemStruct->itemID % 2) == 1) dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_BTNFACE)); else dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_WINDOW)); } // Draw the text dc.DrawText(csItemText.GetBuffer(), csItemText.GetLength(), &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER); // Reset the background color and the text color back to their original values dc.SetTextColor(crOldTextColor); dc.SetBkColor(crOldBkColor); dc.Detach(); }
I'm having trouble with the very first line in this method. It always gets the itemtext of the first column, but I'm having a multicolumn listctrl so I also need to know which subitem to get. This method is called from calls to CListCtrl::InsertItem and CListCtrl::SetItemText which get called in a multithreaded context. I was hoping the LPDRAWITEMSTRUCT would have subitem info but it doesn't seem to. Also, does the lpDrawItemStruct->itemData member contain the info that was set by calls to CListCtrl::SetItemData?? -
type casting function pointersActually that won't work.. If I use the union solution posted previously my compiler (Visual Studio .NET 2003) complains: error C2475: 'CSomeClass::SomeMethod' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name An implementation according to the suggestion of the compiler seems to work though:
Address.pMethod = &CSomeClass::SomeMethod;
But now, where on earth did all the fuss about the this pointer go?? Did I just seem to have discarded it?? -
type casting function pointersSorry, didn't include it because this: c:\Documents and Settings\Martijnv\My Documents\Visual Studio Projects\TestWin32Console\TestWin32Console\TestWin32Console.cpp(193) : error C2440: 'type cast' : cannot convert from 'void (__thiscall X::* )(void)' to 'DWORD' There is no context in which this conversion is possible ...still doesn't tell me why I CAN cast the static global function to DWORD but CANNOT cast the non-static class member function.
-
type casting function pointersWhy can I cast a pointer to a static non-class function to DWORD (for example), but not a pointer to a non-static class function? (The compiler generates an error if you try) ie: DWORD dw1 = (DWORD)fnStaticGlobalFunc; // OK DWORD dw2 = (DWORD)pMyClass->fnClassLocalFunc; // Error
-
Thread Local StorageCan anyone please tell me the usefulness of thread local storage compared to a more OO solution involving a base class for workerthreads and variables?
-
ChartsFor every line of your output: the first number corresponds to the linenumber divided by 4 and multiplied by pi, and the second number corresponds to the something like the sin/cos of the first number. sin/cos/sinh/cosh/acos/asin are in the C++ CRT. I'm not gonna explain their use, your teacher should.
-
ChartsThe general formula to generate these numbers (if that's what you were after, your post is unclear to me) seems to be in pseudocode
start at 0,0 number1 = linenr/4 * pi number2 = something like cos/sin of number1
-
basic question to .h and .cpp filesIn general, I think everyone will agree that header files should be used for declarations, and source files for definitions. Actually, sometimes you won't be able to do without source files. For example for static variables, for initialization of global variables, etc etc
-
how to maintain text file constantHow about (temporarily) using a copy of the text file instead and add to that?
-
namespace does not existThat should compile OK on any machine. Exactly on what line did you get the error message? Maybe where the error is generated your code is at a different scope not within that of your "using" declaration? Maybe where the error is generated the header file with your "using" declaration is not included?
-
function pointers to user-defined functionsHi, I'm trying to construct a library which features a class that should be able take a pointer to any user-defined function (preferably in a user-friendly way). Now, I've tried a templated approach which seems to work, but inheriting from template classes seems rather a pain and dito for all the different function pointer types. Small example:
#pragma once // Functor interface class template < typename _TReturn, typename _TArg> class IExecute { public: // WARNING: USE OF TYPE void AS ARGUMENT TYPE IS NOT SUPPORTED! (REQUIRES MORE DERIVED CLASSES) typedef typename _TReturn _return_type; // Interface functor return type typedef typename _TArg _arg_type; // Interface functor parameter type typedef void _class_type; // Dummy required for template consistency virtual ~IExecute(void) = 0; virtual _TReturn Execute(_TArg _Arg) = 0; // Interface functor execute function }; // Interface functor inline pure virtual destructor defined template < typename _TReturn, typename _TArg> inline IExecute< _TReturn, _TArg >::~IExecute(void) { } // Functor derived class for pointers to functions that are non-const class or namespace members (const members REQUIRES MORE DERIVED CLASSES) template < typename _TClass, typename _TReturn = unsigned int, typename _TArg = void * > class CExecuteMember : public IExecute < _TReturn, _TArg > { protected: // _ptr_type is a typedef for a pointer to a class member function of which the return and parameter type // are defined at instantiation of CExecuteMember. If multiple return or parameter values are required use a // struct pointer instead typedef _return_type (_TClass::*_ptr_type)(_arg_type); // Derived functor pointer-to-function type typedef typename _TClass _class_type; // Override for derived functor class type _class_type * m_lpClass; // Derived functor class pointer _ptr_type m_lpRoutine; // Derived functor pointer-to-function public: CExecuteMember(void) : m_lpClass(NULL), m_lpRoutine(NULL) { } CExecuteMember(_class_type * _Class, _ptr_type _Routine) : m_lpClass(_Class), m_lpRoutine(_Routine) { } ~CExecuteMember(void) { } _return_type Execute(_arg_type _Arg) // Execute a class member function { if (this->m_lpRoutine == NULL) throw std::runtime_error("No routine pointer exists"); if (this->m_lpClass == NULL) throw std::runtime_error("No class pointer exists"); return (m_lpClass->*m_lpRoutine)(_Arg);
-
Summer & Winter timeWell I still don't know how to easily check exactly when a switch between winter and summer time would occur, but I did figure out how to determine which one of the 2 is in effect at any given date x. The Daylight Savings Time flag indicates whether the current time for your locale is summertime (1) or wintertime (0), example:
time_t t1; // Get current time (our given date x) time(&t1); // Adjust for locale struct tm * t2 = localtime(&t1); printf("DST Now:%d\n", t2->tm_isdst); // Substract 90 days t1 -= 7776000; // Adjust for locale t2 = localtime(&t1); printf("DST Then:%d\n", t2->tm_isdst);
Still trying to find out exactly when shifts occur though. -
Summer & Winter timeHow do I check whether it's summertime or wintertime for a given date x? How do I determine when switches between summertime and wintertime occur?
-
Random numbersTo produce random numbers from 0 to some predefined limit it would probably be easiest to do: #define RAND_MAX_LIMIT 15 // Set 15 as limit for randomly generated values srand((unsigned)time(NULL)); // Seed random number generator with current time int Random = rand() % (RAND_MAX_LIMIT + 1); // Only generate numbers between 0 and your predefined limit
-
SuspendThread & TerminateThreadI find the VS help to be a little vague on this method, does SuspendThread halt execution of a thread -immediately-? And what if the thread contains some no-user-mode code? Can I use it to decently halt a thread before calling TerminateThread to brutally kill it? PS: I'm using TerminateThread because in one of my threads I'm calling into a function of a third-party lib (out of my control) that sometimes hangs. TerminateThread seems the only option left to stop the hanging (now threaded) function and retain control over application execution.