Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //WeatherAppDlg.cpp
- typedef double ( __cdecl *CalculateWeatherfunptr) ();
- CalculateWeatherfunptr LibEntryPoint;
- HINSTANCE dllHandle;
- HANDLE threadHandle;
- int city;
- //these are my global variables
- BOOL CWeatherAppDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- dllHandle = LoadLibrary("C:\Users\1337832\Documents\Visual Studio 2005\Projects\WeatherApp\debug\Project1DLL.dll");
- if(dllHandle != 0)
- cout<<"DLL found";
- else
- cout<<"DLL not found";
- //loading the dll
- void CWeatherAppDlg::OnBnClickedPuneBtn()
- {
- city=1;
- LibEntryPoint = (CalculateWeatherfunptr)GetProcAddress(dllHandle,"CalculateWeatherPune");
- threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)myFunctionCaller,this,0,0);
- }
- void CWeatherAppDlg::OnBnClickedMumbaiBtn()
- {
- city=2;
- LibEntryPoint = (CalculateWeatherfunptr)GetProcAddress(dllHandle,"CalculateWeatherMumbai");
- threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)myFunctionCaller,this,0,0);
- }
- void CWeatherAppDlg::OnBnClickedDelhiBtn()
- {
- city=3;
- LibEntryPoint = (CalculateWeatherfunptr)GetProcAddress(dllHandle,"CalculateWeatherDelhi");
- threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)myFunctionCaller,this,0,0);
- }
- void CWeatherAppDlg::OnBnClickedBangaloreBtn()
- {
- city=4;
- LibEntryPoint = (CalculateWeatherfunptr)GetProcAddress(dllHandle,"CalculateWeatherBangalore");
- threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)myFunctionCaller,this,0,0);
- }
- DWORD WINAPI CWeatherAppDlg::Display()
- {
- CString str1;
- double temp;
- while(1){
- switch(city){
- case 1:
- temp = LibEntryPoint();
- Sleep(2000);
- str1.Format(_T("%f"),temp);
- m_puneControl.SetWindowText(str1);
- m_puneControl.RedrawWindow();
- break;
- case 2:
- temp = LibEntryPoint();
- Sleep(2000);
- str1.Format(_T("%f"),temp);
- m_mumbaiControl.SetWindowText(str1);
- m_mumbaiControl.RedrawWindow();
- break;
- case 3:
- temp = LibEntryPoint();
- Sleep(2000);
- str1.Format(_T("%f"),temp);
- m_delhiControl.SetWindowText(str1);
- m_delhiControl.RedrawWindow();
- break;
- case 4:
- temp = LibEntryPoint();
- Sleep(2000);
- str1.Format(_T("%f"),temp);
- m_bangaloreControl.SetWindowText(str1);
- m_bangaloreControl.RedrawWindow();
- break;
- default : cout<<"case does not match";
- }
- }
- return 0;
- }
- DWORD WINAPI CWeatherAppDlg::myFunctionCaller(LPVOID* param)
- {
- CWeatherAppDlg *classPtr = (CWeatherAppDlg*)param;
- classPtr->Display();
- return 0;
- }
Add Comment
Please, Sign In to add comment