Pergunta

I just got a third party source code and it is basically a wrapper project of another c++ library:

I see the code like following in that:

[DllImport("QMSL_MSVC10D.dll", SetLastError = true, CallingConvention=CallingConvention.Cdecl)]
        static extern byte QLIB_SendSync( uint hResourceContext, 
                short requestSize,
                byte [] requestBytes,
                ref short responseSize,
                byte [] responseBytes,
                ulong timeout       
                );

The funny thing is that I do not see "QMSL_MSVC10D.dll" in the references folder. They said it is dynamically loaded but I do not see QMSL_MSVC10D.dll in any of the folder or in the references list. When i debug the code it errors out with the error:

Unable to load DLL 'QMSL_MSVC10D.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

When I told them that this is what is happening, they told me that it is dynamically loaded. Am I missing anything?

Foi útil?

Solução

The references listing just contains other .NET assemblies your program references and uses or COM objects, but any unmanaged code that you call though DllImport is never listed there. As the vendor says, it's dynamically loaded on demand and don't implies a compile-time reference, that's why you don't see there.

But, that don't means that you don't need the .DLL itself at runtime. The file must be accessible at the moment your program makes the first call on the P/Invoke'd function. Look where you got the source, they must supply that third party library with it (otherwise the code is useless). A typical practice is to put DLLs together with the main .EXE so the system can easily locate them.

If you add the DLL to the project (not as a reference, but as an "existing file"), you can set its Copy to output directory to Copy always so that you always have it available on compilation.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top