home *** CD-ROM | disk | FTP | other *** search
- //
- //
- // File: RegADLL.c
- //
- // Purpose: Call DLLRegisterServer/UnRegisterServer in a
- // specified DLL.
- // Needed as a buffer between InstallShield and the
- // DLL itself
- //
- //
-
- #include <windows.h>
- #include <assert.h>
- #include <VER.H>
- #include "RegADLL.h"
-
- BOOL WINAPI LibMain ( HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpvReserved )
- {
- return (TRUE);
- UNREFERENCED_PARAMETER( hInstDLL );
- UNREFERENCED_PARAMETER( dwReason );
- UNREFERENCED_PARAMETER( lpvReserved );
- }
-
-
- INT WINAPI RegisterADLL( HWND hwndMain, LPLONG lplValue, LPSTR pszPath )
- {
- HINSTANCE hModule;
- CTLREGPROC DLLRegisterServer;
- HRESULT regResult;
- BOOL bResult = FALSE;
-
- //Gotta have good pointers
- assert(pszPath != NULL) ;
- assert(lplValue != NULL) ;
-
- //Load the DLL into memory
- hModule = LoadLibrary(pszPath) ;
-
- if (hModule == NULL) // Load failed, couldn't get the DLL
- {
- *lplValue = 0L;
- MessageBox(NULL, "Couldn't find DLL", pszPath, MB_ICONEXCLAMATION);
- return 1;
- }
-
- //Get a pointer to the Register function
- DLLRegisterServer = (CTLREGPROC)GetProcAddress(hModule,"DllRegisterServer" ) ;
-
- if (DLLRegisterServer != NULL)
- {
- regResult = DLLRegisterServer() ;
- bResult = (regResult == NOERROR) ;
- }
- else
- {
- MessageBox(NULL, "Missing server registration function", pszPath, MB_ICONEXCLAMATION);
- }
- FreeLibrary(hModule) ;
-
- //Everything went OK?
- *lplValue = bResult ? 1L:0L;
-
-
- return 1;
- }
-
-
- INT WINAPI UnRegisterADLL( HWND hwndMain, LPLONG lplValue, LPSTR pszPath )
- {
- HINSTANCE hModule;
- CTLREGPROC DLLUnregisterServer;
- HRESULT regResult;
- BOOL bResult = FALSE;
- CHAR szBuf[256];
-
- //Gotta have good pointers
- assert(pszPath != NULL) ;
- assert(lplValue != NULL) ;
-
- //Load the DLL into memory
- hModule = LoadLibrary((LPCSTR)pszPath) ;
-
- if (hModule == NULL) // Load failed, couldn't get the DLL
- {
- *lplValue = 0L;
- MessageBox(NULL, "Can't find DLL", pszPath, MB_ICONEXCLAMATION);
- return 1;
- }
-
- //Get a pointer to the UNRegister function
- DLLUnregisterServer = (CTLREGPROC)GetProcAddress(hModule,"DllUnregisterServer" ) ;
-
- if (DLLUnregisterServer != NULL)
- {
- regResult = DLLUnregisterServer() ;
- bResult = (regResult == NOERROR) ;
- }
- else
- {
- MessageBox(NULL, "Missing server Unregistration function", pszPath, MB_ICONEXCLAMATION);
- }
- FreeLibrary(hModule) ;
-
- //Everything went OK?
- *lplValue = bResult ? 1L:0L;
-
- if (!bResult)
- {
- wsprintf(szBuf, "Unregistration failed - DLLUnregisterServer returned %d", regResult);
- MessageBox(NULL, szBuf, pszPath, MB_OK);
- }
-
- return 1;
-
- }
-
- //
- // Opens the specified DLL to determine if
- // if the DLL is currently being used by another process
- //
-
- BOOL WINAPI IsDLLRunning( HWND hwndMain, LPLONG lplValue, LPSTR pszPath )
- {
- HANDLE hFile;
-
- assert(pszPath != NULL);
-
- //Try to open the file - exclusively. Assume that a failure
- //indicates that the file is currently running
- hFile = CreateFile(
- pszPath, // address of name of the file
- GENERIC_READ | GENERIC_WRITE, // access (read-write) mode
- 0, // share mode (none)
- NULL, // address of security descriptor
- OPEN_EXISTING, // how to create
- FILE_ATTRIBUTE_NORMAL, // file attributes
- NULL // handle of file with attributes to copy
- );
-
- //If couldn't get a handle...
- if(hFile == INVALID_HANDLE_VALUE)
- {
- //If the file exists then it must be locked by another process
- if(GetFileAttributes(pszPath) != 0xFFFFFFFF)
- {
- CloseHandle(hFile);
- *lplValue = 1L;
- return TRUE;
- }
- }
-
- //It's not in use
- CloseHandle(hFile);
- *lplValue = 0L;
- return FALSE;
- }
-
-
- //
- // Runs the specified executable
- //
- //
-
- BOOL WINAPI RunProcess( HWND hwndMain, LPLONG lplValue, LPSTR pszPath )
- {
- BOOL bLaunched;
- PROCESS_INFORMATION pi;
- STARTUPINFO si;
-
- assert(pszPath != NULL);
-
- //Fill in the startup info
- si.cb = sizeof(si);
- si.lpReserved = NULL;
- si.lpDesktop = NULL;
- si.lpTitle = NULL;
- si.dwX = 0;
- si.dwY = 0;
- si.dwXSize = 0;
- si.dwYSize = 0;
- si.dwXCountChars = 0;
- si.dwYCountChars = 0;
- si.dwFillAttribute = 0;
- si.dwFlags = STARTF_FORCEOFFFEEDBACK;
- si.wShowWindow = 0;
- si.cbReserved2 = 0;
- si.lpReserved2 = NULL;
- si.hStdInput = 0;
- si.hStdOutput = 0;
- si.hStdError = 0;
-
- //Run the specified process
- bLaunched = CreateProcess(pszPath, // pointer to name of executable module
- NULL,
- NULL,
- NULL,
- FALSE,
- CREATE_DEFAULT_ERROR_MODE | HIGH_PRIORITY_CLASS,
- NULL,
- NULL,
- &si,
- &pi);
-
- if(bLaunched)
- {
- //Give the process 10 seconds to complete
- WaitForInputIdle(pi.hProcess, 10000);
- }
-
- return bLaunched;
- }
-
-
-
- //
- // Is this Win95 J (japan)
- //
- //
- #define MS_LANGID_JPN 0x0411
-
- BOOL WINAPI IsWinJ( HWND hwndMain, LPLONG lplValue, LPSTR pszPath )
- {
-
- if(GetSystemDefaultLangID() == MS_LANGID_JPN)
- {
- *lplValue = 1L;
- return TRUE;
- }
-
- *lplValue = 0L;
- return FALSE;
-
- }
-