Friday, February 24, 2012

Adding Externall DLL functions written in Visual C++

Hi,

I'm trying to add exernal functions defined by a third party in a dll. They developed the dll in Visual C++ and is provided as is, with very little additional info about the code. The dll is tested and can be integrated into an application developed with VB.NET but no other experiences are available. I tried to add the functions to SQL Server 2005 Express edition but on attempting to CREATE the ASSEMBLY i get the following error:

CREATE ASSEMBLY for assembly 'ThirdPartyDll' failed because assembly 'ThirdPartyDll' is malformed or not a pure .NET assembly.

Unverifiable PE Header/native stub.

No rows affected.

(0 row(s) returned)

@.RETURN_VALUE = -6

Finished running [dbo].[ThirdPartyDll].

Is there an alternative way to add these functions for non pure .NET assemblies, or in general, is there a workaround to solve the problem?

By the way, do i need to register the dll with RegSvr32 first?

Thanks,

Marco.

Your third party dll is probably a COM dll.

You will have to use interop to create a .Net wrapper for the com dll. Both the dll's will have to be installed on your server (yes - you'll have to regsvr32 the original dll). When creating the assembly on the database you'll have to specify unsafe so that you may access external code.

It is not very recommended that you call C++ COM dll's from sql's clr...

No comments:

Post a Comment