Solved

Excel and BCB Dll Example

Posted on 2003-11-29
4
864 Views
Last Modified: 2013-12-03
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
Comment
Question by:alcindor
  • 2
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 9843655
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
 
LVL 2

Author Comment

by:alcindor
ID: 9844053
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
 
LVL 49

Accepted Solution

by:
DanRollins earned 250 total points
ID: 9844581
You probably need to pass BSTR, which is a pointer to a UNICODE string whose storage is managed by the system.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 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