|
-
March 3rd, 2025, 12:28 PM
#1
[RESOLVED] DLL and communication with VBA
Hi all. It's been a while since I have done any coding so bare with me. I have the DLL code built with no errors, but from VBA the code does not run and I get no compile errors from the macro. I'm trying to create a very simple timer with Sleep as the wait time for the timer. The code is as follows, please let me know what I'm missing.
In the past for DLL's I would use LoadLibrary and GetFunctionPTR. Do I need to also do the same with this program from VBA?
*.H
#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();
*.C
// Utility functions for EPIQ.
#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");
//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);
// HWND hWnd;
// HWND hChildWnd;
//LPCWSTR OK = "OK"
// hWnd = 0
// hWnd = FindWindow(NULL, "Message from webpage");
// If(hWnd > 0)
// {
// hChildWin = 0;
//Now find the OK button to send the message to EPIQ dialog box to close
// hChildWin = FindWindow(hWnd, 0, NULL, (LPCSTR) "OK");
// If(hChildWin > 0)
// {
// Sleep(100)
//restore the last button state to normal
// SendMessage(hChildWnd, BM_SETSTATE, NULL, NULL);
// SendMessage(hChildWnd, WM_LBUTTONDOWN, NULL, 11);
// SendMessage(hChildWnd, WM_LBUTTONDOWN, 1, NULL);
// SendMessage(hChildWnd, WM_LBUTTONUP, NULL, NULL);
// SendMessage(hChildWnd, BM_SETSTATE, 1, NULL);
// SendMessage(hChildWnd, BM_SETSTATE, NULL, NULL);
// }
// }
return;
}
// Runs the timer routine.
void EPIQ_ExecuteTimer()
{
if (bTimerOn)
{
EPIQ_TimerProc();
EPIQ_SetTimer();
}
return;
}
// The actual timer section
void EPIQ_SetTimer()
{
// check to see if we'd overflow result or position
if (bTimerOn == TRUE)
{
Sleep(ulWait);
EPIQ_ExecuteTimer();
}
return;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|