It is usually the calling program that needs to adjust to the dll. There are some differences in the way variables are stored that must be considered. And dlls typically use stdcall. With a custom dll for a specific application, you can do just about anything you want. Without knowing more about the problem it is hard to make recommendations.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Anybody has experience of making a dev c++ dll for VBA application? Please give me a hint.
Thank you.
Could you be more specific about the problem?
It is usually the calling program that needs to adjust to the dll. There are some differences in the way variables are stored that must be considered. And dlls typically use stdcall. With a custom dll for a specific application, you can do just about anything you want. Without knowing more about the problem it is hard to make recommendations.
Start here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odeopg/html/deovrthewindowsapiotherdynamiclinklibraries.asp
Cheers,
Ian
thank you guys, and sorry,
I know the _stdcall thing and basically I can make a dll for VBA using VC++, by starting with an empty project, plus a DEF file.
It seems VBA really needs that DEF file, but DEV C++ doesn't like it. So this is my biggest issue right now.
The link Lan provided is good and I'll read it. Please keep pouring more quick hints here.
Thanks again,
If name mangling is a problem compile the dll with the linker options
--add-stdcall-alias
--no-export-all-symbols
Then look at the output DEF file from the dll compile.
I have succeeded in making a dll which export a function to MS Excel
add this 2 files "mydll.cpp" and "mydll.h" to a dev-c++ project and compile to a dll.
The declaration of the function in VBA is as follows
Public Declare Function NormalDeviate Lib "SearchPatch" (ByVal Mean As Double, ByVal Std As Double) As Double
The function NormalDeviate returns a Random Normal deviate with specified mean and standard deviation to MS Excel.
Good luck!
This is the code in file "mydll.cpp"
include "mydll.h"
include <windows.h>
include <math.h>
include <time.h>
DllClass::DllClass()
{
}
DllClass::~DllClass ()
{
}
BOOL APIENTRY DllMain (HINSTANCE hInst / Library instance handle. / ,
DWORD reason / Reason this function is being called. / ,
LPVOID reserved / Not used. / )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
}
define dllexport __declspec(dllexport)
extern "C"
{
double unirand()
{
return (rand()+1.0)/(RAND_MAX+1.0);
}
}
This is the code in file "mydll.h"
ifndef DLL_H
define DLL_H
if BUILDING_DLL
define DLLIMPORT __declspec (dllexport)
else / Not BUILDING_DLL /
define DLLIMPORT __declspec (dllimport)
endif / Not BUILDING_DLL /
class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass(void);
private:
};
endif / DLL_H /