dllexport problem on native Singleton in mixed mode dll

G

Guest

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.
 
M

Marcus Heege

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top