Singleton in native library with C++/CLI

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Hi,
I have a large unmanaged static C++ library which I've wrapped using a small
C++/CLR DLL. This is called from a C# client application.

The static library has a singleton, however it appears that it is being
instantiated twice. The first instantiation is down to me calling
singleton.instance() in the C++/CLR DLL, the second instantiation is down to
the library internally calling singleton.instance().

I'm relatively new to C++/CLR, is this expected behaviour and is there
anything I can do to work around this?

Thanks,
Adrian
 
Adrian said:
Hi,
I have a large unmanaged static C++ library which I've wrapped using a small
C++/CLR DLL. This is called from a C# client application.

The static library has a singleton, however it appears that it is being
instantiated twice. The first instantiation is down to me calling
singleton.instance() in the C++/CLR DLL, the second instantiation is down to
the library internally calling singleton.instance().

I'm relatively new to C++/CLR, is this expected behaviour and is there
anything I can do to work around this?

I've just converted a small DLL from C++Builder to a C++/CLI DLL in
vs2005 that uses singletons with no real problems. It isn't
instantiated twice for me. The only issue I had was with cleanup. To
destroy the singleton we use std::atexit to register a cleanup func but
in C++/CLI, you have to call _onexit_m (found this because of crashes at
shutdown).

Cheers

Russell
 
Please forget my previous message that I sent yesterday. It's not that
it's not correct, but it doesn't show your real problem. Your real problem
is explained in this message.

Excellent - thank you very much for this post - it explains my problem
exactly.

Thanks again.
 
Back
Top