Witam próbuję napisać w C bibliotekę dll którą mógłbym później wykorzystać w makrze excela.
Udało mi się pobrać wartość zwracaną przez funkcje biblioteki ale nie mogę w żaden sposób przesłać nic do niej.
#define export extern "C" __declspec(dllexport) //zezwala na import funkcji z biblioteki
export int Count() // ta funkcja działa
{
return 7;
}
export int Count2(int i)// ta funkcja nie działa i vba zwraca błąd :bad dll calling convention
{
return i;
}
Kod którym testuje bibliotekę dll:
Declare Function CountDLL Lib "myDLL.dll" () As Integer
Declare Function Count2DLL Lib "myDLL.dll" (ByVal i As Integer) As Integer
Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Sub start()
MsgBox CountDLL()
MsgBox Count2DLL(1)
End Sub
Public Sub askKernel()
Dim strTempPath As String
Dim lngTempPath As Long
strTempPath = String(144, vbNullChar)
lngTempPath = Len(strTempPath)
If (GetTempPath(lngTempPath, strTempPath) > 0) Then
GetTempFolder = Left(strTempPath, InStr(1, strTempPath, vbNullChar) - 1)
Else
GetTempFolder = ""
End If
MsgBox GetTempFolder
End Sub
Gdzie popełniam błąd?
Korzystam ze środowiska CodeBlock i kompilatora MinGW