April 26, 2024, 11:39:08 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Using IWbasic dll with VB.NET

Started by dabil, September 01, 2017, 05:44:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dabil

I am trying to use a dll originally written in IWbasic with VB.net or c# and don't understand how to properly construct the DLLImport sections for each of the calls.  Is there any documentation that will help?  I am trying to use the AIM_dll_863 for the AIM 4170.
dabil

Brian

September 01, 2017, 06:18:18 AM #1 Last Edit: September 01, 2017, 07:47:04 AM by Brian Pugh
Don't understand. How can a DLL be written in IWBasic WITH VB.net OR c# ?
Brian

I see now. The DLL was wriiten in IWB and you are wanting to use it with vb net or c#
What is the name of the Dll?

Andy

You would need to understand the IWB variable types to begin with.

I.E. Strings, Istrings, Char, Int, Uint, Int32, and Uint64 etc, and which type of IWB variable relates to VB or C equivalent.

That must be the starting point for you.



Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Dabil,

The attached zip file may help you, possibly

Brian

fasecero

This may give you something to start with. Please make sure to copy the DLL to the same folder that contains the vb executable, and compile the app for x86.


EXPORT Add
EXPORT Message
EXPORT GetExePath
EXPORT StructDoSomething

' Integer
SUB Add( INT a, INT b), INT
RETURN a+b
ENDSUB

' string
SUB Message(string text)
MESSAGEBOX(0, text, "Message from DLL", @MB_OK)
ENDSUB

' return a string
SUB GetExePath(string buffer)
buffer = GETSTARTPATH()
ENDSUB

' fixed struct
TYPE MYSTRUCT
    INT a
INT b
INT aplusb
    ISTRING ExePath[500]
ENDTYPE

SUB StructDoSomething(MYSTRUCT st)
' do something with st
st.aplusb = st.a + st.b
st.ExePath = GETSTARTPATH()
ENDSUB



Imports System.Runtime.InteropServices

Public Class Form1

    Declare Function Add Lib "mydll.dll" (ByVal a As Integer, ByVal b As Integer) As Integer
    Declare Sub Message Lib "mydll.dll" (ByVal text As String)
    Declare Sub GetExePath Lib "mydll.dll" (<Out()> ByVal buffer As System.Text.StringBuilder)

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>
    Public Structure MYSTRUCT
        <MarshalAs(UnmanagedType.U4)> Public a As Integer
        <MarshalAs(UnmanagedType.U4)> Public b As Integer
        <MarshalAs(UnmanagedType.U4)> Public aplusb As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=500)> Public ExePath As String
    End Structure

    Declare Sub StructDoSomething Lib "mydll.dll" (ByRef st As MYSTRUCT)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Integer
        Dim value As Integer = Add(3, 5)
        MessageBox.Show(Me, value.ToString, "Add")

        ' string
        Dim text As String = "hello world"
        Message(text)

        ' get string from DLL
        Dim sb As New System.Text.StringBuilder(500)
        GetExePath(sb)
        MessageBox.Show(Me, sb.ToString, "ExePath")

        ' fixed struct
        Dim st As New MYSTRUCT
        st.a = 3
        st.b = 5
        StructDoSomething(st)
        MessageBox.Show(Me, st.aplusb.ToString, "Struct - Add")
        MessageBox.Show(Me, st.ExePath, "Struct - ExePath")
    End Sub
End Class

dabil

 :) Thank all of you for your help.  I will try your suggestions.  I am trying to get the AIM_DLL_863 drivers to work with c#.  I'll let you know how I make out.
dabil

dabil

Here is the IWBasic DLL interface code that works.  Can some one give me the C# or VB equivalent? 

declare  "AIM_863_DLL",AIM_InitVars(flag:int),int
declare  "AIM_863_DLL",AIM_CommPort(flag:int,port:int, baud:int),int
declare  "AIM_863_DLL",AIM_ScanPoint(flag:int,freq_ : double,  Rss:double byref, Xss:double byref),int         
declare  "AIM_863_DLL",AIM_AvgReadings(avg : int),int
declare  "AIM_863_DLL",AIM_LoadCalFile(_str : string),int
declare  "AIM_863_DLL",AIM_ProgRelay(flag: int),int  : ' flag = 1 => close relay,  0 => open relay
declare  "AIM_863_DLL",AIM_GetVersion(flag:int),string
declare  "AIM_863_DLL",AIM_GetSerialNum(flag:int),int
declare  "AIM_863_DLL",AIM_GetRFVoltage(flag:int),double
declare  "AIM_863_DLL",AIM_Sync(flag:int),int  : ' 1 or 2=enable,  0=disable sync output



