Multithread external DLL with PowerPoint 2003 VBA callback functio

T

Tobias Kober

Hi,

I'm currently trying to get to work a VBA application which uses an external
DLL (which I program parallely). The DLL starts a separate worker thread
which calls a previously registered VBA callback function. This works
perfectly (e.g. I can do a MsgBox "I was called with argument " + str(arg))
but if I try to change a slide in my
slide show, PowerPoint says that "Hyperlink ^0" doesn't exist and crashes.
At the end of this post I put a little bit of code in order to explain what
I'm trying to do.
If I call the VBA procedure *not* inside the thread (e.g. in a method of
MyObject), it works, so I think it has something to do with the threading.
It would give me great pleasure I anyone could help me solving this issue.
I've struggled with this for three days now and I'm at my wits' end...

Thank you very much in advance,

Tobias

-------------- Code -----------------
C++ DLL
=======
class MyObject {
typedef void (CALLBACK *callback_t)(long);
friend DWORD WINAPI WorkerThread(LPVOID pParam);

createWorkerThread() {
// ...
thHdl = ::CreateThread(0, NULL, &WorkerThread, this, &wThreadID);
// ...
}

setCallbackFunc(long addr) {
callbackFunc = (callback_t) addr;
}

HANDLE thHdl;
callback_t callbackFunc;
};

DWORD WINAPI WorkerThread(LPVOID pParam) {
MyObject *objLink = (MyObject *)pParam;

while (objLink->someCondition()) {
waitForSomething();
objLink->callbackFunc(objLink->getNextSlide());
}
}

VBA
===
Private slideShowWin As SlideShowWindow

Public Sub Init
With ActivePresentation.SlideShowSettings
.ShowType = ppShowTypeWindow
Set slideShowWin = .Run
End With
setCallbackFunc AddressOf callbackSub
createWorkerThread
End Sub

Public Sub callbackSub(long slideNo)
slideShowWin.View.GotoSlide slideNo
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top