Hello,
I want to give multiple native classes (in different mixed mode dlls) access
to a managed output window (for error messages). Therefore I wrote a native
singleton with __declspec (dllexport). I get the following compiler errors:
Error 224 error C3389: __declspec(dlle xport) cannot be used with /clr:pure
or /clr:safe
Error 225 error C4394: 'ErrorHandler:: instance' : per-appdomain symbol
should not be marked with __declspec(dlle xport)
Error 226 error C4394: 'private: static ErrorHandler *
ErrorHandler::i nstance' : per-appdomain symbol should not be marked with
__declspec(dlle xport)
Error 228 error C3395: 'ErrorHandler:: GetInstance' : __declspec(dlle xport)
cannot be applied to a function with the __clrcall calling convention
and the same with the other methods of the class. The dll is definitely not
set to /clr:pure or /clr:safe.
I could not reproduce resp. localize the problem with a test program.
I will attach my class below.
Thanks for your help,
Fabian
<SNIP>
#include <stdlib.h>
#include "vcclr.h"
using namespace DebugTools;
#using <System.Windows .Forms.dll>
#pragma once
class __declspec( dllexport ) ErrorHandler
{
private:
static ErrorHandler* instance;
gcroot<FormDebu gOutput^formDeb ugOutput;
public:
static ErrorHandler* GetInstance()
{
if (instance == NULL)
{
instance = new ErrorHandler();
_onexit(destroy Instance); // A _onexit function is called when the
process exits normally.
}
return instance;
}
void PrintMessage(ch ar* Source, char* Message)
{
if (!formDebugOutp ut)
{
formDebugOutput->PrintMessage(( signed char*)Source, (signed char*)Message);
}
}
void SetDebugForm(gc root<FormDebugO utput^FormDebug Output)
{
formDebugOutput = FormDebugOutput ;
}
private:
ErrorHandler()
{
formDebugOutput = nullptr;
}
static int destroyInstance ()
{
delete instance;
instance = NULL;
return 0;
}
};
</SNIP>
FormDebugOutput is a form in a C#-DLL derived from Windows.Forms.F orm.