Solved

DLL access from VBA

Posted on 1998-08-12
8
340 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:dib
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 

Author Comment

by:dib
ID: 1320629
Edited text of question
0
 
LVL 1

Expert Comment

by:amby
ID: 1320630
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
0
 

Author Comment

by:dib
ID: 1320631
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?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dib
ID: 1320632
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?

0
 

Author Comment

by:dib
ID: 1320633
mmh with this declaration I'm not able to use Afx-functions (e.g.AfxMessageBox) inside
MyFunc...!?
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1320634
extern "C" is a must. Otherwise the function is mangled. You can still call MFC functions inside the function with this declaration. __declspec(dllexport) should be used also to export the function.
0
 

Author Comment

by:dib
ID: 1320635
Ok,
but functions like AfxMessageBox, call e.g. CWinApp* AfxGetApp() ...
and calling such functions from VBA crashes my DLL because AfxGetApp()
returns NULL.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1320636
I see. Use ::MessageBox instead.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question