Link to home
Start Free TrialLog in
Avatar of Roger Alcindor
Roger Alcindor

asked on

Excel and BCB Dll Example

I need a working trivial example of a DLL written in Borland C++ Builder having a simple function and an excel spreadsheet VBA declaration that will enable me to call the function.
I have tried but with no success so far. Excel always says that it cannot find the dll.
my code for excel and bcb dll is as follows :-

EXCEL:-
Private Declare Function changeValue Lib "mydll" (x As Integer) As Integer

Private Sub CommandButton1_Click()
Dim k As Integer
k = 3
Sheet1.Cells.Range("A1").Value = changeValue(k)
End Sub

Borland C++ Builder DLL source:-
extern "C" __declspec(dllexport) int __stdcall changeValue(short int y);
int x;
int __stdcall changeValue(short int y)
{
      return y + x++;
}

#pragma argsused
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
    x = 7;
    return 1;
}



Avatar of DanRollins
DanRollins
Flag of United States of America image

I looks pretty good, except...

Maybe you need to provide the full drive and path and file in the Excel declaration.

   Private Declare Function changeValue Lib "c:/mydir/mydll.DLL" (x As Integer) As Integer

-- Dan
Avatar of Roger Alcindor
Roger Alcindor

ASKER

I had already tried putting the complete path in but that didn't work.
I have just found the answer, I need to declare the function name in uooercase, it would seem that Excel is not case sensitive and requires all uppercase ?

I have another problem now in returning a value to an excel string parameter passed by reference to my BCB function.
The C function declares the parameter as a char *

I guess that I should post this as another question ?

Thanks for your comment anyway

Roger
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial