Access violation in MFC dll (loadlibrary) loaded in C++/CLI Wrapper - dll

I'm loading a MFC dll to my CLI wrapper with
HINSTANCE m_keyManagerLib;
m_keyManagerLib = LoadLibrary("dll");
in destr:
FreeLibrary(m_keyManagerLib);
When I load the dll again I get some access violation errors:
First-chance exception at 0x76fdc518 in TestKeyManagerApp.exe: 0xC0000005: Access violation reading location 0xfffffff8.
First-chance exception at 0x75219673 in TestKeyManagerApp.exe: Microsoft C++ exception: CMemoryException at memory location 0x0030e1cc..
'TestKeyManagerApp.exe': Unloaded 'C:\projects\KeyManagerServer\TestKeyManagerApp\bin\Debug\dll\KeyManagerServerD.dll'
additional infos:
load the CLI wrapper into C# program and started there
MFC dll
Use MFC in a Shared DLL
referenced to: Access violation in MFC dll (wrapped in C++/CLI) started from C# program
Thank you in advance for your help!
greets leon22

Related

InteropServices.COMException - Class not registered

I'm having some problems in using a type that comes from an old unmanaged DLL.
gobjDPProject = New DP_Store_21.cProject
When I make this assignment an exception is threw
A first chance exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Retrieving the COM class factory for component with
CLSID {98214FEB-FE5C-495F-A926-F23DC62EEDD6} failed due to the following
error: 80040154 Class not registered (Exception from HRESULT: 0x80040154
(REGDB_E_CLASSNOTREG)).
To check the existence of this class I went to Regedit and found the component with the CLSID reported by the Exception, it exists and under the ProgID subFolder I can see the DP_Store_21.CProject class.
Inside Visual Studio -> My Project -> References I can navigate inside the DP_Store_21 DLL (it's an Interop) and the CProject class is there.
Run regsvr32 /pathTo DP_Store_21.dll gives no problems and the other classes of the library are correctly instantiated, what I am missing ?

Retrieving the COM class factory for component with CLSID {XX} failed due to the following error: 80004005 Unspecified error

I am working on VB.NET WinForm Application ( 32 bit) which references third party COM dll (32 bit). My Target Platform points to x86. I registered the dll using command prompt as administrator. However while creating the instance of dll it intermittently not able to create it and I get the following COM exception:
Retrieving the COM class factory for component with CLSID
{0CBDC6C1-3D1E-4CEB-A89E-5D081985E874} failed due to the following
error: 80004005 Unspecified error (Exception from HRESULT: 0x80004005
(E_FAIL)).
Can anyone help me with this, please?

Getting errors in registering the COM DLL

when i was trying to register my own com dll it is giving me error as
"The module ClassLibrary was loaded but entry point dllregister server was not found.

Debug assertion failed error when passing std::string from c++/cli dll to native win32 dll

I have a C# form calling to a c++/cli interface DLL, which calls off to a win32 native c++ dll. Originally this was written in VS2010, and was working - I was able to marshal a System::String to a std::string, pass it to the native dll, and cout the value. I then converted the C# and c++/cli projects to VS2012 to enable intellisense. This required a service pack install to reenable the 4.0 .NET framework in VS2010. I rebuilt the Win32 dll in 2010, the C# app and c++/cli dll in VS2012, and now I receive an error on the call to the dll:
Debug Assertion Failed!
Program:
...
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c
Line: 1424
Expression: _pFirstBlock == pHead
public ref class ManagedWrapper
{
CSampleWin32Library* m_pUnmanagedWrapper;
public:
ManagedWrapper() {m_pUnmanagedWrapper = new CSampleWin32Library();}
~ManagedWrapper() {delete m_pUnmanagedWrapper;}
//Test call to prove integration
void Test(int x, System::String^ testString) {
//marshaling example: http://msdn.microsoft.com/en-us/library/bb384865.aspx
std::string tmpStdString = marshal_as<std::string>(testString);
m_pGambitUnmanagedWrapper->Test(x, tmpStdString); //ERROR OCCURS HERE
};
};
Hopefully this is as easy as some setting that was lost, or is now required in VS2012. I didn't change any code otherwise, as far as I know.
This error mostly is because of that a block of memory which you malloc in Heap A is freed in Heap B.
You should have a look at Windows Via C/C++--Part IV Dynamic-Link Libraries.
The application will call CRT when it's running.
There two ways to invoke CRT--link to the DLL C/C++ run-time library or link to the static C/C++ run-time library and there different versions of CRT.
All of them use different Memory Management.
So, you should be careful when you free the memory and your code linked to DLL.

Upgrading App from .NET 3.5 to 4.0, COM fails now

I have an application that I am upgrading from the .NET 3.5 to the .NET 4.0 framework. It uses a COM library which is referenced. It works no problem in 3.5 but after converting to 4.0 I have issues getting the COM to work. The COM is from a 3rd party so we didn't develop it ourselves.
I get the following COM error (generic COM error, not specific to the COM object itself): hr = 0x8007000b
CLR gives me: 'The invocation of the constructor on type 'Skype_Business_Launcher.Main' that matches the specified binding constraints threw an exception.' Line number '3' and line position '5'.
And the C# logs:
=== Pre-bind state information ===
LOG: User = \phillip
LOG: DisplayName = Interop.SKYPE4COMLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Skype Business Launcher, Version=1.0.5.0, Culture=neutral, PublicKeyToken=null.
LOG: This bind starts in default load context.
LOG: Using application configuration file:
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///bin/Debug/Interop.SKYPE4COMLib.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
I removed the pathname for security reasons but I have checked all the path information and it's all correct. Also the COM library file exists where it's pointing to. It's also copied to the OBJ folder within the project as well.
Originally I was getting an error about the COM library not supporting embedded types so I made "Embed Interop Types" false (it was true below) and the error went away but I'm not sure if thats connected to this error or not so I thought I'd mention it just in case.
Again, it works just fine with 3.5.
Thanks,
A shot in the dark: it looks like you are using the x64 version of the framework. Was that already the case with 3.5 ? And is the COM server a DLL or an EXE ?
If the COM server is a DLL, there needs to be a "bitness" match between the DLL and your program.
when you convert your project to 4.0 the IDE can perform a issue to convert COM library into 4.0.
when you convert your project to 4.0 remove com library then Re include it in your project then i thing it should be works.