Chris S
asked on
Visual basic 6 - linking to a dll file ?
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
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
ASKER
I tried to register now but the get the error
.dll was loaded but the dllregisterserver entry point was not found
.dll was loaded but the dllregisterserver entry point was not found
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ?
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 ?
sorry, i can't help you with that....
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_MESSA GE_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.
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_MESSA
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.
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
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
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.
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.
ASKER
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_MESSA GE_OFFSET)
The 'Status' variable is in fact a C STRUCT
so what is the equivalent of a CSTRUCT in Visual basic ?
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_MESSA
The 'Status' variable is in fact a C STRUCT
so what is the equivalent of a CSTRUCT in Visual basic ?
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
'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
ASKER
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
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
Dim m_List as MRT_List
then simply.
Varptr(m_List)
correct answer given by egl1044
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.