Yes, this is safe. A reference is an alias for an object that exists elsewhere - in the map, in this case. When a reference goes out of scope, the referenced object still exists and no destructor call is made. In this respect, references work like pointers. Brad
Brad Sokol
Posts
-
Is this safe? (map) -
C++ StandardsI looked a while back. On the ISO site (http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=25845&ICS1=35&ICS2=60&ICS3=[^] it's 364 Swiss francs :( I decided I didn't need it that badly :) Brad
-
How to create a win32 static library?VC6 has a project type called 'Win32 Static Library'. There is no need to export functions from a static library. Just provide a header file with a declaration. Brad
-
SEH problem between debug and release versionYou need to provide a bit more context about your code. That said, I ran into something similar which may be the problem you're having. I had code similar to this:
int* pi = NULL; int i = *pi; // Generates an access violation
In debug builds, an exception was thrown from my SE handler and caught, but not in release builds. As it turned out, in release builds, the optimiser was correctly removing this code because it had no effect. :doh: Not sure what you're doing, but if it's simple test case like mine, you might want to turn off the optimiser for that block of code:#pragma optimize("", off)
Brad -
interrupt handling in win2kI'm pretty sure that you need to run in ring 0 which means you write a device driver or similar kernel-mode code. Brad
-
OCX questionAll COM servers (ActiveX) need to be registered. You can use the regsvr32.exe utility to register .OCX files. Brad
-
Importing a DLL from a classHmm...I think you may be a bit confused on how to program with COM ojbects and how they're used at run-time. #import is used only at compile time to include declarations of objects supported by the COM DLL. The path is only relevant on the computer where your code is being compiled. This is very similar to #include. At install time, you must register any COM components that you install. This adds entries to the registry that the COM APIs use to find the DLLs and create the proper execution environment for the components. Most COM DLLs export a function called
DllRegisterServer
which the DLL author must provide to perform the necessary registration steps. Most installer packages (InstallShield, Wise, etc.) will call this function if you specify the DLL as requiring registration. You can also register a component using the regsvr32.exe utility, which callsDllRegisterServer
. So, the path to the DLL is established at registration time and stored in the registry. You can install the DLL anywhere. At run time, you instantiate an instance of a coclass by specifying either a CLSID or PROGID. The COM APICoCreateInstance
(which is either called by the smart pointer, or by your code directly, depending on how you've written things), performs a lookup in the registry to find the location of the DLL. A warning about installing MSXML yourself. With later versions of the parser, there are more than one DLL. I'm not sure about V1.0. You are probably better off finding out what installation method Microsoft recommendeds. They probably have an installation package that you can re-distribute. That installer will install all required components and perform the necessary registration. Secondly, V1.0 is very old. Newer versions support more of the XML and related standards. Finally, depending on what OS you're targetting, a version of the parser may already be installed. HTH Brad -
debug assertion failedDebug assertions typically aren't compiled into release code, so this likely is in the DLL rather than regsvr32.exe. As well, olefact.cpp is an MFC file, so likely not part of regsvr32.exe. Try running the whole thing under the debugger so that you can break when the assertion trips and look at the call stack. Brad
-
Importing a DLL from a classBecase MSXML.dll implements a bunch of COM objects, you don't need to do an explicit
LoadLibrary
call. COM takes care of this for you when youCreateInstance
a new instance of a coclass. You only need to know the class id or progid. COM looks up the rest in the registry. That said, you obviously need to have the correct version of the MS XML parser installed on the client machine. Different COM class names map to different versions of the DLL. Brad -
C++ Regex Library -
the problem of SEHGetting a stack trace including source file and line number is possible in both debug and release builds. The key is the
EXCEPTION_POINTERS
parameter. You need to use the symbols engine API which is in the dbghelp.dll library in the Platform SDK to translate the exception pointers into more useful information. The best reference I've found for this is "Debugging Windows Applications" by John Robbins. He used to write the Bug Slayer column in MSDN magazine. You can find lots of his archived articles over at the href='http://msdn.microsoft.com'>MSDN site. There is probably lots of useful stuff elswhere on the web but I don't have any links handy. Google for StackWalk or "win32 stack trace" and you'll probably find some useful links. HTH Brad -
where will I find dbgheap.c etcIt's part of the C run-time library source. This is not installed by default with Visual C++ 6. If installed, it is in \Program Files\Microsoft Visual Studio\VC98\CRT\SRC. If not installed, just re-run the installer and install the C run-time source as an additional component. For Visual C++ 7.x, it's in \Program Files\Microsoft Visual Studio .NET\Vc7\crt\src or \Program Files\Microsoft Visual Studio .NET 2003\Vc7\crt\src, depending which version you have installed. I can't remember if it's installed as part of the default setup or if you have to drill into the install options to select it. Brad
-
Is one way better than the other?The following two lines are equivalent:
std::string s1("one"); // Example 1 std::string s2 = "two"; // Example 2
If I recall correctly, there is a standard "short-cut" that compilers can (must?) take to make example 2 above work like example 1. In other words, declaration with assignment is optimised to a constructor provided that an appropriatly overloaded constructor exists. If no constructor, you get a compiler error. Either would likely be faster then default constructor followed byFormat()
for two reasons. First, it's two steps. Second,Format()
is probably slow with all that string parsing. Of course, YMMV. Brad -
Problem with threadChoice e) might be let the thread naturally relinquish the CPU by blocking on an I/O or message queue, for example. Depending on how often/long it blocks, this may be enough. Brad
-
the problem of SEHThe function
GetExceptionInformation
can only be used in the context of an__except
block. An easy way to use structured exceptions is to define an SE handler using the C run-time function_set_se_translator()
. The CRT takes care of wiring everything together for you, so you don't have to worry aboutSetUnhandledExceptionFilter
etc. You can even avoid__try/__except
blocks by throwing a C++ exception. Brad -
What's the point of BOOL?The original Win16 API defined a bunch of data types for use in the API. Things like
WORD
,HWND
,BOOL
,LPARAM
, etc., etc. date back to the 16-bit Windows days. This creates a type system that can be somewhat independent of the underlying hardware and operating system platform. This worked with some - though not complete - success when migrating code from Win16 to Win32 and from Win32 to Win64 (my understanding only, I have no direct Win64 experience). Back in the Win16 days, thebool
type was not part of the C or C++ language standards. It wasn't introduced until Visual C++ V5.0. SoBOOL
was defined in terms of types supported by the compilers of the day. The definition has probably remained to ensure backward compatibility with both code and data. Brad -
COM+ Application to Register my COM Component (VC++). Please Help .........A few simple solutions come to mind. Assuming your ATL COM component is in-process, you could call LoadLibrary() on the DLL, GetProcAddress() on DllRegisterServer() and then call through the function pointer. Alternatively, use CreateProcess() to run regsvr32.exe which essentially does the same as the above. I'm not sure if you can rely on regsvr32.exe being part of a "standard" Windows installation. If your COM component is hosted by an out-of-process server, you can call CreateProcess() on your EXE, passing the "/RegServer" or "/Service" command line argument as required. HTH Brad
-
INI fileA line that starts with a semi-colon ';' is treated as a comment and ignored by all the GetXxxProfileXxx() functions. Brad
-
Create/Remove Users on Win2000 ServerHave a look at the Active Directory doc on MSDN, specifically the samples for creating a user [^]. Brad
-
Compiling ProblemTry generating a make file. If the same problem occurs with nmake, maybe you'll be able to spot the dependency loop in the make file. Brad