Link to home
Start Free TrialLog in
Avatar of flynny
flynnyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

LNK2005 error vc++6

hi i'm getting the following the error when trying to compile my prog. i've made sure tht its set to debug multithreaded dll. however i hve a file launchdll.cpp which includes io.h error.h and structs.h. however structs.cp also contains error.h and error.cpp contains structs.h.

hookstructs.obj : error LNK2005: "int __cdecl initialiseStructure(void)" (?initialiseStructure@@YAHXZ) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addDebug(char *)" (?addDebug@@YAXPAD@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addHookFile(char *,char *)" (?addHookFile@@YAXPAD0@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addExe(char *)" (?addExe@@YAXPAD@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addTitle(char *)" (?addTitle@@YAXPAD@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl addHook(char *)" (?addHook@@YAHPAD@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl addHook(class CString)" (?addHook@@YAHVCString@@@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl addButton(char *,char *,char *,int,int,int,int,int,char *,char *,int *)" (?addButton@@YAHPAD00HHHHH00PAH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl addButton(class CString,class CString,class CString,int,int,int,int,int,class CString,class CString,int *)" (?addButton@@YAHVCString@@00HHHHH00PAH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addField(struct BUTTON *,int *)" (?addField@@YAXPAUBUTTON@@PAH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addField(int,int,int *)" (?addField@@YAXHHPAH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addField(char *,char *,int)" (?addField@@YAXPAD0H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addFieldPosition(char *,char *,int,int)" (?addFieldPosition@@YAXPAD0HH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl addFieldPosition(int,int,int,int)" (?addFieldPosition@@YAXHHHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl countButtons(char *)" (?countButtons@@YAHPAD@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl countFields(char *,char *)" (?countFields@@YAHPAD0@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl removeHook(char *)" (?removeHook@@YAHPAD@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl removeButton(char *,char *)" (?removeButton@@YAHPAD0@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl removeField(char *,char *,int)" (?removeField@@YAHPAD0H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl sortHooks(void)" (?sortHooks@@YAXXZ) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl sortButtons(int)" (?sortButtons@@YAXH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "void __cdecl sortFields(int,int)" (?sortFields@@YAXHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setHookWindow(char *,char *)" (?setHookWindow@@YAHPAD0@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonText(char *,char *,char *)" (?setButtonText@@YAHPAD00@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonClass(char *,char *,char *)" (?setButtonClass@@YAHPAD00@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonX(char *,char *,int)" (?setButtonX@@YAHPAD0H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonY(char *,char *,int)" (?setButtonY@@YAHPAD0H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonAnchor(char *,char *,char *)" (?setButtonAnchor@@YAHPAD00@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonHeight(char *,char *,int)" (?setButtonHeight@@YAHPAD0H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonWidth(char *,char *,int)" (?setButtonWidth@@YAHPAD0H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonProgram(char *,char *,char *)" (?setButtonProgram@@YAHPAD00@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setButtonOutput(char *,char *,char *)" (?setButtonOutput@@YAHPAD00@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl setField(char *,char *,int,int)" (?setField@@YAHPAD0HH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl findHookPosition(char *)" (?findHookPosition@@YAHPAD@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl findButtonPosition(char *,char *)" (?findButtonPosition@@YAHPAD0@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl findFieldPosition(char *,char *,int)" (?findFieldPosition@@YAHPAD0H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl doesFieldExist(char *,char *,int)" (?doesFieldExist@@YAHPAD0H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * __cdecl getDebug(void)" (?getDebug@@YAPADXZ) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * __cdecl getHookTitle(void)" (?getHookTitle@@YAPADXZ) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * __cdecl getHookExe(void)" (?getHookExe@@YAPADXZ) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "struct HOOK * __cdecl getHook(int)" (?getHook@@YAPAUHOOK@@H@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * __cdecl getHookWindow(int)" (?getHookWindow@@YAPADH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "struct BUTTON * __cdecl getButton(int,int)" (?getButton@@YAPAUBUTTON@@HH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * __cdecl getButtonText(int,int)" (?getButtonText@@YAPADHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * __cdecl getButtonClass(int,int)" (?getButtonClass@@YAPADHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl getButtonX(int,int)" (?getButtonX@@YAHHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl getButtonY(int,int)" (?getButtonY@@YAHHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl getButtonWidth(int,int)" (?getButtonWidth@@YAHHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl getButtonHeight(int,int)" (?getButtonHeight@@YAHHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl getButtonAnchor(int,int)" (?getButtonAnchor@@YAHHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "int __cdecl getButtonField(int,int,int)" (?getButtonField@@YAHHHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * __cdecl getButtonProgram(int,int)" (?getButtonProgram@@YAPADHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * __cdecl getButtonOutput(int,int)" (?getButtonOutput@@YAPADHH@Z) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "struct HWND__ * __cdecl getAppHWND(void)" (?getAppHWND@@YAPAUHWND__@@XZ) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "char * debug" (?debug@@3PADA) already defined in LaunchDLL.obj
hookstructs.obj : error LNK2005: "struct HOOKFILE hookFile" (?hookFile@@3UHOOKFILE@@A) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl messageErr(int)" (?messageErr@@YAXH@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl logErr(int)" (?logErr@@YAXH@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl logMsg(class CString)" (?logMsg@@YAXVCString@@@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl setOutput(int)" (?setOutput@@YAXH@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl error(int)" (?error@@YAXH@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl resetLog(void)" (?resetLog@@YAXXZ) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl setLog(char *)" (?setLog@@YAXPAD@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl setErrorVar(char *)" (?setErrorVar@@YAXPAD@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "void __cdecl setErrorReason(char *)" (?setErrorReason@@YAXPAD@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "char * __cdecl getError(int)" (?getError@@YAPADH@Z) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "char * errReason" (?errReason@@3PADA) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "char * errVar" (?errVar@@3PADA) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "int errorOutput" (?errorOutput@@3HA) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "char * logName" (?logName@@3PADA) already defined in LaunchDLL.obj
hookError.obj : error LNK2005: "class std::basic_ofstream<char,struct std::char_traits<char> > log" (?log@@3V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int __cdecl saveHook(void)" (?saveHook@@YAHXZ) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int __cdecl openHook(void)" (?openHook@@YAHXZ) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int __cdecl readFile(class CString)" (?readFile@@YAHVCString@@@Z) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * __cdecl RemoveChars(char *,char)" (?RemoveChars@@YAPADPADD@Z) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * __cdecl SubString(char *,int,int)" (?SubString@@YAPADPADHH@Z) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * __cdecl getToken(void)" (?getToken@@YAPADXZ) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int __cdecl getLineCount(void)" (?getLineCount@@YAHXZ) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * __cdecl getReadVar(void)" (?getReadVar@@YAPADXZ) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * __cdecl Trim(char *)" (?Trim@@YAPADPAD@Z) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * __cdecl rTrim(char *)" (?rTrim@@YAPADPAD@Z) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * __cdecl lTrim(char *)" (?lTrim@@YAPADPAD@Z) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int __cdecl isspace(char)" (?isspace@@YAHD@Z) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int j" (?j@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * seps" (?seps@@3PADA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int butCount" (?butCount@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int lineCount" (?lineCount@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * token" (?token@@3PADA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "class ofstream f" (?f@@3Vofstream@@A) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char ch" (?ch@@3DA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int charCount" (?charCount@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * line" (?line@@3PADA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "char * readVar" (?readVar@@3PADA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int i" (?i@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "class CString tHook" (?tHook@@3VCString@@A) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "class CString tClass" (?tClass@@3VCString@@A) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "class CString tText" (?tText@@3VCString@@A) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "class CString tOutput" (?tOutput@@3VCString@@A) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "class CString tProgram" (?tProgram@@3VCString@@A) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int tAnchor" (?tAnchor@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int tX" (?tX@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int tY" (?tY@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int tWidth" (?tWidth@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int tHeight" (?tHeight@@3HA) already defined in LaunchDLL.obj
hookio.obj : error LNK2005: "int * tFields" (?tFields@@3PAHA) already defined in LaunchDLL.obj
hookstructs.obj : warning LNK4006: "int __cdecl initialiseStructure(void)" (?initialiseStructure@@YAHXZ) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl addDebug(char *)" (?addDebug@@YAXPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl addHookFile(char *,char *)" (?addHookFile@@YAXPAD0@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl addExe(char *)" (?addExe@@YAXPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl addTitle(char *)" (?addTitle@@YAXPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl addHook(char *)" (?addHook@@YAHPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl addHook(class CString)" (?addHook@@YAHVCString@@@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl addButton(char *,char *,char *,int,int,int,int,int,char *,char *,int *)" (?addButton@@YAHPAD00HHHHH00PAH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl addButton(class CString,class CString,class CString,int,int,int,int,int,class CString,class CString,int *)" (?addButton@@YAHVCString@@00HHHHH00PAH@Z) already defined in LaunchDLL.obj; second definition
 ignored
hookstructs.obj : warning LNK4006: "void __cdecl addField(struct BUTTON *,int *)" (?addField@@YAXPAUBUTTON@@PAH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl addField(int,int,int *)" (?addField@@YAXHHPAH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl addField(char *,char *,int)" (?addField@@YAXPAD0H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl addFieldPosition(char *,char *,int,int)" (?addFieldPosition@@YAXPAD0HH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl addFieldPosition(int,int,int,int)" (?addFieldPosition@@YAXHHHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl countButtons(char *)" (?countButtons@@YAHPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl countFields(char *,char *)" (?countFields@@YAHPAD0@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl removeHook(char *)" (?removeHook@@YAHPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl removeButton(char *,char *)" (?removeButton@@YAHPAD0@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl removeField(char *,char *,int)" (?removeField@@YAHPAD0H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl sortHooks(void)" (?sortHooks@@YAXXZ) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl sortButtons(int)" (?sortButtons@@YAXH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "void __cdecl sortFields(int,int)" (?sortFields@@YAXHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setHookWindow(char *,char *)" (?setHookWindow@@YAHPAD0@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonText(char *,char *,char *)" (?setButtonText@@YAHPAD00@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonClass(char *,char *,char *)" (?setButtonClass@@YAHPAD00@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonX(char *,char *,int)" (?setButtonX@@YAHPAD0H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonY(char *,char *,int)" (?setButtonY@@YAHPAD0H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonAnchor(char *,char *,char *)" (?setButtonAnchor@@YAHPAD00@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonHeight(char *,char *,int)" (?setButtonHeight@@YAHPAD0H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonWidth(char *,char *,int)" (?setButtonWidth@@YAHPAD0H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonProgram(char *,char *,char *)" (?setButtonProgram@@YAHPAD00@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setButtonOutput(char *,char *,char *)" (?setButtonOutput@@YAHPAD00@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl setField(char *,char *,int,int)" (?setField@@YAHPAD0HH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl findHookPosition(char *)" (?findHookPosition@@YAHPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl findButtonPosition(char *,char *)" (?findButtonPosition@@YAHPAD0@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl findFieldPosition(char *,char *,int)" (?findFieldPosition@@YAHPAD0H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl doesFieldExist(char *,char *,int)" (?doesFieldExist@@YAHPAD0H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * __cdecl getDebug(void)" (?getDebug@@YAPADXZ) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * __cdecl getHookTitle(void)" (?getHookTitle@@YAPADXZ) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * __cdecl getHookExe(void)" (?getHookExe@@YAPADXZ) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "struct HOOK * __cdecl getHook(int)" (?getHook@@YAPAUHOOK@@H@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * __cdecl getHookWindow(int)" (?getHookWindow@@YAPADH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "struct BUTTON * __cdecl getButton(int,int)" (?getButton@@YAPAUBUTTON@@HH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * __cdecl getButtonText(int,int)" (?getButtonText@@YAPADHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * __cdecl getButtonClass(int,int)" (?getButtonClass@@YAPADHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl getButtonX(int,int)" (?getButtonX@@YAHHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl getButtonY(int,int)" (?getButtonY@@YAHHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl getButtonWidth(int,int)" (?getButtonWidth@@YAHHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl getButtonHeight(int,int)" (?getButtonHeight@@YAHHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl getButtonAnchor(int,int)" (?getButtonAnchor@@YAHHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "int __cdecl getButtonField(int,int,int)" (?getButtonField@@YAHHHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * __cdecl getButtonProgram(int,int)" (?getButtonProgram@@YAPADHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * __cdecl getButtonOutput(int,int)" (?getButtonOutput@@YAPADHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "struct HWND__ * __cdecl getAppHWND(void)" (?getAppHWND@@YAPAUHWND__@@XZ) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "char * debug" (?debug@@3PADA) already defined in LaunchDLL.obj; second definition ignored
hookstructs.obj : warning LNK4006: "struct HOOKFILE hookFile" (?hookFile@@3UHOOKFILE@@A) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl messageErr(int)" (?messageErr@@YAXH@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl logErr(int)" (?logErr@@YAXH@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl logMsg(class CString)" (?logMsg@@YAXVCString@@@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl setOutput(int)" (?setOutput@@YAXH@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl error(int)" (?error@@YAXH@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl resetLog(void)" (?resetLog@@YAXXZ) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl setLog(char *)" (?setLog@@YAXPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl setErrorVar(char *)" (?setErrorVar@@YAXPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "void __cdecl setErrorReason(char *)" (?setErrorReason@@YAXPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "char * __cdecl getError(int)" (?getError@@YAPADH@Z) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "char * errReason" (?errReason@@3PADA) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "char * errVar" (?errVar@@3PADA) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "int errorOutput" (?errorOutput@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "char * logName" (?logName@@3PADA) already defined in LaunchDLL.obj; second definition ignored
hookError.obj : warning LNK4006: "class std::basic_ofstream<char,struct std::char_traits<char> > log" (?log@@3V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int __cdecl saveHook(void)" (?saveHook@@YAHXZ) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int __cdecl openHook(void)" (?openHook@@YAHXZ) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int __cdecl readFile(class CString)" (?readFile@@YAHVCString@@@Z) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * __cdecl RemoveChars(char *,char)" (?RemoveChars@@YAPADPADD@Z) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * __cdecl SubString(char *,int,int)" (?SubString@@YAPADPADHH@Z) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * __cdecl getToken(void)" (?getToken@@YAPADXZ) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int __cdecl getLineCount(void)" (?getLineCount@@YAHXZ) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * __cdecl getReadVar(void)" (?getReadVar@@YAPADXZ) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * __cdecl Trim(char *)" (?Trim@@YAPADPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * __cdecl rTrim(char *)" (?rTrim@@YAPADPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * __cdecl lTrim(char *)" (?lTrim@@YAPADPAD@Z) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int __cdecl isspace(char)" (?isspace@@YAHD@Z) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int j" (?j@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * seps" (?seps@@3PADA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int butCount" (?butCount@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int lineCount" (?lineCount@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * token" (?token@@3PADA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "class ofstream f" (?f@@3Vofstream@@A) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char ch" (?ch@@3DA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int charCount" (?charCount@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * line" (?line@@3PADA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "char * readVar" (?readVar@@3PADA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int i" (?i@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "class CString tHook" (?tHook@@3VCString@@A) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "class CString tClass" (?tClass@@3VCString@@A) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "class CString tText" (?tText@@3VCString@@A) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "class CString tOutput" (?tOutput@@3VCString@@A) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "class CString tProgram" (?tProgram@@3VCString@@A) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int tAnchor" (?tAnchor@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int tX" (?tX@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int tY" (?tY@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int tWidth" (?tWidth@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int tHeight" (?tHeight@@3HA) already defined in LaunchDLL.obj; second definition ignored
hookio.obj : warning LNK4006: "int * tFields" (?tFields@@3PAHA) already defined in LaunchDLL.obj; second definition ignored
   Creating library Debug/LaunchDLL.lib and object Debug/LaunchDLL.exp
LaunchDLL.obj : error LNK2001: unresolved external symbol "struct HWND__ * __cdecl FindCurrentWindow(struct HWND__ *,char *)" (?FindCurrentWindow@@YAPAUHWND__@@PAU1@PAD@Z)
Debug/LaunchDLL.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

LaunchDLL.dll - 107 error(s), 105 warning(s)

can anyone see whatts going wrong here?
Avatar of jkr
jkr
Flag of Germany image

If these header files contain code (and the errors preety much point in that direction), you have to make sure that this code only is include one time - preferrably move that to a separate .cpp file instead of having that in a header file. As a workaround, you could use

#ifndef CODE_INCLUDED
#define CODE_INCLUDED

// code in question

#endif
Avatar of flynny

ASKER

hi and thanks for the response jkr.

i have encased all the header with an ifndef statement but hte prob still remains and this is what is baffling me.

i have the following files.

io.h, io.cpp (fileio methods)
error.h, error.cpp (for error handling holds all error msgs etc)
structs.h structs.cpp (holds all the programs structures, etc)

launchdll.h launch.cpp (main dll method)

like i said before launch.dll includes all these headers as it does io, error, and uses the structs.as well as launchdll.h

structs.cpp includes error.h and structs.h

io.cpp includes structs.h, error.h and structs.h

is there anything else i can try?
To elaborate: If you have code in a header, the compiler will expand that in every .cpp file ypur are #include-ind that header file and create the functions in question in each .obj file that results from the compilation. Now, when the linker is trying to link these .obj files to a binary image, the trouble starts, since these identically naed symbols can be found in each of the input files. Since the linker cannot know they are in fact identical and that any of them could be picked, it raises that error.
>>is there anything else i can try?

As above - the cleanest solution is to have only declarations in the header files and put any implementation code into a .cpp file.
Avatar of flynny

ASKER

sorry jkr by delcarations you mean variable and method delcaration? if so then yes this is all that the files contain.
That's strange - e.g.

hookstructs.obj : error LNK2005: "int __cdecl initialiseStructure(void)" (?initialiseStructure@@YAHXZ) already defined in LaunchDLL.obj

implies that both LaunchDLL.cpp and hookstructs.cpp both have a implementation (i.e. the code for) 'initialiseStructure()'. If you haven't placed code for that functrion in both files, that usually can only happen if you have the code in some header file and include it in more than one .cpp file...

>>>> As a workaround, you could use ....
Hmmm. That doesn't work cause the implementation was included by different cpp files. Header protection only helps for including the same header twice. It doesnÄt help for something like the following:

// a.h
#ifndef A_H
#define A_H
class A
{
    int f();
};

// the following makes the problems
int A::f()
{
    return 5;
}
#endif

// x.cpp
#include "a.h"
   ...

// y.cpp
#include "a.h"

    ....


With that you'll get lnk2005 cause the A::f function was in the x.obj and in the y.obj.

What to do:

put all implementation code that is not inline and not template cod from the headers to a cpp.  In the sample above, do

// a.cpp
#include "a.h"
int A::f()
{
    return 5;
}

Note, it isn't only class member functions, but also global variables or global functions defined in aheader what lead to the above problem.

>>>> LaunchDLL.obj : error LNK2001: unresolved external symbol "struct HWND__ * __cdecl FindCurrentWindow(struct HWND__ *,char *)" (?FindCurrentWindow@@YAPAUHWND__@@PAU1@PAD@Z)

That is the only error *not* related to the above problem. Here the function FindCurrentWindow(struct HWND__ *,char *) has no implementation (or you made an implementation but have a different return type or argument list).

Regards, Alex
flynny, can you show us one of your header files ?
Avatar of flynny

ASKER

no problem heres a couple of them,

#ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED

void messageErr(int errNo);
void logErr(int errNo);
void logMsg(CString msg);

void setLog(LPTSTR logStr); //set the logfile outputting to

void setErrorVar(LPTSTR);
void setErrorReason(LPTSTR reason);

void setOutput(int output); //set where the error is output to 0 for msgbox 1 to log
void error(int error); //outputs the error number

LPTSTR getError(int error); //returns specific error

void resetLog(); //resets (empties) the current logfile.

#endif

// LaunchDLL.h : main header file for the LAUNCHDLL DLL
//

#if !defined(AFX_LAUNCHDLL_H__6398F256_54B2_43E6_9659_BC12D5A8E918__INCLUDED_)
#define AFX_LAUNCHDLL_H__6398F256_54B2_43E6_9659_BC12D5A8E918__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifdef BUILD_DLL // set that when building the DLL
#define DYNLINK __declspec(dllexport)
#else
#define DYNLINK __declspec(dllimport)
#endif
#pragma data_seg(".shared")
      char hookfilename[50] = "\0";
      char logfilename[50] = "\0";
#pragma data_seg()
#pragma comment(linker, "/SECTION:.shared,RWS")
DYNLINK const char* GetHookfile();
DYNLINK const char* GetLogfile();
DYNLINK void SetHookfile(const char*);
DYNLINK void SetLogfile(const char*);

#ifndef __AFXWIN_H__
      #error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"            // main symbols

#define DllExport      __declspec( dllexport )
DllExport HHOOK__* WINAPI InstallKeyboardLauncher(int process);
LRESULT CALLBACK LauncherKeyboardHook (int nCode, WORD wParam, DWORD lParam);

#define DllExport      __declspec( dllexport )
DllExport LRESULT CALLBACK AppEventsHook (int nCode, WPARAM wParam, LPARAM lParam);

#define DllExport      __declspec( dllexport )
LRESULT CALLBACK ButtonMouseHook (int nCode, int wParam, long lParam);

#define DllExport      __declspec( dllexport )
LRESULT CALLBACK WindowMouseHook (int nCode, int wParam, long lParam);

#define DllExport      __declspec( dllexport )
DllExport DWORD WINAPI FindWindowProcess(HWND__* wHnd);

#define DllExport      __declspec( dllexport )
DllExport HINSTANCE__* WINAPI FindWindowHInstance(HWND__* wHnd);

#define DllExport      __declspec( dllexport )
DllExport BOOL WINAPI EnumThreadWndProc(HWND hWnd, LPARAM lParam);

#define DllExport      __declspec( dllexport )
DllExport HHOOK__* WINAPI StartHook(char*, char*, char*);

#define DllExport      __declspec( dllexport )
DllExport BOOL WINAPI StopSystemHook(void);

#define DllExport      __declspec( dllexport )
DllExport LRESULT CALLBACK FoundWndHookProc(int nCode, int wParam, long lParam);

#define DllExport      __declspec( dllexport )
HWND__* FindCurrentWindow( HWND__*, char* );

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam);
BOOL CALLBACK EnumChildPathProc(HWND hwnd, LPARAM lparam);

HWND__* RecursiveSearch(HWND__* hwnd, struct FIELD* field);
HWND__* RecursivePathSearch(HWND__* hwnd, int* i);

BOOL AddCurrent( HWND__* butwnd, HHOOK__* mouseH, struct BUTTON* button, struct ParentWND* parent);
BOOL RemoveCurrent(int i);
void SortCurrent();


BOOL WriteDIB( LPTSTR szFile, HANDLE hDIB);
HANDLE DDBToDIB( CBitmap&, DWORD, CPalette* );

//****************** for testing ******************************
LRESULT CALLBACK AppForegroundHook (int nCode, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK EnumForegroundChildProc( HWND hwnd, LPARAM lParam );
/////////////////////////////////////////////////////////////////////////////
// CLaunchDLLApp
// See LaunchDLL.cpp for the implementation of this class
//

class CLaunchDLLApp : public CWinApp
{
public:
      CLaunchDLLApp();

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CLaunchDLLApp)
      //}}AFX_VIRTUAL

      //{{AFX_MSG(CLaunchDLLApp)
            // NOTE - the ClassWizard will add and remove member functions here.
            //    DO NOT EDIT what you see in these blocks of generated code !
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_LAUNCHDLL_H__6398F256_54B2_43E6_9659_BC12D5A8E918__INCLUDED_)
Avatar of flynny

ASKER

and the rest
#ifndef FILEIO_H_INCLUDED
#define FILEIO_H_INCLUDED

BOOL saveHook(); //config methods
BOOL openHook(); //config methods
int readFile(CString file); //readin hook file

int getLineCount(); //return the current line count into the file
LPTSTR getToken(); //for error debugging
LPTSTR getReadVar(); //for error debugging

char* RemoveChars(char* t, char r);
char* SubString(char* t, int s, int f);

//trim methods
char * Trim ( char * p );
char * rTrim ( char * p );
char * lTrim ( char * p );
int isspace ( char c );

#endif

#ifndef STRUCTS_H_INCLUDED
#define STRUCTS_H_INCLUDED

#include "consts.h"

struct FIELD{
      int x,y;
      LPTSTR fClass;
      int fieldPath;
      int position;
};

struct DIMENSIONS{
      int x,y,width,height;
      int anchor;
};

struct BUTTON{
      LPTSTR bClass;
      LPTSTR text;
      struct DIMENSIONS *dimensions;
      struct FIELD *fields[maxFields];
      LPTSTR program;
      LPTSTR output;
};

struct HOOK{
      LPTSTR window;
      struct BUTTON *buttons[maxButtons];
};

BOOL initialiseStructure();

void addDebug(LPTSTR fname);
void addHookFile(LPTSTR title, LPTSTR exe);
void addExe(LPTSTR exe);
void addTitle(LPTSTR title);

BOOL addHook(LPTSTR window);
BOOL addHook(CString window);

BOOL addButton(LPTSTR hook, LPTSTR text, LPTSTR bClass, int x, int y, int width, int height, int anchor, LPTSTR program, LPTSTR output, int* fields);
BOOL addButton(CString hook, CString text, CString bClass, int x, int y, int width, int height, int anchor, CString program, CString output, int* fields);

void addField(BUTTON* pBut, int* fields);
void addField(int i, int j, int* fields);
void addField(LPTSTR hook, LPTSTR button, int fieldPath);
void addFieldPosition(LPTSTR hook, LPTSTR button,int field, int position );
void addFieldPosition(int i, int j, int k, int pos);

BOOL removeHook(LPTSTR hook);
BOOL removeButton(LPTSTR hook, LPTSTR button);
BOOL removeField(LPTSTR hook, LPTSTR button, int field);


#endif
Can you also show the hookError.cpp file and the LaunchDLL.cpp file ?
Avatar of flynny

ASKER

#include "stdafx.h"
#include "hookio.h"
#include "hookstructs.h"
#include "hookError.h"

#include <iostream>
#include <fstream>
using namespace std;

int errorOutput = 0; //default to message to screen to avoid error

void messageErr(int error)
{
      LPTSTR errStr = getError(error);

      char buf[128];
      sprintf(buf, "%s", errStr);
      MessageBox(NULL, buf, NULL, 0);
}

LPTSTR logName;
std::ofstream log;

void logErr(int error)
{
      if( logName != NULL)
      {
            LPTSTR errStr = getError(error);

            log.open( logName, ios::app  );
            log << errStr << "\n";
            log.close();
      }
      //else
      //{
      //      char buf[128];
      //      sprintf(buf, "Error: Cannot write to log. logfile has not been set.");
      //      MessageBox(NULL, buf, NULL, 0);
      //}
}

void logMsg(CString msg)
{
      if( logName != NULL)
      {
            log.open( logName, ios::app );
            log << msg << "\n";
            log.close();
      }
      //else
      //{
      //      char buf[128];
      //      sprintf(buf, "Error: Cannot write to log. logfile has not been set.");
      //      MessageBox(NULL, buf, NULL, 0);
      //}
}

void setOutput(int output)
{
      if(errorOutput > 0)
            errorOutput = 1;
      else
            errorOutput = 0;
}

void error(int error)
{
      if(errorOutput==0)
            messageErr(error);
      else
            logErr(error);
}

void resetLog()
{
      if( logName != NULL)
      {
            //reset log file;
            log.open( logName );
            log.close();
      }
      //else
      //{
      //      char buf[128];
      //      sprintf(buf, "Error: Cannot write to log. logfile has not been set.");
      //      MessageBox(NULL, buf, NULL, 0);
      //}
}

void setLog(LPTSTR logStr)
{
      logName = (LPTSTR) malloc(strlen(logStr)+1);
      strcpy(logName, logStr);
}

LPTSTR errVar = "";
LPTSTR errReason = "";

void setErrorVar(LPTSTR var) { errVar = var; }
void setErrorReason(LPTSTR reason) { errReason = reason; }

LPTSTR getError(int error)
{
      char* err = (char*)malloc(128);;
      char line[5];
      itoa(getLineCount(), line, 5);

            switch(error)
            {
            case 0:
                  return err;
                  break;
            case -1:

                  strcpy(err, "ERROR: Reading Hook Structure: Line ");
                  strcat(err, line);
                  return err;

                  break;
            case -2:

                  strcpy(err, "ERROR: Reading Hook Structure: Button ");
                  strcat(err, line);
                  return err;

                  break;
            case -3:
                  
                  strcpy(err, "ERROR: Cannot open Hook File in DLL:");
                  return err;
                  
                  break;
            case -4:

                  strcpy(err, "ERROR: Allocating Memory for program variable in DLL:");
                  strcat(err, (char*)getToken());
                  return err;

                  break;
            case -5:

                  strcpy(err, "ERROR: Hook Line Exceed Maximum Length. ");
                  return err;

                  break;
            case -6:

                  strcpy(err, "ERROR: Missing Line Terminator ';', Reading Variable: '");
                  strcat(err, (char*)getReadVar());
                  strcat(err, "' at line: ");
                  strcat(err, line);
                  return err;

                  break;
            case -7:

                  strcpy(err, "ERROR: Missing Line Terminator '{', Reading Struct: '");
                  strcat(err, (char*)getReadVar());
                  strcat(err, "' at line: ");
                  strcat(err, line);
                  return err;

                  break;
            case -8:
                  
                  strcpy(err, "ERROR: Unrecognised variable or structure: '");
                  strcat(err, (char*)getReadVar());
                  strcat(err, "' at line: ");
                  strcat(err, line);
                  return err;

                  break;
            case -9:
                  
                  strcpy(err, "ERROR: Missing WINDOW variable from HOOK structure: at line: ");
                  strcat(err, line);
                  return err;

                  break;
            case -10:

                  strcpy(err, "ERROR:");
                  strcat(err, (char*)getReadVar());
                  strcat(err, ": contains invalid data: ");
                  strcat(err, getToken());
                  strcat(err, ":at line: ");
                  strcat(err, line);

                  return err;

                  break;
            case -11:
                  
                  strcpy(err, "ERROR:");
                  strcat(err, (char*)getReadVar());
                  strcat(err, ": contains invalid amount of arguments: at line:");
                  strcat(err, line);

                  return err;

                  break;
            case -12:
                  strcpy(err, "ERROR: Unable to write to specified file.");
                  return err;

                  break;
            case -13:
                  strcpy(err, "ERROR: Insufficient tokens in string.");
                  return err;

                  break;
            case -14:
                  strcpy(err, "ERROR: Unable to allocate memory for ");
                  strcat(err, errVar);
                  return err;

                  break;
            case -15:
                  strcpy(err, "ERROR: Hook doesn't exist: ");
                  strcat(err, errReason);
                  return err;

                  break;
            case -16:
                  strcpy(err, "ERROR: field already exists in this button");
                  return err;

                  break;
            case -17:
                  strcpy(err, "ERROR: field doesn't exist in the structure");
                  return err;

                  break;
            case -18:
                  {
                        strcpy(err, "ERROR: Cannot Add Hook, Maximum Hooks reached ");
                        char* max = (char*) malloc(6);
                        itoa(maxHooks, max, 5);
                        strcat(err, max);
                        free(max);
                        max = NULL;
                        return err;

                        break;
                  }
            case -19:
                  {
                        strcpy(err, "ERROR: Cannot Add Button, Maximum Buttons reached ");
                        char* max = (char*) malloc(6);
                        itoa(maxButtons, max, 5);
                        strcat(err, max);
                        free(max);
                        max = NULL;
                        return err;

                        break;
                  }
            case -20:
                  strcpy(err, "ERROR: Button doesn't exist: ");
                  strcat(err, errReason);
                  return err;

                  break;
            case -21:
                  strcpy(err, "ERROR: Cannot remove Hook, Hook doesn't exist");
                  return err;

                  break;
            case -22:
                  strcpy(err, "ERROR: Cannot remove Button, Button doesn't exist");
                  return err;

                  break;
            case -23:
                  strcpy(err, "ERROR: Cannot count this Hooks Buttons, Hook doesn't exist");
                  return err;

                  break;
            case -24:
                  {
                        strcpy(err, "ERROR: Cannot Add Field, Maximum Fields reached ");
                        char* max = (char*) malloc(6);
                        itoa(maxFields, max, 5);
                        strcpy(err, max);
                        free(max);
                        max = NULL;
                        return err;

                        break;
                  }
            case -25:
                  {
                        strcpy(err, "ERROR: Button out of screen coordinates, using default values.");
                        return err;
                  }
            case -26:
                  {
                        strcpy(err, "ERROR: Creating Mouse Hook for HWND:");
                        strcat(err, errReason);
                        return err;
                  }
            case -27:
                  {
                        strcpy(err, "ERROR: Couldn't add button to the current array");
                        return err;
                  }
            case -28:
                  {
                        strcpy(err, "ERROR: Creating button:");
                        strcat(err, errReason);
                        return err;
                  }
            case -29:
                  {
                        strcpy(err, "ERROR: Cannot find FieldWND in HWND:");
                        strcat(err, errReason);
                        return err;
                  }
            default:
                  strcpy(err, "ERROR: unhandled error!");
                  return err;

                  break;
            }
}

// LaunchDLL.cpp : Defines the initialization routines for the DLL.
//

using System;
using System.IO;
using System.Collections;

#include "stdafx.h"

#define BUILD_DLL // set that when building the DLL

//include all hook structs, io, and error
#include "hookstructs.cpp"
#include "hookio.cpp"
#include "hookError.cpp"

#include "LaunchDLL.h"

//#include "OLEACC.h" //need for IAccessible interface
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLaunchDLLApp

BEGIN_MESSAGE_MAP(CLaunchDLLApp, CWinApp)
      //{{AFX_MSG_MAP(CLaunchDLLApp)
            // NOTE - the ClassWizard will add and remove mapping macros here.
            //    DO NOT EDIT what you see in these blocks of generated code!
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLaunchDLLApp construction

CLaunchDLLApp::CLaunchDLLApp()
{
      // TODO: add construction code here,
      // Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CLaunchDLLApp object

CLaunchDLLApp theApp;

int errorx = 100; //emergency case coords
int errory = 50;

DYNLINK const char* GetHookfile() { return hookfilename;}
DYNLINK const char* GetLogfile() { return logfilename;}
DYNLINK void SetHookfile(const char* p) { strcpy(hookfilename,p);}
DYNLINK void SetLogfile(const char* p) { strcpy(logfilename,p);}

HWND__* appWND = NULL;
HHOOK__* appHook = NULL;

HWND__* foundChild = NULL;

CString msg; //used for logging
std::ofstream logfile;

//***********structs for keeping track of existing buttons, etc**************
struct ParentWND
{
      HWND__* window;
      HHOOK__* winMHook;
};

struct CurrentButtons
{
      ParentWND* parent;
      BUTTON* button;
      HWND__* field[maxLookupFields];
      HWND__* buttonWND;
      HHOOK__* butMHook;
}CurrentBut[maxCurrentButtons];

//***************************************************************************

char* appTitle = NULL; //main window title

static HINSTANCE hinstDLL = LoadLibrary((LPCTSTR) ".\\LaunchDLL.dll");

DllExport HHOOK__* WINAPI StartHook(char* prog, char* hook, char* debug)
{
      if(strcmp(logfilename, "\0") != 0)
      {
            setOutput(1); //as we hae a log send all messgage to the log file
            setLog(logfilename); //set the logfile
            resetLog(); //reset if reusing from previous run
      }
      else
            setOutput(0); //msgbox out all error messages.

      msg.Format("Trying to Hook into Application:%s:\n",prog);
      logMsg(msg);
      
      if(appHook == NULL )
      {
            HGLOBAL memPtr = GlobalAlloc(GMEM_FIXED, sizeof(HWND__*));
            
            if((appWND = (HWND__*)GlobalLock(memPtr)) != NULL)
            {
                  appWND = FindWindow(NULL, prog); //try and find the program window

                  while (appWND == 0) //sit and wait for the program to load
                  {
                        Sleep(10);
                        appWND = FindWindow(NULL, prog);
                  }

                  //need to sort out closing app hook in dll properly
                  //copy the apptitle into a var o know when to close
                  appTitle = (char*) malloc(sizeof(prog)+1);
                  strcpy(appTitle, prog);

                  appHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)AppEventsHook, hinstDLL, GetWindowThreadProcessId(appWND, NULL) );

                  msg.Format("EVENTS APPLICATION HOOK:%s: for HWND:%s: \n",appHook, appWND);
                  logMsg(msg);

                  return appHook;
            }
            else
            {
                  setErrorVar("App Window Handle");
                  error(-14);
                  return appHook;
            }
      }
      return appHook;
}

DllExport DWORD WINAPI FindWindowProcess(HWND__* wHnd)
{
      return GetWindowThreadProcessId(wHnd, NULL);
}

DllExport HINSTANCE__* WINAPI FindWindowHInstance(HWND__* wHnd)
{
      return (HINSTANCE__*) GetWindowLong(wHnd, GWL_ID);
}


bool isread = false; //used so file will only be read in once

LRESULT CALLBACK AppEventsHook (int nCode, WPARAM wParam, LPARAM lParam)
{
      if ( nCode == HC_ACTION )
      {
            LPCWPSTRUCT pCwp = (LPCWPSTRUCT) lParam;
            
            switch (pCwp->message)
            {
            case WM_WINDOWPOSCHANGING: //was WM_CREATE
                  {

                  if(!isread) //if the file has not been read then read it
                  {
                        isread = true; //only read once

                        msg.Format("Attempting to Read Hook File in DLL. \n");
                        logMsg(msg);
                        
                        int readOK = readFile(hookfilename);

                        //            char buf[128];
            //sprintf(buf, "herezzz ok in pos changing!!! |%s| |%d|", logfilename, readOK);
            //MessageBox(NULL, buf, NULL, 0);

                        if(readOK == 0)
                        {
                              msg.Format("Hook file read successfully. \n");
                              logMsg(msg);
                        }
                        else
                        {
                              error(readOK);
                              return 0;
                        }
                  }
                  else //else has been read so can strt to try and hook into the window
                  {
                        int i;
                        for(i=0; i<maxHooks; i++)
                        {
                              if(getHook(i) == NULL)
                                    break; //must be no more so break

                  //char buf[128];
                  //sprintf(buf, "here ok!!!");
                  //(NULL, buf, NULL, 0);
                              //HWND__* foundWND = FindCurrentWindow(pCwp->hwnd, getHook(i)->window);
                              HWND__* foundWND = FindWindow(NULL, getHook(i)->window);

                              if(pCwp->hwnd == foundWND) //check if not null otherwise will pull back systemwide hook
                              {
                                    HINSTANCE__* currentHInstance = FindWindowHInstance(pCwp->hwnd);
                                    DWORD currentProcessID = FindWindowProcess(pCwp->hwnd);
                                    
                                    struct ParentWND* wnd;
                                    HGLOBAL memPtr = GlobalAlloc(GMEM_FIXED, sizeof(struct ParentWND)); //pointer to mem block
                                    
                                    if(memPtr)
                                    {
                                          wnd = (ParentWND*)GlobalLock(memPtr);
                                    
                                          //wnd->changed = FALSE;
                                          wnd->window = pCwp->hwnd;
                                          //need window hook on main window now so can find the field
                                          //wnd->winMHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC) WindowMouseHook, currentHInstance, currentProcessID);
                                                                  
                                          msg.Format("MHHOOK:%d:HWND:%s:\n",wnd->winMHook, wnd->window);
                                          logMsg(msg);
                                    }
                                    else
                                    {
                                          setErrorVar("Window Cache Variable");
                                          error(-14);
                                    }

                                    msg.Format("WINDOW:HWND:%d:TITLE:%s:WM_CREATE:MHOOK:%d\n",wnd->window, getHook(i)->window, wnd->winMHook);
                                    logMsg(msg);

                                    //*********************** Deprecated?? keep in case of emergency***************************
                                    /*if(!fieldPath) //if not using path and using position then need to lock window as maximised
                                    {
                                          if(strcmp(logfilename, "\0") != 0)
                                          {
                                                logfile.open( logfilename, ios::app  );
                                                logfile << "Removing Maximise Button:HWND:"<< pCwp->hwnd <<":\n";
                                                logfile.close();
                                          }

                                          HMENU hMenu = GetSystemMenu ( pCwp->hwnd, FALSE);
                                          DeleteMenu ( hMenu, 0, MF_BYPOSITION); // disable 'Maximize'
                                          DrawMenuBar( pCwp->hwnd );
                                          ShowWindow(pCwp->hwnd, SW_MAXIMIZE);
                                    }*/
                                    //**************************************************************************************
                                                                              
                                    int j;
                                    for(j=0; j<maxBpW; j++)
                                    {
                                          if(getButton(i,j) == NULL)
                                                break; //no more buttons

                                          BUTTON* tmpBut = getButton(i,j);

                                          RECT wRect;
                                          GetWindowRect(pCwp->hwnd, &wRect);

                                          //test to see if button is within the indow bounds and if not error

                                          if( tmpBut->dimensions->x >= ((wRect.right-wRect.left) - tmpBut->dimensions->width) || tmpBut->dimensions->y >= ((wRect.bottom-wRect.top) - tmpBut->dimensions->height) )
                                          {
                                                //add error needed?
                                                error(-25);

                                                //log for more info
                                                msg.Format("ERROR: Button Coords:HWND:%d:WINSIZE:[%d by %d]:BUTTONCOORDS:[x%dy%d]: \n",wnd->window,(wRect.right-wRect.left),(wRect.bottom-wRect.top), tmpBut->dimensions->x, tmpBut->dimensions->y);
                                                logMsg(msg);

                                                tmpBut->dimensions->x = errorx;
                                                tmpBut->dimensions->y = errory;
                                                errorx = errorx + 100;
                                          }
                                          
                                          int buttonx, buttony;
                                          
                                          switch ( tmpBut->dimensions->anchor )
                                          {
                                          case T_LEFT:
                                                buttonx = tmpBut->dimensions->x;
                                                buttony = tmpBut->dimensions->y;
                                                break;
                                          case T_RIGHT:
                                                buttonx = (wRect.right - wRect.left) - tmpBut->dimensions->x;
                                                buttony = tmpBut->dimensions->y;
                                                break;
                                          case B_LEFT:
                                                buttonx = tmpBut->dimensions->x;
                                                buttony = (wRect.bottom - wRect.top) - tmpBut->dimensions->y;
                                                break;
                                          case B_RIGHT:
                                                buttonx = (wRect.right - wRect.left) - tmpBut->dimensions->x;
                                                buttony = (wRect.bottom - wRect.top) - tmpBut->dimensions->y;
                                                break;
                                          }
                                          
                                          HWND__* buttonWND = CreateWindowEx(WS_EX_LEFT, tmpBut->bClass, tmpBut->text, /*BS_OWNERDRAW*/ WS_CHILD, buttonx, buttony, tmpBut->dimensions->width, tmpBut->dimensions->height, pCwp->hwnd, NULL, currentHInstance, NULL);

                                                if( buttonWND != 0 )
                                                {
                                                      ShowWindow(buttonWND, SW_SHOWDEFAULT);

                                                      HINSTANCE__* buttonHInstance = FindWindowHInstance(buttonWND);
                                                      DWORD buttonThreadProcessID = GetWindowThreadProcessId(buttonWND, NULL);

                                                      HHOOK__* mouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC) ButtonMouseHook, buttonHInstance, buttonThreadProcessID);

                                                      if( mouseHook == 0)
                                                      {
                                                            msg.Format("Button:%d:Text:%s:",buttonWND, tmpBut->text);
                                                            char* reason = (char*) malloc(sizeof(msg)+1);
                                                            strcpy(reason, msg);
                                                            setErrorReason(reason);
                                                            error(-26);
                                                      }

                                                      BOOL added = AddCurrent( buttonWND, mouseHook, tmpBut, wnd );
                                                      
                                                      if(!added)
                                                            error(-27);            
                                                }
                                                else
                                                {
                                                      msg.Format("HWND:%d:TEXT:%s:", buttonWND, tmpBut->text);
                                                      char* reason =(char*) malloc(sizeof(msg)+1);
                                                      strcpy(reason, msg);
                                                      setErrorReason(reason);
                                                      error(-28);
                                                }

                                                msg.Format("BUTTON:HWND:%d:CLASS:%s:TEXT:%s:DIMENSIONS[x%d,y%d,w%d,h%d]:\n",buttonWND,tmpBut->bClass,tmpBut->text, tmpBut->dimensions->x, tmpBut->dimensions->y, tmpBut->dimensions->width, tmpBut->dimensions->height);
                                                logMsg(msg);
                                    }
                              }
                        }
                  }

                  }
                  break;

            case WM_PAINT:
                  {
                        int i;
                        for(i=0; i<maxCurrentButtons; i++)
                        {
                              int j;
                              for(j=0; j<maxLookupFields; j++)
                              {

                                    if(CurrentBut[i].parent == NULL)
                                          break;

                                    if(CurrentBut[i].field[j] == NULL) //if the fieldWND has not been found
                                    {
                                          foundChild = NULL; //reset
                                          CurrentBut[i].field[j] = RecursivePathSearch(CurrentBut[i].parent->window, &CurrentBut[i].button->fields[j]->fieldPath);

                                          msg.Format("PAINT:HWND:%d:FIELDWND:%d: \n", CurrentBut[i].buttonWND, CurrentBut[i].field[j]);
                                          logMsg(msg);

                                          if( CurrentBut[i].field[j] == 0)
                                          {      
                                                if(strcmp(logfilename, "\0") != 0)
                                                {
                                                      msg.Format("%s:FIELD:%s:", CurrentBut[i].parent->window, &CurrentBut[i].button->fields[j]->fieldPath);
                                                      char* reason =(char*) malloc(sizeof(msg)+1);
                                                      strcpy(reason, msg);
                                                      setErrorReason(reason);
                                                      error(-29);
                                                }
                                                return 0; //may need to send close message and shut down if overloads
                                          }

                                          //kept just in case will search and find the field path using position and class
                                          /*msg.Format("Trying to find fieldWND on HWND:%d:FIELDPATH:%d:\n", CurrentBut[i].parent->window, &CurrentBut[i].button->fields[j]->fieldPath);
                                          logMsg(msg);

                                          foundChild = NULL; //reset
                                          CurrentBut[i].field[j] = RecursiveSearch(CurrentBut[i].parent->window, CurrentBut[i].button->fields[j]);            

                                          if( CurrentBut[i].field[j] == 0 )
                                          {
                                                msg.Format("%s:FIELD:%s:", CurrentBut[i].parent->window, &CurrentBut[i].button->output.field[j]);
                                                char* reason =(char*) malloc(sizeof(msg)+1);
                                                strcpy(reason, msg);
                                                setErrorReason(reason);
                                                error(-29);
                                                return 0;
                                          }*/
                                    }
                              }
                        }
                  }
                  break;

            case WM_SIZE:
                  {
                        int i;
                        for(i=0; i<maxCurrentButtons; i++)
                        {
                              if(CurrentBut[i].parent == NULL)
                                    break;

                              if(CurrentBut[i].parent->window == pCwp->hwnd) //it buttons parent being resized
                              {
                                    RECT wRect;
                                    GetWindowRect(pCwp->hwnd, &wRect);

                                    int buttonx, buttony;
                              //do coordinate comparison for button position                                          
                                    switch ( CurrentBut[i].button->dimensions->anchor )
                                    {
                                          case T_LEFT:
                                                buttonx = CurrentBut[i].button->dimensions->x;
                                                buttony = CurrentBut[i].button->dimensions->y;
                                                break;
                                          case T_RIGHT:
                                                buttonx = (wRect.right - wRect.left) - CurrentBut[i].button->dimensions->x;
                                                buttony = CurrentBut[i].button->dimensions->y;
                                                break;
                                          case B_LEFT:
                                                buttonx = CurrentBut[i].button->dimensions->x;
                                                buttony = (wRect.bottom - wRect.top) - CurrentBut[i].button->dimensions->y;
                                                break;
                                          case B_RIGHT:
                                                buttonx = (wRect.right - wRect.left) - CurrentBut[i].button->dimensions->x;
                                                buttony = (wRect.bottom - wRect.top) - CurrentBut[i].button->dimensions->y;
                                                break;
                                    }

                                    BOOL moved =  MoveWindow(CurrentBut[i].buttonWND, buttonx, buttony, CurrentBut[i].button->dimensions->width, CurrentBut[i].button->dimensions->height, TRUE);
                              }
                        }
                  }
                  break;

            case WM_SHOWWINDOW:
                  {
                        /*int i; //renames windows not needed
                        for(i=0; i<maxCurrentButtons; i++)
                        {
                              if(CurrentBut[i].parent == NULL)
                                    break;

                              if(pCwp->hwnd == CurrentBut[i].parent->window)
                              {            
                                    if(!CurrentBut[i].parent->changed)
                                    {
                                          CurrentBut[i].parent->changed = TRUE;

                                          TCHAR title[100];
                                          GetWindowText(CurrentBut[i].parent->window, title, 100);
      
                                          char* newTitle = (char*) malloc(strlen(title)+strlen(appText)+1);
                                          strcpy(newTitle, title);                                    
                                          strcat(newTitle, appText);
                                                
                                          BOOL test = SetWindowText(pCwp->hwnd, newTitle);
                                          UpdateWindow(pCwp->hwnd);
                                    }

                                    logfile.open( logfilename, ios::app  );
                                    logfile << "Bringing Buttons to Front of Pane:HWND:" << CurrentBut[i].buttonWND << ":TEXT:" << CurrentBut[i].button->butText << ": \n";
                                    logfile.close();
      
                                    BringWindowToTop(CurrentBut[i].buttonWND);
                              }
                        }*/
                  }
                  break;

            case WM_DRAWITEM:
                  {
                  /*      LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pCwp->lParam;

                        int i;
                        for(i=0; i<maxCurrentButtons; i++)
                        {
                              if(CurrentBut[i].parent == NULL)
                                    break;

                              if(pCwp->hwnd == CurrentBut[i].parent->window)
                              {
                                          HFONT hFont = ::CreateFontA(-12, 0, 0, 0, FW_THIN, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");  
                                          SendMessage(CurrentBut[i].buttonWND, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
                              }
                        }*/
                  }
                  break;

            case WM_ACTIVATEAPP:
                  {
                  }
                  break;

            case WM_ACTIVATE:
            
                  switch LOWORD(pCwp->wParam)
                  {

                  case WA_ACTIVE:

                        int i;
                        for(i=0; i<maxCurrentButtons; i++)
                        {
                              if(CurrentBut[i].parent == NULL)
                                    break;

                              if(pCwp->hwnd == CurrentBut[i].parent->window)
                                    BringWindowToTop(CurrentBut[i].buttonWND);
                        }

                        break;

                  case WA_INACTIVE:

                        break;
                  }

                  break;

            case WM_CLOSE:
                  
                  if(pCwp->hwnd == FindWindow(NULL, appTitle)) //if the main window is closing then exit
                        StopSystemHook();

                  int i;
                  for(i = 0; i<maxCurrentButtons; i++)
                  {
                        if(CurrentBut[i].parent == NULL)
                              break;

                        if(pCwp->hwnd == CurrentBut[i].parent->window)
                        {            
                              BOOL butunhooked = UnhookWindowsHookEx(CurrentBut[i].butMHook);

                              msg.Format("WM_CLOSE:HWND:%d:BUTTON:HWND%d:TEXT:%s:UNHOOKED:%s: \n", CurrentBut[i].parent->window, CurrentBut[i].buttonWND, CurrentBut[i].button->text, butunhooked);
                              logMsg(msg);
                              
                              BOOL unhooked = UnhookWindowsHookEx(CurrentBut[i].parent->winMHook);
                              RemoveCurrent(i);
                        }
                  }
                  
                  break;
            }
      }
      return CallNextHookEx( appHook, nCode, wParam, lParam );
}

LRESULT CALLBACK ButtonMouseHook (int nCode, int wParam, long lParam)
{
      HHOOK__* currentHook = 0;

      if(nCode == HC_ACTION)
      {
            MOUSEHOOKSTRUCT* pStruct = (MOUSEHOOKSTRUCT*)lParam;

            int i;
            for(i=0; i<maxCurrentButtons; i++)
            {      
                  if(CurrentBut[i].parent == NULL)
                        break;

                  LRESULT pushed = SendMessage (CurrentBut[i].buttonWND, BM_GETSTATE, 0, 0); //620 ==lbutclk

                  if(pStruct->hwnd == CurrentBut[i].buttonWND)
                  {
                        if((int) pushed == 620) // if a left mouse button click
                        {
                              msg.Format("WM_LBUTTONDBLCLK:HWND:%d:TEXT:%s: \n", CurrentBut[i].buttonWND, CurrentBut[i].button->text);
                              logMsg(msg);
                              
                              currentHook = CurrentBut[i].butMHook;

                              int j;
                              int fLength =0;
                              char* fieldValues[maxLookupFields];

                              for(j=0; j<maxLookupFields; j++)
                              {
                                    int length = SendMessage(CurrentBut[i].field[j], WM_GETTEXTLENGTH, 0, 0);

                                    fLength+=length;
                                    char* text=(char*)malloc(length + 1);

                                    if (!text)
                                    {
                                          char* reason = (char*) malloc(sizeof(CurrentBut[i].field[j])+1);
                                          itoa((int) CurrentBut[i].field[j],reason,10);
                                          setErrorVar(reason);
                                          error(-14);
                                    }

                                    int hr = SendMessage(CurrentBut[i].field[j], WM_GETTEXT, length+1, (LPARAM)text);
                                    fieldValues[j] = text;            
                              }

                              if( pStruct->wHitTestCode == HTCLIENT)
                              {      
                                    if( strcmp(CurrentBut[i].button->program, "msgbox") == 0 )
                                    {
                                          char* values = (char*) malloc(fLength+j+11);
                                          strcpy(values, fieldValues[0]);

                                          if(strcmp(fieldValues[1], "") != 0)
                                                strcat(values, "\n");
                                                                                    
                                          for(j=1; j<maxLookupFields; j++)
                                          {
                                                strcat(values, fieldValues[j]);

                                                if(j+1<maxLookupFields)
                                                      if(strcmp(fieldValues[j+1], "") != 0)
                                                            strcat(values, "\n");
                                          }

                                          MessageBox(NULL, values, "Field Values", 0);
                                          free(values);
                                          values=NULL;
                                          return 0;
                                    }
                                    else if( strcmp(CurrentBut[i].button->program, "barcode") == 0 )
                                    {
                                          std::ofstream file;
                                          file.open (CurrentBut[i].button->text);

                                          int j;
                                          for(j=0; j<maxLookupFields; j++)
                                          {
                                                file << fieldValues[j] << "\n";
                                          }

                                          file.close();
                                          return 0;
                                    }
                                    else //launch the program
                                    {
                                          int j,k;
                                          int iPos = 0; //insert position
                                          int sPos = 0; //current string position
                                          char* outputString = (char*) malloc(fLength + strlen(CurrentBut[i].button->text) + 1);
                                          strcpy(outputString,"");

                                          for(j=0; j<=strlen(CurrentBut[i].button->text); j++)
                                          {      
                                                if(j == CurrentBut[i].button->fields[iPos]->position)
                                                {
                                                      //append variable
                                                      for(k=0; k<strlen(fieldValues[iPos]);k++)
                                                      {
                                                            outputString[sPos] = fieldValues[iPos][k];
                                                            sPos++;
                                                      }
                                                      iPos++;
                                                }
                                                
                                                if(CurrentBut[i].button->fields[iPos-1]->position == CurrentBut[i].button->fields[iPos]->position)
                                                      j--; //if we have to add another at the same point
                                                else
                                                {
                                                      outputString[sPos] = CurrentBut[i].button->text[j];
                                                      sPos++;
                                                }
                                          }
                                          sPos--;

                                          //append any othe remaining fields
                                          while(iPos < maxLookupFields)
                                          {
                                                if(CurrentBut[i].button->fields[iPos]->position != NULL)
                                                {
                                                      for(k=0; k<strlen(fieldValues[iPos]);k++)
                                                      {
                                                            outputString[sPos] = fieldValues[iPos][k];                                          
                                                            sPos++;
                                                      }
                                                }                                                
                                                iPos++;
                                          }

                                          outputString[sPos] = '\0';
                                          
                                          char* program = (char*) malloc(strlen(CurrentBut[i].button->program)+1+strlen(outputString)+1);
                                    
                                          strcpy( program, CurrentBut[i].button->program );
                                          strcat( program, " " );
                                          strcat( program, outputString);
                                          strcat( program, "\0");

                                          PROCESS_INFORMATION pi;
                                          STARTUPINFO si;

                                          memset(&si,0,sizeof(si));
                                          si.cb= sizeof(si);

                                          if(!CreateProcess(NULL, program, NULL, NULL, false, 0, NULL,NULL,&si,&pi))
                                          {
                                                //could not run program o throw error
                                                      AfxMessageBox(_T("Could not run the program."));
                                          }
                                                      
                                          CloseHandle( pi.hProcess );
                                          CloseHandle( pi.hThread );            
                                          return 0;
                                    }
                              }
                        }
                  }
            }
      }

      return CallNextHookEx(currentHook, nCode, wParam, lParam);
}

LRESULT CALLBACK WindowMouseHook (int nCode, int wParam, long lParam)
{
      HHOOK__* currentHook = 0;

      if(nCode == HC_ACTION)
      {
            MOUSEHOOKSTRUCT* pStruct = (MOUSEHOOKSTRUCT*)lParam;

            switch(wParam)
            {
            case WM_NCLBUTTONDBLCLK:

                        //if(!fieldPath) //if using position then remove the double click on menu
                        //      return 1;

                  break;
            case WM_MOUSEMOVE:
            

                  break;
            }
                                    
      }

      return CallNextHookEx(currentHook, nCode, wParam, lParam);
}

int childCount;
int recCount = 0;

HWND__* RecursivePathSearch(HWND__* hwnd, int* path)
{
      if(foundChild == NULL)
      {
            childCount = 0;
            EnumChildWindows(hwnd, (WNDENUMPROC) EnumChildPathProc, (LPARAM) path);
      }

      return foundChild;
}

BOOL CALLBACK EnumChildPathProc(HWND hwnd, LPARAM lparam)
{
      if(childCount == *((int*) lparam))
      {
            if(*( ((int*) lparam)+1 ) != NULL )
                  RecursivePathSearch(hwnd, (((int*) lparam)+1) );

            foundChild = hwnd;
            return false;
      }

      childCount++;
      return true;
}

HWND__* RecursiveSearch(HWND__* hwnd, struct FIELD* field)
{
      if(foundChild == NULL)
            EnumChildWindows(hwnd, (WNDENUMPROC) EnumChildProc, (LPARAM) field);

      return foundChild;
}

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam)
{
      static char szClass[51];
      GetClassName( hwnd, szClass, 50 );
      struct FIELD* f = (struct FIELD*) lparam;

      RECT rect;
      GetWindowRect( hwnd,  &rect);

      if(strcmp(szClass,f->fClass)==0 && rect.left == f->x && rect.top == f->y)
            foundChild = hwnd;

      RecursiveSearch( hwnd, f );
      return true;
}

BOOL closing = false;

DllExport BOOL WINAPI StopSystemHook(void)
{
      if(strcmp(logfilename, "\0") != 0)
      {
            logfile.open( logfilename, ios::app  );
            logfile << "CLOSING APPLICATION:HWND:" << appHook << ": \n";
            logfile.close();
      }

      if ( appHook != NULL )
            if( UnhookWindowsHookEx( appHook ) != 0 )
                  return true;

      return false;
}

HHOOK__ * HookTest;

DllExport HHOOK__* WINAPI InstallKeyboardLauncher(int process)
{
      HookTest = (HHOOK)SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)LauncherKeyboardHook, theApp.m_hInstance, 0);
      return HookTest;
}

LRESULT CALLBACK LauncherKeyboardHook (int nCode, WORD wParam, DWORD lParam)
{
      LRESULT Result = CallNextHookEx(HookTest, nCode, wParam, lParam);

      //HC_ACTION must equal 0 from printouts

      if(nCode == HC_ACTION)
      {
            if ((GetKeyState(VK_CONTROL) < 0) && (wParam == 'C'))
            {                  
                  if(lParam & 0x80000000)
                  {
                        Result = 0;
                  }
            }
      }
      return Result;
}

//used to rename the window so coudl find them redundant
/*
const char* appText = " - HOOKED";

HWND__* FindCurrentWindow( HWND__* wnd, char* name )
{
      HWND__* foundWND = FindWindow(NULL, name);

      char* newTitle = (char*) malloc(strlen(name)+strlen(appText)+1);
      strcpy(newTitle, name);                                    
      strcat(newTitle, appText);
                              
      while( foundWND > 0 )
      {
            if(foundWND != wnd)
            {
                  SetWindowText(foundWND, newTitle);
                  UpdateWindow(foundWND);
                  foundWND = FindWindow(NULL,name);
            }
            else
                  break;
      }                              

      //got foundWND now rename all that have been changed back
      while( FindWindow(NULL, newTitle) > 0 )
      {
            SetWindowText(FindWindow(NULL, newTitle), name);                                                                  
      }

      return foundWND;
}*/

BOOL AddCurrent( HWND__* butwnd, HHOOK__* mouseH, BUTTON* button, ParentWND* parent)
{
      int i;
      for(i=0; i<maxCurrentButtons; i++)
      {
            if( CurrentBut[i].parent == NULL)
            {
                  CurrentBut[i].parent = parent;
                  CurrentBut[i].button = button;
                  
                  int j;
                  for(j=0; j<maxLookupFields; j++)
                        CurrentBut[i].field[j] = NULL;

                  CurrentBut[i].buttonWND = butwnd;
                  CurrentBut[i].butMHook = mouseH;
                  return true;
            }
      }
      return false;
}

BOOL RemoveCurrent(int i)
{
      CurrentBut[i].parent = NULL;
      CurrentBut[i].button = NULL;

      int j;
      for(j=0; j<maxLookupFields; j++)
            CurrentBut[i].field[j] = NULL;

      CurrentBut[i].buttonWND = NULL;
      CurrentBut[i].butMHook = NULL;

      SortCurrent();

      return true;
}

void SortCurrent()
{
      int i;
      int blank=0;

      for(i=0; i<maxCurrentButtons; i++)
      {
            if(CurrentBut[i].parent == NULL)
                  blank = i;

            if(CurrentBut[i].parent != NULL && blank!=NULL)
            {
                  CurrentBut[blank].parent = CurrentBut[i].parent;
                  CurrentBut[blank].button = CurrentBut[i].button;
                  CurrentBut[blank].buttonWND = CurrentBut[i].buttonWND;
                  CurrentBut[blank].butMHook = CurrentBut[i].butMHook;

                  CurrentBut[i].parent = NULL;
                  CurrentBut[i].button = NULL;
                  CurrentBut[i].buttonWND = NULL;
                  CurrentBut[i].butMHook = NULL;

                  int j; //move the fieldWNDs
                  for(j=0; j<maxLookupFields; j++)
                  {
                        CurrentBut[blank].field[j] = CurrentBut[i].field[j];
                        CurrentBut[i].field[j] = NULL;
                  }

                  SortCurrent();
            }
      }
}
This is your problem :

//include all hook structs, io, and error
#include "hookstructs.cpp"
#include "hookio.cpp"
#include "hookError.cpp"
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of flynny

ASKER

doh just seen it i apologise what an idoit i've been i have this

//include all hook structs, io, and error
#include "hookstructs.cpp"
#include "hookio.cpp"
#include "hookError.cpp"

instead of the header files. not even sure why i did it!!
Avatar of flynny

ASKER

beat me to it Infinity thanks for the help.
It compiles fine now ?
Avatar of flynny

ASKER

yes thats fine its compiling just fine now. again you've been a big help.
Nice :)