• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 913
  • Last Modified:

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;
}



0
alcindor
Asked:
alcindor
  • 2
1 Solution
 
DanRollinsCommented:
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
0
 
alcindorAuthor Commented:
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
0
 
DanRollinsCommented:
You probably need to pass BSTR, which is a pointer to a UNICODE string whose storage is managed by the system.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now