Referencing unregistered DLL  
Author Message
Richard Meijer





PostPosted: Visual Basic for Applications (VBA), Referencing unregistered DLL Top

Hi all,

I've had kind help with part 1 of my problem somewhere else on the forum, but I think part 2 should be posed here.

What I am trying to do is create a .dll-file (TestDLL) that contains a function (StartMe) initiating a form (frmMain) and then call that form from both an EXE-file and an Excel add-in.
The DLL-file I created with VB 2005 could not be registered with Windows, so I could not call the function StartMe from within the EXE. As it turns out, I could simply include a reference to TestDLL in the EXE-file, telling it where to look for the function StartMe. Logical deduction would therefore tell me I should also include a reference to TestDLL in the VBA-code, telling that where to find StartMe.

Is it possible to do that
If not, is there a way to make a registerable dll so that any and all programs (both EXE and ..XLA / VBA) can call it

I know it was possible to run a program both as standalone and as an Add-in way back with VB5 as I found a VB5 program that does just that. Unfortunately I'm not experienced enough to figure out how to go about doing that . Any help (tips, sample code etc) would therefore be greatly appreciated.

Kind regards,

Richard



Microsoft ISV Community Center Forums2  
 
 
duck thing





PostPosted: Visual Basic for Applications (VBA), Referencing unregistered DLL Top

<<The DLL-file I created with VB 2005 could not be registered with Windows, so I could not call the function StartMe from within the EXE.>>

How are you creating the DLL I've been using the VB.NET command line compiler at work to build DLLs and then call them through EXE files, and haven't had an issue. (Though I don't believe this would work from VBA, at least not in Excel 2003).

If you know the function signature for the function you want to call, you can use Declare Sub or Declare Function to link to the function in the DLL. For example:

Declare Function MyFunc Lib "MyDLL.dll" Alias "MyFuncA" (ByVal Param1 As Integer, ByVal Param2 As String) As Boolean



 
 
Richard Meijer





PostPosted: Visual Basic for Applications (VBA), Referencing unregistered DLL Top

Hi Duck Thing,

I've created a dll by starting a new "Class Library" project in VB2005. When I build that project, a dll appears in the obj\release folder. However, that dll can't be registered with Windows. Is there another way to create a dll, one that can be registered

With "Declare Function .... etc ...." isn't it only possible to link to registered dll's Even though I know the function signature for the dll (TestDLL.dll), I can't seem to call it from within VBA.

The function I am trying to call is the following one by the way:

Public Function StartMe (byVal sCallSign As String) As Boolean
'find out if program is called from Excel or is standalone
If Trim(UCase(sCallSign)) = "EXCEL" Then
bExcelOpen = True
Else: bExcelOpen = False
End If

'start the program
Call MainProgram
StartMe = True
End Function

Regards,

Richard


 
 
Derek Smyth





PostPosted: Visual Basic for Applications (VBA), Referencing unregistered DLL Top

Hi,

If it's a .NET assembly you've created then you can't register it with regsrv32.exe, you need to use regasm.exe which is runnable from the Visual Studio Command Prompt. Also it's a good idea to strongly name the assembly and to install it into the GAC.



 
 
Richard Meijer





PostPosted: Visual Basic for Applications (VBA), Referencing unregistered DLL Top

Hi Duck Thing and Derek,

Thanks both for your invaluable help. I was struggling with this issue for quite some time, but everything is solved now... Programming life is good again .

Cheers,

Richard