473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

dllexport problem on native Singleton in mixed mode dll

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^FormDebugOutpu t)
{
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.
May 8 '07 #1
1 6250
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

"Fabian" <Fa****@discussions.microsoft.comwrote in message
news:4F**********************************@microsof t.com...
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^FormDebugOutpu t)
{
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.
May 13 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike Kamzyuk | last post by:
Hello all. Basically, I need to call a mixed-mode dll's function (which uses managed code) from a native or mixed-mode dll function (which does not use managed code). I'm wondering if this could...
18
by: Paul Brun | last post by:
Can this be done? Is there a way to "de-alias" the int datatype so I can pass an int into a C method?? Paul
3
by: Adam | last post by:
I can't seem to find one spot on the net that specifies exactly what I need to do. Situation: Native dll needs to hold a static reference to a managed class in .net 2.0 (whidbey) which needs to...
8
by: bonk | last post by:
Hello, I created a MFC extension dll (using VS 2005 Beta 2) that is supposed to export a class that uses .NET internally (See header below) und later shall be used by a plain MFC Project (without...
24
by: Dave | last post by:
I understand that VS.NET is supposed to compile native Win32 apps that do not require the .Net runtime. If that's the case then there is something else from the VS200x package that is required. ...
9
by: Herby | last post by:
Is possible to have a managed method within a Native(un-managed) class within a \clr project? E.g. class myClass { public: #pragma managed void myMethod(void);
8
by: quortex | last post by:
Hi all, I have a native class which has a single instance controlled via the singleton pattern. I need to call this from both native C++ and from mixed mode visual studio 2005 c++ CLI. At...
5
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I have a class that is writen in unmanaged pure native C++. This class files (h and cpp) are inserted to a managed C++ (VC++ 2005, C++/CLI) DLL compoenet. This DLL compoenet is used in a C#...
4
by: joes.staal | last post by:
Hi, I know this has been asked earlier on, however, none of the other threads where I looked solved the following problem. 1. I've got a native C++ library (lib, not a dll) with a singleton. 2....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.