How to get some fields directly from windows DLL (dynamic link library) into Ms Access Project (1 Viewer)

nector

Member
Local time
Today, 11:32
Joined
Jan 21, 2020
Messages
368
Hello!

I want to get some parameters directly from windows as per file described library below into VBA in order for me to convert it into Json format:

The fiscal code library is used for generate Fiscal code that should be printed on Invoices. It is a DLL (dynamic link library) that can be install in windows IDE and import by programming language C/C++/C#. There is only one method in this library as follows:

If I was to use C++ , then the function should be as below to get the parameters:

C++:
IntGetFiscalCode(c har *TPIN, char *code, char *number, char *date, char *terminalID, char * amount, char *fiscalCode, char *int keyLen);


I have tried to convert the above code to VBA so that the above listed parameters can be called from MS Access project and below is my replica function of C++ to VBA

Code:
Public Function IntGetFiscalCode(ByVal TPIN As String, ByVal code As String, ByVal number As String, ByVal date As String, ByVal terminalID As String, ByVal amount As String, ByVal fiscalCode As String, ByVal intKeyLen As Integer) As Integer
End Function

Requirements

I want to include all parameters (TPIN, code, number, date, terminalID, amount, fiscalCode, int keyLen) in the VBA Json code below so that I make one string and then send to the internet to the server. How do I call the above parameters in the VBA Json format below? Here are the parameters (TPIN, code, number, date, terminalID, amount, fiscalCode, int keyLen)

Below is my VBA Json converter

Code:
'Arranging parameters in Json format
Private Sub CmdNewJsons_Click()
Dim Businessdata As New Dictionary
Dim Main As New Dictionary
Dim Content As New Dictionary
Dim Report As New Dictionary
Set Businessdata = New Dictionary
Set Report = New Dictionary
Set Main = New Dictionary
Set Content = New Dictionary
With Content
.Add "Message", Businessdata
Businessdata.Add "Body", Main
Main.Add "data", Report
  Report.Add "device", "531030026147"
  Report.Add "serial", "00000"
  Report.Add "bus_id", "Invoice - App - A"
  Report.Add "Sign", "YYY"
  Report.Add "key", "KKK"
  Report.Add "ComputerKey", GetPCSerialNumber()
End With


Dim member As Variant
    For Each member In Content
    
    Next
MsgBox JsonConverter.ConvertToJson(Content, Whitespace:=3), vbOKOnly, "Audited by Chris Hankwembo"

End Sub


If you check below I used also a similar code to get the computer serial number to be part of my Json code and its working ok see below the code and the final screen shoot results


Code:
'Getting the computer serial number
Public Function GetPCSerialNumber()
Dim objWMIService As Object
Dim colItems As Variant
Dim objItem
Dim strMsg As String
Set objWMIService = GetObject("winmgmts://./root/cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS Where PrimaryBIOS = true", , 48)
For Each objItem In colItems
  strMsg = objItem.SerialNumber
  Next
  GetPCSerialNumber = strMsg
End Function



Computer Keys.png
 
Last edited:

sonic8

AWF VIP
Local time
Today, 10:32
Joined
Oct 27, 2015
Messages
998
I have a hard time understanding what your actual question or problem is.

Do you want to call the C(++) function from the library in VBA? If yes, what about your recent success with using the WinSock API from VBA? While doing that, you should have learned the mechanics of calling C(++)-DLL functions from VBA. Applying your learned experience to this case should take you further than you currently appear to be with that.

BTW: An int data type in C is an Int32, which translates to the Long data type in VBA.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 18:32
Joined
Jan 20, 2009
Messages
12,852
DLLs are compiled so it doesn't really much matter so much what language they are written in. They have "entry points" which expose their functions to other applications. Their performance can be far superior to functions written in VBA because they are compiled.

Register the DLL using regsvr32 to make it available to Windows.
Include the library in the VBA References.
Then Declare the library in a VBA Module and use the function in the definition of a VBA function.
You just need to understand the translation of the parameter datatypes.


There is a bit of a learning curve involved to get started but it is not that difficult for a VBA developer to write a DLL in VB.NET using Visual Studio.
 

Users who are viewing this thread

Top Bottom