VisualCpp.org Collection of Visual C++ Stuffs

10Oct/08Off

Windows Mail Interfaces!

Unlike it's predecessor Outlook Express Which doesn't have any documented Programmer model for automating it, The Windows Mail have documented COM based API model. Which could be found at following link:-

Database Describes WindowsMail’s database-related API.
Messaging Describes WindowsMail’s messaging-related API.
Networking Describes WindowsMail’s network-related API.
Accounts Describes WindowsMail’s accounts-related API.
Miscellaneous Describes WindowsMail’s miscellaneous API.
Filed under: COM/ATL Comments Off
2Oct/08Off

One possible solution to LNK1169 problem ?

A few days ago, I created an ATL (with MFC support) DLL project. The project compiled properly with absolutely no problem.

Then today, after doing some code modifications (which, believe me, were trivial and innocuous), I was confronted with the link error LNK1169 : Multiple Symbols Defined.

The problem was that while linking with mfcs42.lib, the linker noticed that this library contains a DEFINITION (i.e. full code, and not just a reference) of the function _DllMain@12. However, it also noted that the same function _DllMain@12 was already defined inside MSVCRTD.lib.

After some research and testing, I discovered the following facts regarding DllMain() when used in the context of a DLL project in which MFC is used :

1. Because MFC is used, a CWinApp class will be generated. This is so that the DLL application startup and shutdown processes can be abstracted by the CWinApp class (e.g. the use of InitInstance() and ExitInstance(), etc).

2. For this to happen, MFC must have its own version of DllMain() which will initialize the CWinApp class etc. Hence, this (MFC's) DllMain() must be the one eventually used (i.e. linked-to) by the Dll.

3. The MSVC runtime libraries also include their own versions of DllMain(). This being the case, potential conflicts can happen.

4. Such multiple-defined symbol link errors normally do not cause any problems because the linker will use the function that it finds first in its list of libraries.

5. It is still unclear to me why this link error occurred but this is a blessing in disguise because had this error not appeared, the DllMain() defined inside MSVCRTD.LIB would have been used and there will be problems : i.e. my CWinApp class will not be properly initialized.

Solution
---------
The solution to the above problem is to make sure that MFC's DllMain() is discovered first by the linker during linkage.

The way to do this in VC++ 6.0 is to go to the Project Settings, go to the "Link" tab, go to the "General" category, type in the name of the appropriate MFC library (e.g. mfcs42.lib, in my case) in the "Object/library modules" box. If the competing library (i.e. msvcrtd.lib in my case) is also in the box, make sure that the target MFC library is placed BEFORE the competing library.

Note that in my case, simply typing mfcs42.lib in the box ensured that this library is used first. Msvcrtd.lib was not in the box and so I did not have to put it there either.

---------------------------

This tip is provided by Mr. Lim Bio Liong, Original Tip could be found on this page.  

 

 

1Oct/08Off

How to affect the order of Class Factory Registration in a COM Exe Server?

If you have written a COM EXE server in ATL, it is possible to change the order of Class Factory registration in the server. Here's how :

1. Look up the ObjectMap declaration. This is encapsulated between the BEGIN_OBJECT_MAP() and END_OBJECT_MAP() macros.

2. Between the BEGIN_OBJECT_MAP() and END_OBJECT_MAP() macros are listed lines of OBJECT_ENTRY() statements.

3. The order of this list affects the order of Class Factory registration.

4. For example, in the following sample code :

BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_TestCOMExeObject01, CTestCOMExeObject01)
OBJECT_ENTRY(CLSID_TestCOMExeObject02, CTestCOMExeObject02)
END_OBJECT_MAP()

The class factory for CTestCOMExeObject01 will be registered first followed by CTestCOMExeObject02.

-----------------------------

This tip is provided by Mr. Lim Bio Liong, Original Tip could be found on this page.