Search code examples
c#dllimportvolume-shadow-service

c# dll import entry point with colons / scope


Looking to dll import from vssapi.dll,

Looking at the GetSnapshotDeviceName function, and DLL export viewer gives me:

protected: long __cdecl CVssWriter::GetSnapshotDeviceName(unsigned short const * __ptr64,unsigned short const * __ptr64 * __ptr64)const __ptr64
protected: long __cdecl CVssJetWriter::GetSnapshotDeviceName(unsigned short const * __ptr64,unsigned short const * __ptr64 * __ptr64)const __ptr64

Assuming I want the first one, how do I declare the dll import, for instance:

[DllImport("vssapi.dll", EntryPoint = "CVssWriter::GetSnapshotDeviceName", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
private static extern uint GetSnapshotDeviceName(string wszOriginalVolume, out string ppwszSnapshotDevice);

[With or without the ExactSpelling] always gives me the

Unable to find an entry point named 'CVssWriter::GetSnapshotDeviceName' in DLL 'vssapi.dll

error. Variations on the colons (removing etc), and reversing the names (as the decorated version) gave me no joy either.

I know it can work using the decorated name or the ordinal, but I'd like the code to be reasonably portable (decls being compiler dependent, and nothing I've ever seen says ordinals will stay the same in updates either).

Yeah I already know with this dll it won't port to pre Vista ... that I can live with.
Also heard about AlphaVSS too - but for what I need would be like using an aircraft carrier to go fishing on a lake (- and did they really need to make it so ungainly to use?)


Solution

  • These are C++ instance methods, that is member functions. As such, they cannot be imported using p/invoke. This API for VSS that you are attempting to use is available either as C++ classes, or via COM.

    If the functionality that you need is available through the COM interface, then that will be the simplest way for you to proceed. Otherwise you will need to wrap the C++ classes one way or another. Surely the simplest way to do that will be with a mixed mode C++/CLI assembly.

    Either way, p/invoke cannot help you here.