Solved

DLL access from VBA

Posted on 1998-08-12
8
336 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
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
Industry Leaders: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 244
fix34  challenge 9 164
Use of condition with 'serial' in ansible 2 86
changeXy challenge 13 93
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

740 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