Solved

DLL access from VBA

Posted on 1998-08-12
8
302 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
  • 5
  • 2
8 Comments
 

Author Comment

by:dib
Comment Utility
Edited text of question
0
 
LVL 1

Expert Comment

by:amby
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:dib
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I see. Use ::MessageBox instead.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now