Hi, I'm trying to generate a DLL that is just a simple timer like routine for activating when a System DLG box pops up. I am unable to get anything but 0 from the library. I have checked the code, but I don't see the issue. It would be great if someone could point out where my issue lies. Here is the C++/H code.
Code:
//
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include <utility>
#include <Windows.h>
#include <synchapi.h>
#include "EPIQ Util.h"
// DLL internal state variables:
static BOOL bTimerOn; // Turns on/off the timer
static BOOL bRunning; // Keeps us in the while loop
static unsigned long ulWait; // How long to wait
//void EPIQ_ExecuteTimer();
//void EPIQ_SetTimer();
//void EPIQ_init(const unsigned long);
//void EPIQ_StopTimer();
//void EPIQ_StartTimer();
// Initialize the Timer variables
void EPIQ_init(const unsigned long ullWait)
{
bTimerOn = FALSE;
ulWait = ullWait;
MessageBox(NULL, (LPCWSTR) "Made it here", (LPCWSTR) "We made it", NULL);
return;
}
// Stop the timer from running
void EPIQ_StopTimer()
{
bTimerOn = FALSE;
Sleep(ulWait);
return;
}
// Start the timer from running
void EPIQ_StartTimer()
{
bTimerOn = TRUE;
return;
}
//The actual process of the timer
void EPIQ_TimerProc()
{
//create two structures to hold our Main Window handle
//and the Button's handle
HWND WindowHandle;
HWND ButtonHandle;
//this window's caption is "File Download", so we search for it's handle using the FindWindow API
WindowHandle = FindWindow(NULL, (LPCWSTR) "Message from webpage");
SetForegroundWindow(WindowHandle);
//the Button's Caption is "OK" and it is a "Button". SPYXX.exe that comes with Microsoft Visual Studio will reveal this information to you
ButtonHandle = FindWindowEx(WindowHandle, 0, (LPCWSTR) "Button", (LPCWSTR) "OK");
//send a message to the button that you are "clicking" it. Surprisingly C++ understands what BM_CLICK is without having to set it. Different than VB
SendMessage(ButtonHandle, BM_CLICK, 0, 0);
return;
}
#pragma once
// EPIQ_Util.h - Contains declarations of Utility Functions
#pragma once
#ifdef EPIQUTIL_EXPORTS
#define EPIQUTIL_API __declspec(dllexport)
#else
#define EPIQUTIL_API __declspec(dllimport)
#endif
// The functions needed to interface with VBA EPIQ_Interface
// This function must be called before any other function.
extern "C" EPIQUTIL_API void EPIQ_init(const unsigned long);
// Set how long to wait in ms.
extern "C" EPIQUTIL_API void EPIQ_SetTimer();
// Perform the TimerProc function.
extern "C" EPIQUTIL_API void EPIQ_ExecuteTimer();
// disable the timer.
extern "C" EPIQUTIL_API void EPIQ_StopTimer();
// Start the Timer
extern "C" EPIQUTIL_API VOID EPIQ_StartTimer();
extern "C" EPIQUTIL_API void EPIQ_TimerProc();
//extern "C" EPIQUTIL_API HWND SetActiveWindow Lib "user32.dll" (HWND hwnd);
int SetForegroundWindow (int hwnd);
int SetActiveWindow(int hwnd);