Thread: Load Dll
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Andy Smith Andy Smith is offline
external usenet poster
 
Posts: 13
Default Load Dll

The DLL is loaded when the Excel file is opened, provided there's a
declaration for the WaitPSSync function in your code, and the DLL is in
either System32 or the same folder as the Excel file, in which case it's best
to change the current directory to that folder by putting "ChDir
ThisWorkbook.Path" in ThisWorkbook/Workbook_Open.

You have to be careful and know the language/compiler with which the DLL was
written, because the Declare statement in the VBA code has to have all
parameters and the return type identical with respect to both type and
calling convention (reference/value). In particular, C/C++'s default
convention is by value, but VBA's is by reference (pointer). Worse yet,
string parameters, which are pointers, should nevertheless be declared by
value, because the parameter is actually a pointer.

For example:
Public Declare Function WaitPSSync Lib "ehllap32" As Long
assumes it takes no parameters and returns a signed long

but:
Public Declare Sub WaitPSSync Lib "ehllap32" (ByVal LongParm As Long)
takes a signed long and returns nothing.

--

--Andy Smith



"Lisandro Oliveira" wrote:

Does anyone know how can I load a dll from vba (excel)

Path: "C:\apps_pub\tn327080\ehllap32.dll

I need to execute this function: WaitPSSync()

Tks,
Lisandro Oliveira.