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?
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?
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
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
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?
anyway the decaration with: extern "C" __declspec(dllexport) int MyFunc();
works fine.
Is this the only declaration I could use?
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?
anyway the decaration with: extern "C" __declspec(dllexport) int MyFunc();
works fine.
Is this the only declaration I could use?
ASKER
mmh with this declaration I'm not able to use Afx-functions (e.g.AfxMessageBox) inside
MyFunc...!?
MyFunc...!?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok,
but functions like AfxMessageBox, call e.g. CWinApp* AfxGetApp() ...
and calling such functions from VBA crashes my DLL because AfxGetApp()
returns NULL.
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.
ASKER