Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Visual basic 6 - linking to a dll file ?

Posted on 2006-06-25
17
Medium Priority
?
1,493 Views
Last Modified: 2013-11-25
I am wanting to integrate a custom dll into my Visual Basic 6

and the steps given are

(1)Add MRTLib.h and MRTLib.dll to a project.

(2)Implement LoadLibrary() Win32 API function to load “MRTLib.dll”

(3)Following (2), get function pointer address for each function of the DLL with GetProcAddress() API.

(3) Implement your program code.

(4) Build and debug.

Im stuck at the first step

Im not able to add project->reference to MRTLib.dll since visual studio says "can't add a reference to the specific file"

But if I add these lines the visual basic project compiled

Private Declare Function MRT_Init _
      Lib "C:\MRTlib.dll" _
                     (ByVal hwnd As Long, _
                     ByVal messageoffset As Integer _
                     ) As String

But Im not sure whether it is OK since Im not including either the .lib or the .h files ?

HOw to proceed to steps 2 ) and step 3) above


also in the usage document they have said
/* You have to prepare to reserve window message id for the DLL for your program, */
/* and assign the DLL with MRT_Init() API. */
status = MRT_Init(hInstDLL, DLL_MESSAGE_OFFSET); // formulaic procedure.
MRT_Init(
HWND hWnd, // [in] Handle to window waiting a message.
UINT messageOffset // [in] Offset value of message ID.
);

(2) Parameters
hWnd
[in]    An window handle receive the message.
messageOffset
[in]    Specify the message ID which is the head value of range used by this library (DLL).

so what should I pass from visual basic to the MRT_init function for hWnd and messageOffset ?

What is reserving window message ?

What is Message offset ?

also I have a query about how to retrieve the returned value from functions of this dlls

The document says for example

3) Return Values for the MRT_init function is

MRT_STATUS

MRT_NORMAL: This function succeeds.

i.e how do I find using visual basic whether the MRT_STATUS is MRT_NORMAL ??

Please advise

chris
0
Comment
Question by:christopher sagayam
  • 4
  • 4
  • 2
  • +2
17 Comments
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 16981372
have u registered the dll u r using... unless n until u register it u cannot add reference to that dll..
First register the specific dll and try again.

http://www.filesland.com/companies/EMSA-SYSTEMS-LTD/Emsa-Register-Dll-Tool.html

Use this tool to register or unregister any dll. Its very easy.
0
 
LVL 6

Author Comment

by:christopher sagayam
ID: 16981396
I tried to register now but the get the error

.dll was loaded but the dllregisterserver entry point was not found
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 1000 total points
ID: 16982586
First of all a regular windows dll doesn't need to be registered. If its not an activeX.dll than you will have to use the declerations to call one of the exported functions.
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 1000 total points
ID: 16982607

>(2)Implement LoadLibrary() Win32 API function to load “MRTLib.dll”
>(3)Following (2), get function pointer address for each function of the DLL with GetProcAddress() API.
you gotta love vb,
it handles this crap


just use it like you should do with normal api,
for example:
MRT_Init _   me.hwnd, 15
0
 
LVL 6

Author Comment

by:christopher sagayam
ID: 16982637
Thanks for the me.hwnd tip

Ok I will use it for this function argument namely hInstDLL

can you please tell me what I should use for DLL_MESSAGE_OFFSET

The documentation says

 Specify the message ID which is the head value of range used by this library (DLL)

Can you please tell me what is a message offset and how can I get it using visual basic ?
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16982652

sorry, i can't help you with that....
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16982689
Well the return value from the looks of it is the returned status code. However I don't belive that its a return value of a string. This might be a long value.

Private Declare Function MRT_Init _
      Lib "C:\MRTlib.dll" _
                     (ByVal hwnd As Long, _
                     ByVal messageoffset As Integer _
                     ) As Long

Dim Status as long

Status = MRT_Init(me.hwnd,DLL_MESSAGE_OFFSET)

Now if you have the header file than you could look up the defined value of DLL_MESSAGE_OFFSET. This value has to be documented or you will never know how to call this exported function.
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 16986810
most return values from dlls are longs...either zero or a positive number usually stands for success however it can vary.
Some also use specific return values to stand for constant strings...

As far as referecing the dll from vb, it may need to be compiled with a .def file
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 16990157
U can try 1 thing..
I think the custom dll u r using might be many in number on ur pc. U might hav registered one of them and then it might hav been deleted by mistake. SO its entry is still in registry so u r getting error ' dllregisterserver entry point was not found'

DO one thing use Regmechanics or anyother registry checking software that removes invalid entries from registry. Then try again to register the dll u want to use. I am sure this time ur dll will surely register. Then u can add its reference to ur program.
0
 
LVL 6

Author Comment

by:christopher sagayam
ID: 16990215
Just found out that all functions in the dll return

a structure like

typedef enum tag_MRT_STATUS {
      MRT_NORMAL,
      MRT_E_FATAL,
      MRT_E_OVERFLOW,
} MRT_STATUS;

so for capturing the return value what datatype I must use in Visual basic ?

specifically

Private Declare Function MRT_Init _
      Lib "C:\MRTlib.dll" _
                     (ByVal hwnd As Long, _
                     ByVal messageoffset As Integer _
                     ) As Long --> ** The return value must be a C STRUCT equivalent **

Dim Status as long  --> It must be an equivalent of C STRUCT

Status = MRT_Init(me.hwnd,DLL_MESSAGE_OFFSET)

The 'Status' variable is in fact a C STRUCT

so what is the equivalent of a CSTRUCT in Visual basic ?
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16990895
The enum is just long values. You can either create the Enum in VB and use it within your declerations or you can just use a long variable.

'Where ? means the value of defined constant

public Enum My_Status
   MRT_NORMAL = ?
   MRT_E_FATAL = ?
   MRT_E_OVERFLOW = ?
End Enum

Private Declare Function MRT_Init _
      Lib "C:\MRTlib.dll" _
                     (ByVal hwnd As Long, _
                     ByVal messageoffset As Integer _
                     ) As My_Status


'Or simply just

Private Declare Function MRT_Init _
      Lib "C:\MRTlib.dll" _
                     (ByVal hwnd As Long, _
                     ByVal messageoffset As Integer _
                     ) As Long
0
 
LVL 6

Author Comment

by:christopher sagayam
ID: 16991173
Thanks for the help and Im able to progress now to the NEXT stage

The same dll expects a pointer to an array of STRUCT

Private Type MRT_List
version As Byte
instance As Long
speed As Integer
opbit As Integer
product As Integer
End Type

Dim somevar(1 to 10) as MRT_list

How do I pass a pointer to the array of an User defined datatype in visual basic ?

i.e I want to pass a pointer to the array "somevar" to a function

I have tried

Private Declare Function VarPtr Lib "msvbvm60.dll" Alias "VarPtr34" (Var() As Any) As Long

Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr34" (Var() As Any) As Long

Private Declare Function VarPtrStringArray Lib "msvbvm60.dll" Alias "VarPtr35" (Var() As Any) As Long

etc but it says data type mismatch
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16996199

Dim m_List as MRT_List

then simply.

Varptr(m_List)
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17293846
correct answer given by egl1044
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question