How to Create and Send a Data Structure to a DLL?

I am trying to display a message on an LED screen. The SDK for the screen has a DLL that handles on the communications. Which is nice, less programming for me. But the call to the DLL that sends a message has the data structure below as one of the parameters of the call.

Type User_FontSet
strFontName As String
iFontSize As Long
bFontBold As Long
bFontItaic As Long
bFontUnderline As Long
colorFont As Long
iAlignStyle As Long
iVAlignerStyle As Long
iRowSpace As Long
End Type

This is the DLL call:

Public Declare Function User_RealtimeSendText Lib “EQ2008_Dll.dll” (ByVal CardNum As Long, ByVal x As Long, ByVal y As Long, ByVal iWidth As Long, ByVal iHeight As Long, ByVal strText As String, ByRef pFontInfo As User_FontSet) As Boolean

I’ve tried to create a memory block using the following code, but it just crashes when I run it:

Dim fontName as String
Dim Offset As Integer

fontName = “@Arial Unicode MS”

Dim mbUserFontSet as New MemoryBlock((Len(fontName)*2)+2)

Offset = mbUserFontSet.size
mbUserFontSet.Long(Offset+4)=12 'size
mbUserFontSet.Long(Offset+8)=0 'bold
mbUserFontSet.Long(Offset+12)=0 'italic
mbUserFontSet.Long(Offset+16)=0 'underline
mbUserFontSet.Long(Offset+20)=0 'color
mbUserFontSet.Long(Offset+24)=0 'style
mbUserFontSet.Long(Offset+28)=0 'alignment
mbUserFontSet.Long(Offset+32)=1 'row spacing

If app.User_RealtimeSendText(1,0,0,224,32,“Hello”,mbUserFontSet) Then 'call the DLL with the message
MsgBox(“Message Sent”)
MsgBox(“Unable to send message”)
End If

Any suggestions on how to proceed?

Try adding a structure “User_FontSet” to your project. Add all the fields listed above to the structure… I think “strFontName” should likely be added as wstring, the rest can be int32. Then dim your structure and populate it and send that to the dll.

Something like this should be close…

Declare Function User_RealtimeSendText Lib "EQ2008_Dll.dll" (CardNum As int32, x As int32, y As int32, iWidth As int32, iHeight As int32, strText As WString, pFontInfo As User_FontSet) As Boolean

Dim fontName as WString = "@Arial Unicode MS"
Dim myUserFontSet as User_FontSet

myUserFontSet. strFontName=fontName
myUserFontSet. iFontSize =12 'size
myUserFontSet. bFontBold =0 'bold
myUserFontSet. bFontItaic =0 'italic
myUserFontSet. bFontUnderline =0 'underline
myUserFontSet. colorFont =0 'color
myUserFontSet. iAlignStyle =0 'style
myUserFontSet. iVAlignerStyle =0 'alignment
myUserFontSet. iRowSpace =1 'row spacing

If app.User_RealtimeSendText(1,0,0,224,32,"Hello", myUserFontSet) Then 'call the DLL with the message
MsgBox("Message Sent")
MsgBox("Unable to send message")
End If