LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default calling a shared lib from VBA in Excel


"Chip Pearson" wrote in message

Declare Function SetBootstraps lib "mylib" (ByVal nBootstraps As Long) As
Boolean


Should be

Declare Function SetBootstraps lib "mylib" (ByVal nBootstraps As Long) As
Long

Also, in VC++, there is "BOOL" and "bool", two distinct types: "BOOL" is a
long int (32-bits) and "bool" is a char (8-bits).

You can test the difference with

int __stdcall SizeOfBOOLUpperCase()
{
return sizeof(BOOL);
}

int _stdcall SizeOfboolLowerCase()
{
return sizeof(bool);
}

SizeOfBOOLUpperCase returns 4.
SizeOfboolLowerCase returns 1.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Chip Pearson" wrote in message
...
Ian,

The C DLL function must have been compiled with the "__stdcall" modifier,
and the function must have been exported with a DEF file. Also, since the
SetBootstraps function requires a value of nBootstraps, not a pointer, you
need the ByVal modifier in your Declare statement.

Declare Function SetBootstraps lib "mylib" (ByVal nBootstraps As Long) As
Boolean


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)






"Ian Kennedy" wrote in message
...
Hi I'm attempting to call a function in a shared library from a VBA macro
in excel. This is a typical c function:

extern "C" bool SetBootstraps(int nBootstraps)

In VBA I have it declared as:

declare function SetBootstraps lib "mylib" (nBootstraps as long) as
Boolean

When I attempt to run this via the c debugger I don't get the value
passed down to excel that I would expect. What do I have to do to pass
variables down correctly. Do I need to use CDecl in the VBA or do I need
to use pascal in the C. Which is correct.

Also am I correct in thinking that the following is correct

VBA C
Integer short
Long int
Double double
Boolean bool

Thanks
Ian





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shared Workbooks-shared headers and footers Sherry New Users to Excel 1 June 13th 08 03:59 PM
Saving shared spreadsheets on a shared drive. Meridith Excel Discussion (Misc queries) 0 April 3rd 08 05:20 PM
Issues with shared vs. non-shared formulas on somewhat wide spreadsheets david.karr Excel Discussion (Misc queries) 0 August 16th 07 12:52 AM
Printing viewing a shared workbook on a shared drive aloomba Excel Discussion (Misc queries) 0 April 13th 07 02:52 PM
update pivot in shared shared workbook 00George00 Excel Discussion (Misc queries) 1 August 23rd 06 08:16 PM


All times are GMT +1. The time now is 08:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"