View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Matt Matt Matt Matt is offline
external usenet poster
 
Posts: 2
Default A problem when trying to run a dll from Excel / VBA

Hi,
A decade ago, I last ran dlls from the VBA environment. I'm tryin
again, and my day of reading, hacking and googling has yeilded only
failure for me.

When I use Application.Run, it appears that the executable dll is
being read as a text file input to the spreadsheets.

Here is a test case code, in the .xls file, VBA environment, in the
ThisWorkbook module:

Option Explicit
'be sure to go to Tools--References and add in the reference to the
desired dll/exe/ocx
Private Declare Sub Main Lib "C:\Documents and Settings\TestCase
\Project1.dll" ()
Sub TestCase()
Application.Run ("C:\Documents and Settings\TestCase\Project1.dll!
Main")
End Sub


I have a Project1.vbp, with a single class module in it, Class1. It
is compiled to Project1.dll.
The code of Class1 is:
Public Sub Main()
MsgBox "Main"
End Sub


When I run TestCase, I get a message box indicating the following
lines:
This file is not in a recognizable format.
If you know the file is from another program which is incompatible
with Microsoft Office Excel, click Cancel, .......
If you suspect the file is damaged, click Help for more information
about solving the problem.
If you still want to see what text is contained in the file, click
OK.....


If I hit OK, the binary of the dll is read in to a spreadsheet.

What am I screwing up?


Other info:
Excel VBA environment
About Microsoft Visual Basic
Microsoft Visual Basic 6.3
Version 9972
VBA: Retail 6.4.9972

VB6 environment
Microsoft Visual Basic 6.0
For 32-bit Windows Development
Version 8176
VBA: Retail 6.0.8169

I'm on an XP system.
thanks,
Matt