Call DLL in WinForms App Fails But Works In MFC App
-
I have a DLL written in Visual C++ 6.0. I have a MFC test application which calls this DLL and it works fine. I also have a .NET C# WinForms test app which calls this DLL. I am importing the DLL and calling it successfully. I can see that the DLL is called correctly and all parameters are passed successfully. The DLL works for a time and then fails when trying to create a COM component by calling CoCreateInstance. This fails with an Access Violation. This doesn't happen when called from the MFC app. Why does this happen in the .NET app and how do I solve it?
-
I have a DLL written in Visual C++ 6.0. I have a MFC test application which calls this DLL and it works fine. I also have a .NET C# WinForms test app which calls this DLL. I am importing the DLL and calling it successfully. I can see that the DLL is called correctly and all parameters are passed successfully. The DLL works for a time and then fails when trying to create a COM component by calling CoCreateInstance. This fails with an Access Violation. This doesn't happen when called from the MFC app. Why does this happen in the .NET app and how do I solve it?
Could you provide some more detailed information about how you use this from C#? Could you also provide more details about what kind of error you see when trying to use the dll? If my COM-memory is not totally wrong, CoCreateInstance() cannot be called until the calling thread has called CoInitalize(). Could that be your problem?
//daniel