This question has been raised several times in the forum and as I had to implement such feature in one of our development here is a small tip that retrieves the name of the application that calls a DLL:
// Note: link against cone.lib, apparc.lib and eikcore.lib
#include <apparc.h>
#include <eikapp.h>
#include <eikappui.h>
#include <coemain.h>
/**
* Get the full path of the callin app
* (ex: "c:\system\myapp\myapp.app")
* @param aPath On exit, contains the full path to the application.
* The descriptor should be big enough to hold a full file name (i.e. 255 characters)
*/
EXPORT_C void MyDll::GetCallingAppPath(TDes& aPath)
{ aPath=((CEikAppUi*)CCoeEnv::Static()->AppUi())->Application()->DllName();
}
You can also use the function above to get the drive on which the DLL is installed (provided that the application and your DLL are part of the same package and installed on the same drive):
/**
* Get the drive on which the DLL is installed
* (It is assumed that the app and the DLL are part of the same
* SIS file and that the PKG specifies same drive for both)
* @param aDrive On exit, contains the full path to the application.
* The descriptor should be big enough to hold a full file name (i.e. 255 characters)
* Note: take care that this code is designed as this for simplicity
* but it uses 1KB of stack (512 bytes for the TFileName
* and a little bit more for the TParse object)
*/
EXPORT_C void MyDll::GetInstallationDrive(TDes& aDrive)
{
// Get the path of the calling application
TFileName appPath;
GetCallingAppPath(appPath);
// Parse the app name to get the drive
TParse parser;
parser.Set(appPath,NULL,NULL);
aDrive=parser.Drive();
}
|