Zuccj
06-26-2017, 07:06 AM
I'm trying to use a function from a dll that will open a file. The issue I'm having is I can't quite figure out how to correctly pass the file location information to the dll, as it is expecting the Char type. I've tried passing the data as a byte and string array, but neither one has worked so far.
The dll list the function as:
unsigned long NQ_LoadParams (unsigned long ulNQHandle, char*pcFilename)
I'm calling it like this:
Private Declare Function NQ_LoadParams Lib "C:\....dll" (ByVal ulNQHandle As Long, _
ByRef pcFilename() As String) As NQ_ErrorEnum
Sub LoadFile_Click()
Dim fopen As FileDialog
Dim fcontent As String
Dim textfile As Integer
Dim holder As String
Dim addr() As String
'Sets up File Location to File Location
Set fopen = Application.FileDialog(msoFileDialogOpen)
fopen.Title = "Select Config File"
fopen.InitialFileName = "C:\..."
fopen.Show
'Takes the file Selected and Stores its location
holder = fopen.SelectedItems(1)
ReDim addr(Len(holder) - 1)
For i = 1 To Len(holder)
addr(i - 1) = Mid(holder, i, 1)
Next
'Opens the files location
textfile = FreeFile
Open holder For Input As #textfile
'Stores file's content after it has been opened
fcontent = Input(LOF(textfile), textfile)
'Closes File
Close #textfile
ulNQError = NQ_LoadParams(ulNQHandle, addr)
End Sub
When I tried the byte array I used the StrConv() function.
I know addr has the correct information. I'm just not sure what format it needs to be, or what needs to be done in able to pass it to the dll correctly.
Also, I've tried looking around real quick for an answer on this, but I was wondering are VBA strings naturally null terminated? I was thinking could be a possible cause for error, but I would imagine that it null terminates them.
The dll list the function as:
unsigned long NQ_LoadParams (unsigned long ulNQHandle, char*pcFilename)
I'm calling it like this:
Private Declare Function NQ_LoadParams Lib "C:\....dll" (ByVal ulNQHandle As Long, _
ByRef pcFilename() As String) As NQ_ErrorEnum
Sub LoadFile_Click()
Dim fopen As FileDialog
Dim fcontent As String
Dim textfile As Integer
Dim holder As String
Dim addr() As String
'Sets up File Location to File Location
Set fopen = Application.FileDialog(msoFileDialogOpen)
fopen.Title = "Select Config File"
fopen.InitialFileName = "C:\..."
fopen.Show
'Takes the file Selected and Stores its location
holder = fopen.SelectedItems(1)
ReDim addr(Len(holder) - 1)
For i = 1 To Len(holder)
addr(i - 1) = Mid(holder, i, 1)
Next
'Opens the files location
textfile = FreeFile
Open holder For Input As #textfile
'Stores file's content after it has been opened
fcontent = Input(LOF(textfile), textfile)
'Closes File
Close #textfile
ulNQError = NQ_LoadParams(ulNQHandle, addr)
End Sub
When I tried the byte array I used the StrConv() function.
I know addr has the correct information. I'm just not sure what format it needs to be, or what needs to be done in able to pass it to the dll correctly.
Also, I've tried looking around real quick for an answer on this, but I was wondering are VBA strings naturally null terminated? I was thinking could be a possible cause for error, but I would imagine that it null terminates them.