How to define a global COM object in VC++8

G

Guest

Hi,

I need define a global COM object in a VC++8 project. But when I compile it,
I get a error message:
error C3145:'ComLibC1': global or static variable may not have managed type
MYCOMLib::Class1^ (MYCOMLib is a COM Wrapper built in VC++6).
My code looks like this:

namespace MyApp
{
(some global variables)
MYCOMLib::Class1^ ComLibC1;
...

public ref class MainForm : public System::Windows::Forms::Form
{
public:
MainForm(void)
{
...


Anybody can help me to solve this problem?


Thanks,

Minfu
 
B

Bruno van Dooren

I need define a global COM object in a VC++8 project. But when I compile
it,
I get a error message:
error C3145:'ComLibC1': global or static variable may not have managed
type
MYCOMLib::Class1^ (MYCOMLib is a COM Wrapper built in VC++6).
My code looks like this:

namespace MyApp
{
(some global variables)
MYCOMLib::Class1^ ComLibC1;
...

public ref class MainForm : public System::Windows::Forms::Form
{
public:
MainForm(void)
{
...


Hi,
If you look at the explanation of C3145, you'll see that this happens if you
define CLR object outside function scope.

Try this:
public ref class MainForm : public System::Windows::Forms::Form
{
private:
static MYCOMLib::Class1^ ComLibC1;

public:
MainForm(void)
{

instead of this
MYCOMLib::Class1^ ComLibC1; //should be in a class scope to aboid C3145

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
G

Guest

Hi Bruno.

Thank you for the advice. But how can I get access the 'global object
ComLibC1 in other classes?

Minfu
 
B

Bruno van Dooren

Hi Bruno.
Thank you for the advice. But how can I get access the 'global object
ComLibC1 in other classes?

Minfu

Hi,

What you can do is to make a class with only some static members like this:

ref class GlobalObjects{
public:
static MYCOMLib::Class1^ ComLibC1;
};

That way you can simply use GlobalObjects::ComLibC1 as a global varible.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 

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