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(dllexport) cannot be used with /clr:pure
or /clr:safe
Error 225 error C4394: 'ErrorHandler::instance' : per-appdomain symbol
should not be marked with __declspec(dllexport)
Error 226 error C4394: 'private: static ErrorHandler *
ErrorHandler::instance' : per-appdomain symbol should not be marked with
__declspec(dllexport)
Error 228 error C3395: 'ErrorHandler::GetInstance' : __declspec(dllexport)
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<FormDebugOutput^> formDebugOutput;
public:
static ErrorHandler* GetInstance()
{
if (instance == NULL)
{
instance = new ErrorHandler();
_onexit(destroyInstance); // A _onexit function is called when the
process exits normally.
}
return instance;
}
void PrintMessage(char* Source, char* Message)
{
if (!formDebugOutput)
{
formDebugOutput->PrintMessage((signed char*)Source, (signed char*)Message);
}
}
void SetDebugForm(gcroot<FormDebugOutput^> FormDebugOutput)
{
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.Form.
Marcus Heege - 13 May 2007 21:06 GMT
The problem is that you are compiling with /clr:pure, which does not support
exporting functions.
If you compile with /clr:pure, you can not define functions with native
calling conventions. Only functions with the managed calling convention
__clrcall can be defined. This means that only managed code can invoke a
function compiled with /clr. To export a function, a native calling
convention is necessary.
Instead of /clr:pure, you should compile with /clr.
HTH
Marcus
> Hello,
>
[quoted text clipped - 85 lines]
>
> FormDebugOutput is a form in a C#-DLL derived from Windows.Forms.Form.