Use VBA to Call DLL and process parameters of the [char *] type in C Language

Source: Internet
Author: User

DLL export Function Definition

---------------------------------------------------

_ Declspec (dllexport) int _ stdcall MyExportFunction (const char * p1, const char * p2, char * const out );

VBA processing (similar to VB.net processing)

Note that the [char *] type in C is equivalent to [ByRef aa As Byte] in VBA (or VB. NET ].

---------------------------------------------------

Private Declare Function fnc Lib "DLL path \ DLL name. dll "_

Alias "function name" (ByRef p1 As Byte, ByRef p2 As Byte, ByRef out As Byte) As Integer

 

Sub Test ()

Dim pUserID () As Byte

'String conversion to Byte array

Call ToBytes ("999999900", pUserID)

Dim pYYMMDD () As Byte
Call ToBytes ("091020", pYYMMDD)

Dim pPWD (50) As Byte

 

Aa = fnc (pUserID (0), pYYMMDD (0), pPWD (0 ))

Dim str As String
Str = StrConv (pPWD, vbUnicode)

MsgBox (str)

End Sub

'String conversion to Byte array
Private Sub ToBytes (ByRef src As String, ByRef dst () As Byte)

ReDim dst (Len (src ))

Dim I As Integer
For I = 1 To Len (src)
Dst (I-1) = Asc (Mid (src, I, 1 ))
Next

End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.