Guest User

Untitled

a guest
Jan 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. //WeatherAppDlg.cpp
  2. typedef double ( __cdecl *CalculateWeatherfunptr) ();
  3. CalculateWeatherfunptr LibEntryPoint;
  4. HINSTANCE dllHandle;
  5. HANDLE threadHandle;
  6. int city;
  7. //these are my global variables
  8.  
  9. BOOL CWeatherAppDlg::OnInitDialog()
  10. {
  11. CDialog::OnInitDialog();
  12. dllHandle = LoadLibrary("C:\Users\1337832\Documents\Visual Studio 2005\Projects\WeatherApp\debug\Project1DLL.dll");
  13. if(dllHandle != 0)
  14. cout<<"DLL found";
  15. else
  16. cout<<"DLL not found";
  17. //loading the dll
  18.  
  19. void CWeatherAppDlg::OnBnClickedPuneBtn()
  20. {
  21. city=1;
  22. LibEntryPoint = (CalculateWeatherfunptr)GetProcAddress(dllHandle,"CalculateWeatherPune");
  23. threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)myFunctionCaller,this,0,0);
  24. }
  25.  
  26. void CWeatherAppDlg::OnBnClickedMumbaiBtn()
  27. {
  28. city=2;
  29. LibEntryPoint = (CalculateWeatherfunptr)GetProcAddress(dllHandle,"CalculateWeatherMumbai");
  30. threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)myFunctionCaller,this,0,0);
  31.  
  32. }
  33.  
  34. void CWeatherAppDlg::OnBnClickedDelhiBtn()
  35. {
  36. city=3;
  37. LibEntryPoint = (CalculateWeatherfunptr)GetProcAddress(dllHandle,"CalculateWeatherDelhi");
  38. threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)myFunctionCaller,this,0,0);
  39. }
  40.  
  41.  
  42. void CWeatherAppDlg::OnBnClickedBangaloreBtn()
  43. {
  44. city=4;
  45. LibEntryPoint = (CalculateWeatherfunptr)GetProcAddress(dllHandle,"CalculateWeatherBangalore");
  46. threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)myFunctionCaller,this,0,0);
  47. }
  48.  
  49. DWORD WINAPI CWeatherAppDlg::Display()
  50. {
  51. CString str1;
  52. double temp;
  53. while(1){
  54. switch(city){
  55. case 1:
  56. temp = LibEntryPoint();
  57. Sleep(2000);
  58. str1.Format(_T("%f"),temp);
  59. m_puneControl.SetWindowText(str1);
  60. m_puneControl.RedrawWindow();
  61. break;
  62. case 2:
  63. temp = LibEntryPoint();
  64. Sleep(2000);
  65.  
  66. str1.Format(_T("%f"),temp);
  67. m_mumbaiControl.SetWindowText(str1);
  68. m_mumbaiControl.RedrawWindow();
  69. break;
  70. case 3:
  71. temp = LibEntryPoint();
  72. Sleep(2000);
  73. str1.Format(_T("%f"),temp);
  74. m_delhiControl.SetWindowText(str1);
  75. m_delhiControl.RedrawWindow();
  76. break;
  77. case 4:
  78. temp = LibEntryPoint();
  79. Sleep(2000);
  80. str1.Format(_T("%f"),temp);
  81. m_bangaloreControl.SetWindowText(str1);
  82. m_bangaloreControl.RedrawWindow();
  83. break;
  84. default : cout<<"case does not match";
  85. }
  86. }
  87. return 0;
  88. }
  89. DWORD WINAPI CWeatherAppDlg::myFunctionCaller(LPVOID* param)
  90. {
  91. CWeatherAppDlg *classPtr = (CWeatherAppDlg*)param;
  92. classPtr->Display();
  93. return 0;
  94. }
Add Comment
Please, Sign In to add comment