//--------------------------------------------------------------------------- #include #pragma hdrstop #include #include //--------------------------------------------------------------------------- // Important note about DLL memory management when your DLL uses the // static version of the RunTime Library: // // If your DLL exports any functions that pass String objects (or structs/ // classes containing nested Strings) as parameter or function results, // you will need to add the library MEMMGR.LIB to both the DLL project and // any other projects that use the DLL. You will also need to use MEMMGR.LIB // if any other projects which use the DLL will be perfomring new or delete // operations on any non-TObject-derived classes which are exported from the // DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling // EXE's to use the BORLNDMM.DLL as their memory manager. In these cases, // the file BORLNDMM.DLL should be deployed along with your DLL. // // To avoid using BORLNDMM.DLL, pass string information using "char *" or // ShortString parameters. // // If your DLL uses the dynamic version of the RTL, you do not need to // explicitly add MEMMGR.LIB as this will be done implicitly for you //--------------------------------------------------------------------------- USERES("UninstCust.res"); //--------------------------------------------------------------------------- int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*) { return 1; } //--------------------------------------------------------------------------- extern "C" { LONG APIENTRY __export UninstInitialize(HWND x, HINSTANCE y, long z) { DWORD size; char *path; char *app; DWORD type; HKEY hKey; STARTUPINFO StartupInfo; PROCESS_INFORMATION ProcessInformation; DWORD ExitCode; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\sword.exe\\", NULL, KEY_READ, &hKey) == ERROR_SUCCESS) { RegQueryValueEx(hKey, "Path", NULL, &type, NULL, &size); path = (char *) calloc(size+1, 1); app = (char *) calloc(size+40, 1); RegQueryValueEx(hKey, "Path", NULL, &type, path, &size); strcpy(app, path); strcat(app, "\\InstallMgr -uninstall"); GetStartupInfo(&StartupInfo); if (CreateProcess(NULL, app, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, path, &StartupInfo, &ProcessInformation)) { do { _sleep(1); GetExitCodeProcess(ProcessInformation.hProcess, &ExitCode); } while (ExitCode == STILL_ACTIVE); free(app); free(path); RegCloseKey(hKey); } else { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); // Display the string. MessageBox( NULL, (const char *)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION ); // Free the buffer. LocalFree( lpMsgBuf ); } } } LONG APIENTRY __export UninstUnInitialize(HWND x, HINSTANCE y, long z) { } }