473,543 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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::Class 1^ (MYCOMLib is a COM Wrapper built in VC++6).
My code looks like this:

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

public ref class MainForm : public System::Windows ::Forms::Form
{
public:
MainForm(void)
{
...
Anybody can help me to solve this problem?
Thanks,

Minfu
Mar 26 '06 #1
4 5737
> 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::Class 1^ (MYCOMLib is a COM Wrapper built in VC++6).
My code looks like this:

namespace MyApp
{
(some global variables)
MYCOMLib::Class 1^ 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::Class 1^ ComLibC1;

public:
MainForm(void)
{

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

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"

Mar 27 '06 #2
Hi Bruno.

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

Minfu
"Bruno van Dooren" wrote:
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::Class 1^ ComLibC1;

public:
MainForm(void)
{

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

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"

Mar 27 '06 #3
> 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::Class 1^ ComLibC1;
};

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

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"

Mar 27 '06 #4
Thanks Bruno. It works.

Minfu
Mar 27 '06 #5

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

Similar topics

12
1981
by: Santiago de Compostela | last post by:
Hi The following program doesn't compile on MS VC++ or Bloodshed Dev-C++ #include <iostream> int strlen(const char *in) {
34
3644
by: Dennis | last post by:
I would like to dynamically allocate in a sub a 2 dimensional Array float *myarray = new float ; of course I get an error. How do you allocate a 2D array using the New operator? I currently use static float gxy;
6
3146
by: Peng Yu | last post by:
I want to define a macro #define FILEWR(FILENAME) which can be expanded to #ifndef OUTFILE #define OUTFILE ofstream out; #endif
5
2371
by: kUfa.scoopex | last post by:
Hi there! I have a small problem, and i really dont see any convenient way to fix it. Basically, i'd like to overload global new operators, into something like this: void *operator new( size_t size ); void *operator new( size_t size, AllocationType allocType ); void *operator new( size_t size, MemoryHandler* memHandler ); void *operator...
6
9187
by: David Young | last post by:
Hello all, I'm quite new to C# (< 6 months) but really love it and is my language of choice ..... but I have one question I've not been able to find out ..... In C++ a #define label in one file can be referanced in other *.cpp files, however in C# if I have say #define SPEED it only refers to the class(es) in that *.cs file. Is there...
3
4188
by: Peter Oliphant | last post by:
OK. I created a managed class. Now I want to create a global pointer to an instance of the class that the entire application can reference. Yet, when I do something like: MyManagedClass* my_instance ; as a global variable (i.e., it's not in a process of class or struct, or etc.) it tells me something like 'managed class instances can't...
5
3599
by: eiji | last post by:
Hi folks, I hope this is not "off topic"! :-) Consider the next code: /* Declarations of types that could become platform-dependent */ #define MyChar char #define MyInt int
4
2347
by: Leif902 | last post by:
Hi all, I'm working on a little project and have hit a roadblock, I'm trying to make an extension for a program who's extension DLL's must return either a double or a null terminating string (no void). This extension is actually a wrapper for another managed DLL which dosn't follow these rules (my dll will call it's functions and return...
1
2671
by: Bryan Parkoff | last post by:
An object can be defined using a class. The class contains variables and functions. It has a pointer to bind variables and functions. If I want to create more than one object. The class can have two objects with a separate pointer. However, functions are always shared with one or more objects, but each object has its own separate...
0
7347
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7590
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. ...
0
7684
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...
0
5883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4890
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...
0
3388
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1814
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
1
963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
633
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...

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.