none
howto use DLLs files without References or Register them in ms access RRS feed

  • Question

  • Hi all
    In his site (Http://www.lebans.com/reporttopdf.htm  )
    Stephen Lebans has a Microsoft Access file that
    uses 2 DLLs without References or Register them. (DynaPDF.dll ,StrStorage.dll)
    Does anyone know how to create such files in vs 2015
    Or can refer me to a helpful source on how to.

    I tried all kinds of DLL like the templates in  C ++ or C #
    but nothing seems  to work .

    Any help would be welcome
    Thanks

    Asaf
    • Edited by Asaf_S Thursday, March 16, 2017 11:13 AM
    Thursday, March 16, 2017 10:31 AM

Answers

  • Thank you all for the support.  (:
    this Dlls idea become very complicated
    and therefore expensive .
    so i decided to change the way to achieve the goal
    of guarding a part off the code from the application users.
    By making a file with modules only
    and compile the new file to accde  and then reference him from the original db.

    Asaf

    Thursday, March 16, 2017 6:57 PM

All replies

  • To create unmanaged code libraries, or Windows DLL libraries, you can use Visual C++:

    Walkthrough: Creating and Using a Dynamic Link Library (C++)

    If you have additional questions you should post to the Visual C++ forum:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vcgeneral


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, March 16, 2017 12:19 PM
  • Thank you so much Paul  (:
    I'll check it out.
    The reason I post  here is that  I am an  ms-access developer.
    And I plan to deploy it in ms-access application .
    So if I ask C ++ developers I'm not sure
    They knew the answer (related to access).

    Asaf

    Thursday, March 16, 2017 12:50 PM
  • Are you asking how to create a DLL, or how to use one without registering it?

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Thursday, March 16, 2017 1:51 PM
  • I am asking how to create  this kind of DLL
    Stephen Lebans in is reporttopdf is all ready  showing
    how to use one without registering it?

    Asaf

    Thursday, March 16, 2017 1:59 PM
  • I am asking how to create  this kind of DLL
    Stephen Lebans in is reporttopdf is all ready  showing
    how to use one without registering it?

    Yes, that's right.  I just wanted to make sure you were getting the right sort of replies, since your thread topic says, "how to use", not "how to create".


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Thursday, March 16, 2017 3:40 PM
  • Thank you so much Paul  (:
    I'll check it out.
    The reason I post  here is that  I am an  ms-access developer.
    And I plan to deploy it in ms-access application .
    So if I ask C ++ developers I'm not sure
    They knew the answer (related to access).

    Asaf

    As far as calling the DLL library functions from Access VBA is concerned, just make sure to use the correct calling convention for exporting the functions:

    https://msdn.microsoft.com/en-us/library/dt232c9t.aspx

    I'm sure if the C++ developers know how you are planning to use the DLL they should be able to help you with that.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, March 16, 2017 5:15 PM
  • Thank you all for the support.  (:
    this Dlls idea become very complicated
    and therefore expensive .
    so i decided to change the way to achieve the goal
    of guarding a part off the code from the application users.
    By making a file with modules only
    and compile the new file to accde  and then reference him from the original db.

    Asaf

    Thursday, March 16, 2017 6:57 PM
  • There are two kinds of external dll’s you can and would use with Access. (And Actually 3 if you include .net code).

    There are standard external .dll library code routines. These types of library do not need to be registered. As a “normal” course of use, you in general have to provide a full path name to that dll in the VBA declare statement.

    Eg:

    Public Declare Function MyBeep Lib "c:\MyCode\playsound.dll" _
         (ByVal soundFrequency As Long, ByVal soundDuration As Long) As Long

    The above is an example of how Stephan’s code works. However, Because Stephan did not want to “hard code” the location, but just SIMPLY copy the .dll to the SAME folder as the Access application, then Stephan’s code uses what is called the loadlib API.

    This runtime loading the .dll allows one to REMOVE the path name from the declare like this:

    Public Declare Function MyBeep Lib " playsound.dll" _
         (ByVal soundFrequency As Long, ByVal soundDuration As Long) As Long

    And before you use the code, then you use Stephan’s approach of loadlibrary. This approach thus allows you to set the .dll at runtime.

    Regardless of “loadlibary” or not, such external .dlls represent external .dll code that you call directly from Access and such code is NOT required to be registered. So the .dll's are NEVER required to be registered and thus Stephan's examples does NOT eliminate the need to register such .dll's since no such registration is required in the first place.

    The next common type of .dll or external code object is what we call a “COM” object, or ActiveX object. These types of objects require to you register the object on the target computer. Once the object is registered, then you can create an instance of that object

    Eg:

    myObj   = createObject("Word.Application").


    So keep in mind that some dll’s don’t need to be registered, but some do. To register such objects you use regsvr32.exe. And note that you cannot register those standard external .dll’s – but only .dll’s designed as “com” objects.

    And last but not least, you can also call + use .net code from Access. In this case you use regasm.exe, and this creates an ActiveX or “COM” object out of the .net code. This is a useful approach that allows you to consume .net code. And it is possible to “side load” these .net dll’s without having registered the object with regasm. (So this is similar in nature to Stephan’s example in which you use external .net code, but don’t have to register the code (object) in question.

    So the above quite much outlines 3 approaches to consuming external code in Access/VBA.

    Regards,
    Albert D. Kallal (Access MVP)
    Edmonton, Alberta Canada

    Thursday, March 16, 2017 8:22 PM
  • Hi Asaf_S,

    from your last reply , I can see that now you had changed the approach to handle this issue and you are not using dlls anymore.

    its good to know that you have got  the solution for your issue.

    I want to suggest you that kindly mark your last post as an answer.

    so that we can close this thread.

    if you don not mark the answer then it will remain open.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 17, 2017 5:33 AM
    Moderator
  • Thank you Albert
    For a detailed explanation. But probably i  did not explain myself properly.
    My problem is not where the DLL location or declaration .
    but the creation off the DLL itself. All my attempts so far was not seccessful in that
    I created a DLL that is ComVisible (True) and I had to register him with Regserv 32
    witch missing the goal of not doing that .
    if i try to use .net class then I received an error of "no entry point"
    But since the  idea became complicated , and a simpler solution is availible  for achieving the goal.
    So  ...

    Thank's :)

    Asaf

    Friday, March 17, 2017 7:24 AM
  • Well, unfortunately we can only provide you with answers to the questions you actually ask. ;-)

    Hopefully someone else doesn't find this confusing when searching for the answer to the original question.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, March 17, 2017 1:55 PM
  • >if i try to use .net class then I received an error of "no entry point"

    Yes, you are correct. However when using a .net class, then you are creating a COM object, and thus you use CreateObject() in Access. You can’t use “declare” for a .net .dll.

    So if you write this code in vb.net:

    Imports System.Runtime.InteropServices

    <ClassInterface(ClassInterfaceType.AutoDual)>
    Public Class AlbertCom1

        Public Function Hello() As String

            Return "hello how are you"
        End Function

        Public Sub MsgHello()

            MsgBox("Hello world", MsgBoxStyle.Information, "VB.net example")

        End Sub
    End Class

    The code really looks like and writes like VBA.

    So, just compile the above class. Make sure the project is set to x32 bits (x86). And check the box “register for com-interop).

    The resulting .dll can thus be used like this in access:

    Sub ComTest1()

       Dim MyObj      As New AlbertCom1.AlbertCom1
      
       MyObj.MsgHello
      
      
    End Sub

    So that’s all you require here. And what is great is .net has all kinds of cool abilities. For example, add this code to above and you can zip files in Access:

        Sub MyZipper(strFileName As String, strZipFile As String)


            Using archive As ZipArchive = ZipFile.Open(strZipFile, ZipArchiveMode.Update)
                archive.CreateEntryFromFile(strFileName, Path.GetFileName(strFileName), CompressionLevel.Fastest)
            End Using

        End Sub


    So now, in Access we can go:

       MyObj.MyZipper "c:\test\Invoice.pdf", "c:\test\Invoice.zip"


    So it not a lot of code required here. It sounds like  you found a solution but as long as you keep in mind and follow the different approaches required for the 3 types of .dll’s, then calling or consuming code is not difficult.

    So how your VBA/Access code calls that external code will require you to follow the above 3 rules and approaches. It sounds like your compiled accDE approach works just fine anyway.


    Regards,
    Albert D. Kallal (Access MVP)
    Edmonton, Alberta Canada

    Friday, March 17, 2017 4:12 PM