[Herecast-commit] herecast/src/HerecastTester HerecastAPI.cpp,1.2,1.3 HerecastAPI.h,1.3,1.4 Herecast
Status: Beta
Brought to you by:
mdpaciga
|
From: Mark P. <mdp...@us...> - 2005-07-25 19:38:41
|
Update of /cvsroot/herecast/herecast/src/HerecastTester In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12731/src/HerecastTester Modified Files: HerecastAPI.cpp HerecastAPI.h HerecastTester.cpp Log Message: moved dynamic DLL loading logic to HerecastAPI Index: HerecastTester.cpp =================================================================== RCS file: /cvsroot/herecast/herecast/src/HerecastTester/HerecastTester.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** HerecastTester.cpp 25 Jul 2005 19:31:20 -0000 1.3 --- HerecastTester.cpp 25 Jul 2005 19:38:31 -0000 1.4 *************** *** 35,63 **** // Example of checking to see if Herecast is running ! if (!g_herecast.findHerecast()) { ! ! hDLL = LoadLibrary(TEXT("whereami.dll")); ! ! if (!hDLL) { ! MessageBox(0, TEXT("Herecast is not running, not installed"), TEXT("Error"), 0); ! return 1; ! } ! else { ! HerecastInit = GetProcAddress((HMODULE)hDLL, TEXT("HerecastInit")); ! HerecastCleanup = GetProcAddress((HMODULE)hDLL, TEXT("HerecastCleanup")); ! ! if (!HerecastInit || !HerecastCleanup) { ! MessageBox(0, TEXT("Herecast is not running, and DLL was invalid"), TEXT("Error"), 0); ! return 1; ! } ! ! HerecastInit(); ! ! if (!g_herecast.findHerecast()) { ! MessageBox(0, TEXT("Herecast is not running, and could not load"), TEXT("Error"), 0); ! return 1; ! } ! } ! } --- 35,40 ---- // Example of checking to see if Herecast is running ! if (!g_herecast.findHerecast(true)) { ! MessageBox(0, TEXT("Herecast is not running, not installed"), TEXT("Error"), 0); } *************** *** 98,109 **** - // If the DLL was loaded dynamically, shut it down - - if (hDLL) { - HerecastCleanup(); - FreeLibrary((HMODULE)hDLL); - } - - return 0; } --- 75,78 ---- Index: HerecastAPI.h =================================================================== RCS file: /cvsroot/herecast/herecast/src/HerecastTester/HerecastAPI.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** HerecastAPI.h 25 Jul 2005 19:26:11 -0000 1.3 --- HerecastAPI.h 25 Jul 2005 19:38:31 -0000 1.4 *************** *** 35,38 **** --- 35,42 ---- WCHAR* lastString; // last string received via WM_COPYDATA + HINSTANCE hDLL; // handle to the dynamically-loaded DLL + FARPROC HerecastInit; // and its functions + FARPROC HerecastCleanup; + unsigned long getInt(int msg); // get an integer from Herecast WCHAR* getString(int msg); // get a string from Herecast *************** *** 49,53 **** // findHerecast returns NULL if Herecast isn't running ! HWND findHerecast(); --- 53,57 ---- // findHerecast returns NULL if Herecast isn't running ! HWND findHerecast(bool forceLoad = false); Index: HerecastAPI.cpp =================================================================== RCS file: /cvsroot/herecast/herecast/src/HerecastTester/HerecastAPI.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HerecastAPI.cpp 21 Jul 2005 20:07:03 -0000 1.2 --- HerecastAPI.cpp 25 Jul 2005 19:38:30 -0000 1.3 *************** *** 7,10 **** --- 7,11 ---- #include "HerecastAPI.h" + HerecastAPI::HerecastAPI() { *************** *** 12,23 **** --- 13,37 ---- hwndHerecast = NULL; hwndSelf = NULL; + hDLL = NULL; + HerecastInit = NULL; + HerecastCleanup = NULL; } + HerecastAPI::~HerecastAPI() { free(lastString); lastString = NULL; + + + // If the DLL was loaded dynamically, unload it + + if (hDLL) { + HerecastCleanup(); + FreeLibrary((HMODULE)hDLL); + } } + LRESULT CALLBACK HerecastAPI::My_WM_COPYDATA(HWND hWnd, UINT uimessage, WPARAM wParam, LPARAM lParam) { *************** *** 30,36 **** ! HWND HerecastAPI::findHerecast() { hwndHerecast = FindWindow(TEXT("Herecast"), NULL); return hwndHerecast; } --- 44,70 ---- ! HWND HerecastAPI::findHerecast(bool forceLoad) { hwndHerecast = FindWindow(TEXT("Herecast"), NULL); + + if (!hwndHerecast && forceLoad) { + hDLL = LoadLibrary(TEXT("whereami.dll")); + + if (!hDLL) { + return NULL; + } + + HerecastInit = GetProcAddress((HMODULE)hDLL, TEXT("HerecastInit")); + HerecastCleanup = GetProcAddress((HMODULE)hDLL, TEXT("HerecastCleanup")); + + if (!HerecastInit || !HerecastCleanup) { + return NULL; + } + + HerecastInit(); + + hwndHerecast = FindWindow(TEXT("Herecast"), NULL); + } + return hwndHerecast; } |