#include #include "testdll2.h" static char szTest[10] = "TestDLL"; static char szValue[41] = "FirstString"; static char szValue2[41] = ""; static int nValue =1; static float fValue = 123.45; static double dValue = 987.65; static long lValue = 123456; static char cValue; // the following are the test functions // they store and retieve one of each data type extern "C" DllExport1 int DllExport2 DllCall GetFloat(float FAR *p) { *p = fValue; return (0); } extern "C" DllExport1 int DllExport2 DllCall SetFloat(float nIn) { fValue = nIn; return (0); } extern "C" DllExport1 int DllExport2 DllCall GetInt() { return (nValue); } extern "C" DllExport1 int DllExport2 DllCall SetInt(int nIn) { nValue = nIn; return (0); } extern "C" long DllExport2 DllCall GetLong() { return (lValue); } extern "C" DllExport1 int DllExport2 DllCall SetLong(long nIn) { lValue = nIn; return (0); } extern "C" DllExport1 int DllExport2 DllCall GetString(char FAR * pString) { char FAR *p; p = szValue; _fstrcpy(pString, p ); return (0); } extern "C" DllExport1 int DllExport2 DllCall SetString(char FAR *p) { if (p) { _fstrcpy(szValue2, szValue); _fstrcpy(szValue, p); return (0); } else return -3; } extern "C" DllExport1 int DllExport2 DllCall GetDouble(double FAR *p) { *p = dValue; return (0); } extern "C" DllExport1 int DllExport2 DllCall SetDouble(double nIn) { dValue = nIn; return (0); } extern "C" DllExport1 int DllExport2 DllCall GetStructure(S_PTR px) { char FAR *p, *p2; p = szValue; p2 = szValue2; px->nInt = strlen(szValue); _fstrcpy(px->szString, p ); _fstrcpy(px->szString2, p2 ); return (0); } extern "C" DllExport1 int DllExport2 DllCall SetStructure(S_PTR px) { char FAR *p,*p2; p = szValue; p2 = szValue2; _fstrcpy(p, (char FAR *) px->szString); _fstrcpy(p2, (char FAR *) px->szString2); return (0); } S_NT s_x; extern "C" DllExport1 int DllExport2 DllCall GetStructNT(S_NT FAR *x) { // char FAR *p; *x = s_x; // p = s_x.szString; // _fstrcpy(x->szString, p); // x->nInt = s_x.nInt; return (0); } extern "C" DllExport1 int DllExport2 DllCall SetStructNT(S_NT FAR *x) { //char FAR *p; s_x = *x; // p = s_x.szString; // _fstrcpy(p, x->szString); // s_x.nInt = x->nInt; return (0); } ///////////////////////////// /// used to trigger events in powerbuilder app from DLL HWND hWnd = 0; extern "C" DllExport1 HWND DllExport2 DllCall FindPB(char FAR *pClass, char FAR * pCaption, char FAR *pString) { char FAR *p; char sName[20]; char stemp[40]; int iFound = 0; hWnd = FindWindow(pClass, pCaption); if (hWnd == 0) { if (pClass != 0) { _fstrcpy(stemp, pClass); if (pCaption != 0) { strcat(stemp, " | "); strcat(stemp, pCaption); } } else _fstrcpy(stemp, pCaption); MessageBox(NULL, "pb app not found", stemp, MB_OK); iFound = 0; } else { iFound = 1; } if (iFound == 1) _fstrcpy(sName, "Found PB App"); else _fstrcpy(sName, "No PB App"); p = sName; _fstrcpy(pString, p ); return (hWnd); } // this proc will search for a powerbuilder application // if found it will trigger a user event the that window (pbm_custom01) // ue_1024 // function returns string (found or not) extern "C" DllExport1 HWND DllExport2 DllCall TriggerPB(char FAR *pClass, char FAR * pCaption, char FAR *pString) { int rc; int iFound = 0; if (hWnd == 0) hWnd = FindPB(pClass, pCaption, pString); if (hWnd != 0) { rc = PostMessage(hWnd, 1024, (WPARAM) 1, (LPARAM) 2); if (rc == 0) MessageBox(NULL, "PostMessage Failed", "test dll", MB_OK); } return (hWnd); } extern "C" DllExport1 HWND DllExport2 DllCall SignalPB(BOOL) { return (hWnd); } extern "C" DllExport1 int DllExport2 DllCall Test(char FAR * pString) { char FAR *p; static int nVersion; #ifdef DLLTYPE_3x nVersion = 1; #endif #ifdef DLLTYPE_NT nVersion = 2; #endif #ifdef DLLTYPE_95 nVersion = 3; #endif p = szTest; _fstrcpy(pString, p ); return (nVersion); }