?
Solved

Excel and BCB Dll Example

Posted on 2003-11-29
4
Medium Priority
?
887 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

801 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