Link to home
Start Free TrialLog in
Avatar of dib
dib

asked on

DLL access from VBA

hi,
I wrote a (MFC-) DLL and want to acces some methods from VBA:

Declare Function GetVal Lib "MyDll" Alias "MyValue" () As Integer

The VBA error is: "Funktion is not defined in that DLL".
From a C++ exe I could access the Method without any problems ...!
I tried a MFC extension DLL (with AFX_EXT_CLASS) and also a  shared
MFC DLL (with __declspec(dllexport) ).
So whats wrong?
Avatar of dib
dib

ASKER

Edited text of question
try to define the function as WINAPI type

example:  long WINAPI MyFunc(param 1, param 2);

do not forget that your exported function CANNOT be a class-member... or else it will never ever work in VB (which does not know anything about C++ classes)...

Good luck
Avatar of dib

ASKER

Defining the function as WINAPI did not work with VBA ...
anyway the decaration with: extern "C" __declspec(dllexport) int MyFunc();
works fine.
Is this the only declaration I could use?

Avatar of dib

ASKER

Defining the function as WINAPI did not work with VBA ...
anyway the decaration with: extern "C" __declspec(dllexport) int MyFunc();
works fine.
Is this the only declaration I could use?

Avatar of dib

ASKER

mmh with this declaration I'm not able to use Afx-functions (e.g.AfxMessageBox) inside
MyFunc...!?
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dib

ASKER

Ok,
but functions like AfxMessageBox, call e.g. CWinApp* AfxGetApp() ...
and calling such functions from VBA crashes my DLL because AfxGetApp()
returns NULL.
I see. Use ::MessageBox instead.