Visual Basic development
Visual Basic development
Hi,
I'd like to have a go at writing an application to interface with the PM3 but the only language I'm particularly familiar with is VD6. Can you tell me if the current development of the SDK is compatible with VB?
If you had a demo of the basic setup that would be superb!
Many thanks,
Mark.
I'd like to have a go at writing an application to interface with the PM3 but the only language I'm particularly familiar with is VD6. Can you tell me if the current development of the SDK is compatible with VB?
If you had a demo of the basic setup that would be superb!
Many thanks,
Mark.
Mark,
This post from the old forum: http://www.c2forum.com/viewtopic.php?t=87 was from a user who was trying to get the DLLs to work from inside VB6.
The SDK is NOT currently compatible with VB6, because it's defined in the DLL as using a c-style calling convention rather than the VB compatible stdcall.
There are some good links in that other post that will get you started. I'm not sure how much of the information that was linked to is still available, but basically what's necessary is an additional wrapper layer written in C/C++ that converts the cdecl DLLs into a stdcall version.
If you're willing to move to VB.NET or C# then you can import the functions in the DLLs even though they aren't stdcall. This is done by specifiying the calling convention in the .NET import statement. Let me know if you choose that route and I can post in the necessary import lines to get you started.
Mike
(Here's another good link on the .NET stuff: http://www.c2forum.com/viewtopic.php?t=88)
This post from the old forum: http://www.c2forum.com/viewtopic.php?t=87 was from a user who was trying to get the DLLs to work from inside VB6.
The SDK is NOT currently compatible with VB6, because it's defined in the DLL as using a c-style calling convention rather than the VB compatible stdcall.
There are some good links in that other post that will get you started. I'm not sure how much of the information that was linked to is still available, but basically what's necessary is an additional wrapper layer written in C/C++ that converts the cdecl DLLs into a stdcall version.
If you're willing to move to VB.NET or C# then you can import the functions in the DLLs even though they aren't stdcall. This is done by specifiying the calling convention in the .NET import statement. Let me know if you choose that route and I can post in the necessary import lines to get you started.
Mike
(Here's another good link on the .NET stuff: http://www.c2forum.com/viewtopic.php?t=88)
- Chris Brett
- 500m Poster
- Posts: 61
- Joined: May 25th, 2006, 10:07 am
An active X control is currently in development which will make coding PM3 applications in VB 6.0 and VBA fairly straightforward. In the hopefully short interim period however....
That link is very useful and the Chris Rey Code is a good starting point. Essentially you need to write/modify/copy a wrapper dll as per the link. The wrapper defines a stdcall function version
e.g
for each of the SDK functions that you wish to use (see the comprehensive PM3 Comms Interface Definition document for details)
e.g.
Example of a wrapper function definition
To use the wrapper.dll functions in VB you then simply declare them within your VB Code
e.g.
The most tricky part of the process if you are not familiar with compiling dlls is that you need the exported symbolic name of the functions we have defined within our wrapper.dll file.
In this case this is
The symbolic names are written to the map file which is generated when the dll is compiled. (Make sure that Generate Mapfile is selected when building a dll for use within a VB Project)
Here are some lines from the mapfile in this example
Note that this is where the "_W_tkcmdsetDDI_shutdown@4" comes from and that in this example the wrapper dll is called PM3_Wrapper
I hope that this is of some use.
That link is very useful and the Chris Rey Code is a good starting point. Essentially you need to write/modify/copy a wrapper dll as per the link. The wrapper defines a stdcall function version
e.g
Code: Select all
W_tkcmdsetDDI_shutdown(UINT16_T port)
for each of the SDK functions that you wish to use (see the comprehensive PM3 Comms Interface Definition document for details)
e.g.
Code: Select all
tkcmdsetDDI_shutdown(port)
Example of a wrapper function definition
Code: Select all
PM3_WRAPPER_API ERRCODE_T _stdcall W_tkcmdsetDDI_shutdown(UINT16_T port)
{
return tkcmdsetDDI_shutdown(port);
}
To use the wrapper.dll functions in VB you then simply declare them within your VB Code
e.g.
Code: Select all
Option Explicit
Private Declare Function W_tkcmdsetDDI_shutdown Lib "PM3_Wrapper.dll" _
Alias "_W_tkcmdsetDDI_shutdown@4" _
(ByVal port As Integer) As Integer
In this case this is
Code: Select all
"_W_tkcmdsetDDI_shutdown@4"
Here are some lines from the mapfile in this example
Code: Select all
0001:000001b0 _W_tkcmdsetDDI_discover_pm3s@12 100011b0 f PM3_Wrapper.obj
0001:00000210 _W_tkcmdsetDDI_shutdown@4 10001210 f PM3_Wrapper.obj
0001:00000270 _W_tkcmdsetDDI_fw_version@8 10001270 f PM3_Wrapper.obj
I hope that this is of some use.
Great summary of the VB-support issues.
If you want to export non-mangled names in your VB code, you can add a .DEF file to your VC++ wrapper DLL project.
Something like....
Then you can Declare W_tkcmdsetDDI_discover_pm3s rather than using the mangled name in VB.
Mike
If you want to export non-mangled names in your VB code, you can add a .DEF file to your VC++ wrapper DLL project.
Something like....
Code: Select all
LIBRARY PM3_Wrapper
EXPORTS
W_tkcmdsetDDI_discover_pm3s = _W_tkcmdsetDDI_discover_pm3s@12
Mike
-
- Paddler
- Posts: 3
- Joined: January 27th, 2015, 6:33 am
Re: Visual Basic development
Haboustak, would it be possible for you to supply those import lines? I am asking because I have what I think SHOULD work but I am getting:
"An unhandled exception of type 'System.AccessViolationException' occurred in DLLTest.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt"
as an error when I try to do anything but initialise the dll.
If possible could you also point me in the right direction as to the wrapper dll as I am willing to try that but am feeling very lost atm.
"An unhandled exception of type 'System.AccessViolationException' occurred in DLLTest.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt"
as an error when I try to do anything but initialise the dll.
If possible could you also point me in the right direction as to the wrapper dll as I am willing to try that but am feeling very lost atm.
Re: Visual Basic development
Look at the date on the previous post. This thread has been dead for almost 9 years.
Bob S.
Bob S.
-
- Paddler
- Posts: 5
- Joined: December 7th, 2014, 8:02 pm
- Location: Sammamish, WA or Reading, UK
- Contact:
Re: Visual Basic development
Make sure you are handling byref and byval parameters correctly. My suspicion is that, because the example you were given was a byval parameter, then you may have declared all of them byval. Return parameters need to be implicitly (e.g an array) or explicitly (e.g. a ushort) declared as byref.
Here is a C# example of parameter that are implicitly byref (rsp_data) or need to be declared explicitly byref (rsp_data_size).
They also have marshalling attributes ([in] [out], etc) for explicit byref parameters.
I don't know enough about VB to help you with those language specifics but hopefully the C# will help get you on the right path.
Here is a C# example of parameter that are implicitly byref (rsp_data) or need to be declared explicitly byref (rsp_data_size).
They also have marshalling attributes ([in] [out], etc) for explicit byref parameters.
I don't know enough about VB to help you with those language specifics but hopefully the C# will help get you on the right path.
Code: Select all
[DllImport("ExternalDlls\\PM3CsafeCP.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?tkcmdsetCSAFE_command@@YAFGGQAKPAG0@Z")]
public static extern ushort tkcmdsetCSAFE_command(
[In] ushort unit_address,
[In] ushort cmd_data_size,
[In] uint[] cmd_data,
[In, Out] ref ushort rsp_data_size,
[In] uint[] rsp_data);
- Citroen
- SpamTeam
- Posts: 8059
- Joined: March 16th, 2006, 3:28 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Visual Basic development
And Mike hasn't logged in since 2013.Bob S. wrote:Look at the date on the previous post. This thread has been dead for almost 9 years.
Bob S.
-
- Paddler
- Posts: 3
- Joined: January 27th, 2015, 6:33 am
Re: Visual Basic development
Sorry for the late reply. Thank you very much MarkD, the ByRef ByVal parameters were the issue! I know the post (and the forum really) had been dead for a long time but I was in need of the help!