I have a COM DLL which has been written in C#. I am using the DLL from VBA (MS Access 2010).
Some functions in the DLL contain out
parameters which are not working correctly when used from VBA: VBA gives error "Object reference not set to an instance of an object" when the function is called. All other functions in the DLL class are working correctly.
VBA code:
Dim par0 As String
par0 = "test"
Dim outPar1 As Boolean
Dim outPar2 As myDllNamespace.Foo
Set outPar2 = New myDllNamespace.Foo
Dim outPar3 As String
dllClassInstance.Bar par0 outPar1 outPar2 outPar3
C# COM DLL code (Class for dLLClassInstance):
[ProgId("myDllNamespace.DllTestClass")]
[Guid( ... ),
ClassInterface(ClassInterfaceType.None),
ComDefaultInterface(typeof(IDllTestClass))]
public class DllTestClass : IDllTestClass
{
public void Bar(string filter, out bool success, out Foo entries, out string html) { ... }
}
C# COM DLL interface code (Interface for the class):
[Guid( ... ), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IDllTestClass
{
void Bar(string filter, [Out] out bool success, [Out] out Foo entries, [Out] out string html);
}
Why does VBA throw the "Object reference not set to an instance of an object" error even all the variables have a value and the three last parameters are out parameters anyway?
{ ... }
code. Use the debugger to step through the code or stop when the exception is thrown. Project > Properties > Debug tab > Start external program. – Hans Passant