473,805 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(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.
May 8 '07 #1
1 6290
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****@discuss ions.microsoft. comwrote in message
news:4F******** *************** ***********@mic rosoft.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(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.
May 13 '07 #2

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

Similar topics

1
2202
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 be accomplished and how. Here's the problem. We have a third party app (TPA) capable of loading native and mixed-mode dlls somehow (we don't know how). It loads our native dll (OND) and allows us to use our code inside the app (that is, we...
18
2357
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
1428
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 hold a static reference to managed classes. 1. In 2003 I needed special initialization because of the loader lock issue. In 2005 it seems I dont need this, however I am calling into a managed dll from a native dll, and I read somewhere there can...
8
12482
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 the /CLR). As soon as I try to specify __declspec(dllexport) (AFX_EXT_CLASS) I get the following compiler error: Error 2 error C3395: 'CWPFControlProxy::OnWPFButtonClick' : __declspec(dllexport) cannot be applied to a function with the...
24
2871
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. MSVCR80.DLL and MSVCR80D.DLL are present and accounted for in Windows\System32. This is something else. Message says that the application configuration is incorrect. I just compiled a simple "Hello.cpp" app that exhibits the same behavior so...
9
2076
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
3653
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 the moment I have a MC++ unit test project which accesses the singleton. What I seem to be finding is that the singleton accessed directly from the unit test project is not the same instance as the singleton accessed from native code.
5
7272
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# application. My question is: Does the performance of the unmanaged pure native C++ class described above is the same if it was a in a pure unmanaged native C++ DLL component?
4
2876
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. I've got a C++/CLI program with a wrapper around some functions in the singleton of the native lib. 3. When I run my program, the wrappers instantiate their own copy of the singleton, i.e.
0
10609
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.