I'm trying to compile C++ code as managed dll. I was able to compile it using this compiler and linker options:
Compiler:
/TP /analyze- /W3 /Zc:wchar_t /Zi /Od /sdl- /Fd"Debug\vc140.pdb" /Zc:inline /fp:precise /D "_SCL_SECURE_NO_WARNINGS" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Oy- /clr:pure /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /MDd /Fa"Debug\" /nologo /Zl /Fo"Debug\" /Fp"Debug\aaa.pch"
Linker:
/OUT:"C:\Out\x86\Debug\aaa.dll" /MANIFEST /NXCOMPAT /PDB:"C:\aaa.pdb" /DYNAMICBASE "ucrtd.lib" "vcruntimed.lib" "libvcruntimed.lib" "msvcurtd.lib" "msvcrtd.lib" "libcmtd.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /FIXED:NO /DEBUG /DLL /CLRIMAGETYPE:PURE /INCREMENTAL:NO /PGD:"C:\Out\x86\Debug\aaa.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\aaa.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /ASSEMBLYDEBUG /TLBID:1
The problem I have is really strange. I have a pure abstract base class and a derived class in that dll. When I create an instance of that derived class with new, I can see that it's vtable is filled with zeros.
So I can't call any virtual function.
I couldn't recreate this issue with dummy console application, so I have no idea, what can be the reason of this. As far as I see from dummy application, there is no calls to crt or some obscure library to fill vtable with correct addresses, there is just a couple of assembly lines.
UPDATE:
The problem in the code looks like this:
class Connector : public IConnector
{
public:
Connector() : m_a(0), m_b(0)
{}
<...>
};
<...>
Connector * pc = new Connector();
Connector c;
IConnector has default ctor and no fields, so it does nothing.
In the watch window I can see that vtable pointers in pc and c are set to something nonzero and they are the same. But the place they point to is filled with zeros.
IMHO it doesn't look like vtable pointer is broken, it looks like vtable itself is not initialized.