DLL Help. VB.net to Access

kleblanc

AccessDude
Local time
Today, 12:34
Joined
Jan 15, 2004
Messages
12
Attached is a Sample program in VB.net 2005.
The sample program performs what I want to happen in Access.

Can this DLL be accessed in Access 2003 or higher?

If so how do I make the commands in the DLL available in Access?

Keith
 

Attachments

Last edited:
This is not the BEEP Command. It is to Beep a device conected to the Computer. The commands are listed in the Reference OTS_SR_C.

Below is the Code in VB.NET:

Imports OTS_SR_C

Public Class Form1
Dim SRC_Device = New SR_C

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SRC_Device.beep()
End Sub
End Class
 
Are we referring to a form?

If that's the case, then that probably won't work. You need to refer to it as a library, rather than an application. In your case, you only need a "SRC_Device.Beep" method.

Is SR_C's base type an object? If not, then you will need to have a wrapper class.
 
Here is the Sample in C#.

This should help you see what I am asking.

Can the Reference OTC_SR_C be used in access?
 

Attachments

and it has the COM interop checked?

If SR_C's base type is a object and not inherited from anything else, then all you would need to do is to pass this code in Access (assuming DLL takes care of identifying the device)

Code:
Private Sub foo()

Dim MySRC as New SR_C

MySRC.Beep

End Sub
 
Ok, I took look at the C# files, but there weren't any DLL file to be found; it's referenced in the project but there's an error- I think it may be missing..

Let me clarify- Do you have the actual source code for the DLL itself, not the Window application?

[strike]If you don't have the source code for the DLL, and it's not COM-interoperable, then you are SOL.[/strike]


On second thought, if you don't have DLL's source code and it's not COM-interoperable, you may be able to get away with creating a wrapper DLL that calls the first DLL, then exposes its methods via a .TLB file which you can then add as a reference to Access application.
 
A quick check on the DLL verified that it's not COM-interoperable, at least not to Access.

You will need to write a wrapper library that basically copies the methods. Here's a quick'n'dirty example:

Code:
Using OTS_SR_C

public class SR_COM
     {
     public void Beep
           {
           OTS_SR_C.Beep
           }
     }
}

Compile the wrapper DLL with COM interop enabled, then in Access, select the TLB file as a reference, then you can now use that method Beep.
 
Can't it be done something like this in a module?

Private Declare Function ShowWindow Lib "USER32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
 
The issue is how the DLL is written, which I have absolutely no idea.

If it was written with .NET framework, then it will sure as hell not work with COM applications. The Windows APIs are written in a specific way so it's accessible to anything running on the Windows. This isn't true for all custom DLLs.

If you really wanted to try (and possibly crash Access in process), you could try something like this:

Code:
Private Declare Function DevBeep Lib "C:\OTR_R_C.DLL" ( <Insert the required arguments> )

Keep in mind that this is much more unsafe than if you explicitly reference using the proper COM interop services.
 
The Wrapper dll works fine.

I did find the code for the original dll last night. So I am going to try to recompile that code to use in Access.

Thank you for the help Banana.
 

Users who are viewing this thread

Back
Top Bottom