dabil

Brian

Dabil,

Where can you download this DLL? If you can't, could you post it here? You would probably have to zip it

Can't say I have ever heard of it in connection with IBasic over the years I have been a member

Brian

Brian

Dabil,

This is my best shot at converting your declares to VB. If they don't work, don't come running, as I am not a VB expert, but it should give you a start:

Declare Function AIM_InitVars Lib "AIM_863_DLL" (By Val flag As Long) As Long
Declare Function AIM_CommPort Lib "AIM_863_DLL" (By Val flag As Long, By Val port As Long, By Val baud As Long) As Long
Declare Function AIM_ScanPoint Lib "AIM_863_DLL" (By Val flag As Long, By Val freq_ As Double, By Val Rss As Double, By Val Xss As Double) As Long
Declare Function AIM_AvgReadings Lib "AIM_863_DLL" (By Val avg As Long) As Long
Declare Function AIM_LoadCalFile Lib "AIM_863_DLL" (By Val _str As String) As Long
Declare Function AIM_ProgRelay Lib "AIM_863_DLL" (By Val flag As Long) As Long 'flag = 1 => close relay, 0 => open relay
Declare Function AIM_GetVersion Lib "AIM_863_DLL" (By Val flag As Long) As String
Declare Function AIM_GetSerialNum Lib "AIM_863_DLL" (By Val flag As Long) As Long
Declare Function AIM_GetRFVoltage Lib "AIM_863_DLL" (By Val flag As Long) As Double
Declare Function AIM_Sync Lib "AIM_863_DLL" (By Val flag As Long) As Long '1 or 2=enable, 0=disable sync output

Note that the DLL has to be in the same folder as your program. If it is in a different place, you need to put the full path in the declare, as in this example: Declare Function AIM_AvgReadings Lib "c:\my folder\AIM_863_DLL" (By Val avg As Long) As Long

You could always look at this page for some more help:
https://msdn.microsoft.com/en-us/library/aa716201(v=vs.60).aspx

Best of luck,

Brian

Egil

October 25, 2017, 04:40:23 AM #9 Last Edit: October 25, 2017, 06:39:42 AM by Egil
There have been a lot of questions similar to this on several other forums lately, all about how to use the DLLs that comes with the AIM Antenna Analyzers.
Most questions about these analyzers will probably be answered here: http://aim4150.proboards.com/board/1/antenna-analyzer-forum

You can most probably get help from the supplier: https://www.arraysolutions.com
I beleive that the software that comes with these devices are propriatary, but if you have obtained a license this should not cause problems.

Lots of information on these analyzers can be found on W5BIG's website: http://www.w5big.com


Good luck!
Egil - LA2PJ
Support Amateur Radio  -  Have a ham  for dinner!

Brian

Egil,

I had a quick search of the 'net this morning, and I couldn't find anything given the name of the DLL he mentioned, so I just did the conversions to the best of my ability. He is not very forthcoming with info, and I somehow can't believe it was ever written with an IW product

Let's hope your information will help him somewhat

Brian

Egil

QuoteLet's hope your information will help him somewhat

I hope so too Brian.
A friend of mine owns one of these small wonders, and on his specimen the web adress to the manufacturer is printed on a label on the back of the instrument. He is serving in Afganistan at the moment, but this morning he mailed me the link to the forum posted above.
He said he has a CD containing several AIM related programs and DLLs, but he is unable to find it until he is back in Norway some time next year.


Egil
Support Amateur Radio  -  Have a ham  for dinner!

dabil

If you go to this page

http://www.w5big.com/prog_update.htm
and download the AIM_910A software the 863 dll will be included in the zip.

You really need to device to tell if the software is working.  I can get the dll to work with IWbasic, but not C# or VB.
dabil

Brian

Have you tried my conversions at all?

Brian

Egil

QuoteI can get the dll to work with IWbasic, but not C# or VB.

