dll call from excell/vba

dll call from excell/vba


Needing some help with excel/vba dll calls. I used the following declare sub and was not sure if the additional records being passed with the BSTR for a string need to be put into the @bytes number? Can someone tell me exactly what bytes number should be specified for this example?

Declare Sub dll_rout Lib "C:dll_rout.dll" _
Alias "_DLL_ROUT@12" (int_arg As Long, ByVal str_in As String, ByVal str_in_len As Long, ByVal str_out As String, ByVal Str_out_len As Long)

Example link below.



5 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

tried it. 20.
I use dumpbin /exports to check it.

There are 5 arguments passed. Each in the size of 4 bytes. Hence , 5x4 = 20.
Adding extra argment inside the dll_rout.dll will yield 24 (6 arguments x 4 bytes).

Thanks Edmund,

I noticed that if I take out the allias attribute in the fortran dll it does not indicate how many bytes are needed.

Have you gotten this example to work?


yes.It worked for me. I even use a cell value as input (see code below). If you want to try it, make sure the cell's property is set to numeric. (note I save the file name as sub1.dll)

Declare Sub DLL_ROUT Lib _
"e:sub1.dll" _
(int_arg As Long, _
ByVal STR_IN As String, _
ByVal STR_IN_LEN As Long, _
ByVal STR_OUT As String, _
ByVal STR_OUT_LEN As Long)

Public Sub Command1_Click()

Dim int_arg As Long
Static STR_IN As String * 10, STR_OUT As String * 20

int_arg = Cells(1, 1).Value

STR_IN = "Testing..."

Rem Pass lengths of string arguments

Call DLL_ROUT(int_arg, STR_IN, Len(STR_IN), STR_OUT, Len(STR_OUT))

MsgBox (STR_OUT)

End Sub

I tried your case by removing the alias attribute. It is interesting to see that from dumpbin /exports, there were two entry points for the subroutines(both fortran/stdcall types). This probably means you don't have to worry about using _alias_at all in your fortran dll. (well, I could be wrong but it works in this example)

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!