My problem: A program was using 127.0.0.2 (an alias for 127.0.0.1) to make a local connection on a specific port. However, one Windows 2003 server box was configured so that this port was being listened to on a specific network adapter (and hence a specific IP address). Hence, my local connection failed even though the [...]
Archive for the ‘C++’ Category
Getting listening ports and addresses programmatically
Posted in C++, Sockets, Windows API on November 10, 2007 | Leave a Comment »
“Loss of information”
Posted in C++, Windows, Windows API on August 8, 2007 | Leave a Comment »
I’ve always wondered (and again two days ago) what “irreversible loss of information” is being referd to when you reset a local user password from the “Computer Management” console. Independantly, I’ve been tracking down a bug reported by one PMG Connect user in which the connection routine fails.
These things are linked. The bug was a call [...]
Block Sock Block
Posted in C++, Sockets, Windows, Windows API on August 7, 2007 | Leave a Comment »
WinHttpGetProxyForUrl also blocks. This is despite the documentation saying that it won’t if you close the handle during it’s operation. (Let’s face it, Microsoft programmers often have a very loose sense of the meaning of block, what’s a minute or two.) Anyway, this called for a generic class for blocking things (see previous post re [...]
Managed, Unmanaged and COM
Posted in .NET, C++, COM on July 6, 2007 | 2 Comments »
I’m wrapping a legacy lib for use in a .NET envirment.
Usefull: An Overview of Managed/Unmanaged Code Interoperability
Firstly, I tried to wrap the lib api with COM and use that from my C# app. With speed and efficiecency a priority, this was unacceptable. It involves callbacks (legacy lib) or events (COM) – the big slowdown happened in [...]
Custom Draw Toolbar
Posted in C++ on June 24, 2007 | Leave a Comment »
After WPF, spending time with NM_CUSTOMDRAW seemed like running somewhere, when one could catch a bus. Someday, we may even do it’s like for pleasure.
My problem: I couldn’t get the separators to draw on my owner draw toolbar. Apparently, the NM_CUSTOMDRAW doesn’t send a CDDS_ITEMPOSTPAINT for separators. So, the way to do it is draw your separator over [...]
Lazy Value
Posted in C++ on June 23, 2007 | Leave a Comment »
I wanted to replace a const int with a lazily evalueated int. It had to be lazy evaluated as all that was needed to calculate it was not available when the class is instanciated but was available before the int was needed. I didn’t want to change the code that uses the int. So, I made this class:
template <class T>
class CLazyValue
{
public:
CLazyValue() : [...]
Does the file exists
Posted in C++ on June 23, 2007 | Leave a Comment »
After about 16 years of writing C++ on Windows I’m sure there’s been many an occasion with the need to test if a file exists. Today, I discovered a new way to check!
bool FileExists(const extra::tstring &file)
{
OFSTRUCT of = {sizeof(of)};
return (OpenFile(CT2CA(file.c_str()),&of,OF_EXIST)!=HFILE_ERROR);
}
Where an extra::tstring is declared such (part of my library of code):
typedef std::basic_string<TCHAR>tstring;
Apparently it [...]
The easiest way to test A COM object
Posted in C++ on June 20, 2007 | Leave a Comment »
This is assuming your COM object is a dual interface object (implements IDispatch).
1) Create a text file with a .js extension (eg: test.js)
2) Load the file into Visual Studio.
3) Put the following line at the top:
var arbiObj = new ActiveXObject(“ArbiCOM.ArbiClassProx”);
where “ArbiCOM.ArbiClassProx” is the prog id of your COM object.
4) VS will have intelisense (bellow type [...]