That is probably because calls to the DLL functions need to be declared in a different format than that used with IWB.
Usually the helpfile for any coding language describe how to declare such calls. If not, I advise you to try posting your questions on a C# or VB users forum.
Sorry I can't be more specific, but I'm not familiar with any of the two languages.

But if you have coded a working example for interfacing the AIM analyzers, there are numerous radio enthusiasts (including me) on this forum that will love to see what you've done.


Good luck!
Egil
Support Amateur Radio  -  Have a ham  for dinner!

Brian

Which begs the question: If it works with IWB, why does he need to have it working with C or VB, with all the bloat that they bring?

Brian

Egil

October 25, 2017, 07:52:22 AM #16 Last Edit: October 25, 2017, 07:55:53 AM by Egil
I just downloaded the mentioned software, and to my surprise I found several pieces of EB code, showing how to use the DLL.


Dabil:
Have you seen the AIM_Software_Guide_121212 .pdf?
On page 6 there is a warning for users that use NET runtimes, with a suggestion on how to get rid of errors. Maybe that fix also can be of help for you?


Egil
Support Amateur Radio  -  Have a ham  for dinner!

Egil

Quote from: Brian Pugh on October 25, 2017, 07:46:36 AM
Which begs the question: If it works with IWB, why does he need to have it working with C or VB, with all the bloat that they bring?

Brian

Good question, but maybe he feels more comfortable with that languages. In addition some schools only accept coding projects made with one of them.


Egil
Support Amateur Radio  -  Have a ham  for dinner!

Brian

I'll download it tonight and have a look when I get home. I think I read somewhere that you can run it in demo mode if you have not got the device/hardware
Brian

dabil

I tried your conversion.

It is about what I came up with. 

These calls below function but get an error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at WindowsFormsApplication1.Form1.AIM_GetSerialNum(Int32 flag)"

        [DllImport("@AIM_863_DLL.dll", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.I4)]
        public static extern int AIM_InitVars([MarshalAs(UnmanagedType.I4)] int flag);

        [DllImport(@"AIM_863_DLL.dll", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.I4)]
        public static extern int AIM_CommPort([MarshalAs(UnmanagedType.I4)] int flag, [MarshalAs(UnmanagedType.I4)] int port, [MarshalAs(UnmanagedType.I4)] int baud);

        [DllImport(@"AIM_863_DLL.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern string AIM_GetVersion([MarshalAs(UnmanagedType.I4)] int flag);

        [DllImport(@"AIM_863_DLL.dll", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.I4)]
        public static extern int AIM_GetSerialNum([MarshalAs(UnmanagedType.I4)] int flag);


The reason I am trying to integrate with Visual Studio as I have a program written that allows other analyzer to be used.  I am trying to integrate a 4170 as just another selection.
dabil

Brian

I downloaded the package, and converted the EBA file to IWB format - not a lot to do, really

And I generated a .lib file from the DLL with IWBasic. That's in the zip along with the DLL and .iwb file

As I said before, I am not an expert at all with Visual Studio or C, so that is the end of the trail for me

Brian

fasecero

October 25, 2017, 01:35:29 PM #21 Last Edit: October 25, 2017, 03:16:27 PM by fasecero
I think we could help you better if you make a small functional sample in IWB and its equivalent not-working .NET and upload it in a zip. Maybe someone can have a better perspective of what may be happening by watching the actual code.

Edit: Sorry, this was actually a bad idea that is probably breaking a forum rule.

Brian

Fasecero,

I'm quite willing to help someone if I have the time, and the brains, but this is a forum for IWBasic programming, and Dabil should really be asking for help on the appropriate sites, not here. I've exhausted what I can do now - I don't know anything about Visual Studio or C#

Brian

fasecero

Oh. I didn't realize about that, thank you for pointing it out. I have edited my last post.

Brian

October 27, 2017, 03:18:20 AM #24 Last Edit: October 27, 2017, 05:06:56 AM by Brian Pugh
Dabil,

Keep checking this forum item: http://aim4150.proboards.com/thread/528/aim-dll

I have had a request put on this forum for information about interfacing the DLL with C# for you. It was only put on last night, so be patient!

I noticed that there were a couple of exports in the DLL that you haven't got defined. The export names are correct, but it is a guess to what they actually call:

DECLARE "AIM_863_DLL",AIM_ConstantFreq(flag:int),int
DECLARE "AIM_863_DLL",AIM_GetTemperature(flag:int),int

Brian