Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2007

Tip: Looking for answers? Try searching our database.

dllexport problem on native Singleton in mixed mode dll

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fabian - 08 May 2007 14:35 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.