Solved

Excel and BCB Dll Example

Posted on 2003-11-29
4
858 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now