VBA call to managed C++ dll
I am trying to call into managed C++ dll passing the ActiveWorkbook property of the Application object as a parameter. I am receiving the following excpetion:
System.InvalidCastException was unhandled
Message: Unable to cast object of type 'System.__ComObject' to type 'Microsoft.Office.Tools.Excel.Workbook'.
My C++ function is defined as follows:
void
__clrcall ConnectToDatabase(Microsoft:{
}
And my call in VBA is like so:
Private Declare Sub ConnectToDatabase Lib "C:\Documents and Settings\mgarwood\My Documents\Visual Studio 2005\Projects\CalcModuleManaged\Debug\CalcModuleManaged.dll" (ByVal work As Workbook)
Private Sub Workbook_Open()
ConnectToDatabase Application.ActiveWorkbook
End Sub

