Creating global objects in a class library

  • Thread starter Thread starter Leif902
  • Start date Start date
L

Leif902

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
the results as doubles and strings which the prog. can understand).


The problem i'm having is this.
Because I can't create global instances of a managed object in Visual
C[++] I can not create an instance of the object that can be read and
modified by all the functions in the DLL. The DLL i'm trying to wrap
has an object that I need an instance of (to store data and change
settings in)... and all the functions need access too it, but of
course w/ managed code it can't be global.


Is there any workaround for this? The application can't create an
instance of the object, it's expansion mechanism only executes
functions from the DLL.
I need to be able to have all my functions read/write data from the
same instance.

Thanks, and sorry if this is poorly stated
- Leif
 
No, I'm afraid that wouldn't work because I'd still have to create an
instance of the object of which the other objects were static members
of... and the program for which I am writing an extension won't do
that. It just calls global functions.

- Leif

How about static member objects?

--
Sheng Jiang



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
the results as doubles and strings which the prog. can understand).
The problem i'm having is this.
Because I can't create global instances of a managed object in Visual
C[++] I can not create an instance of the object that can be read and
modified by all the functions in the DLL. The DLL i'm trying to wrap
has an object that I need an instance of (to store data and change
settings in)... and all the functions need access too it, but of
course w/ managed code it can't be global.
Is there any workaround for this? The application can't create an
instance of the object, it's expansion mechanism only executes
functions from the DLL.
I need to be able to have all my functions read/write data from the
same instance.
Thanks, and sorry if this is poorly stated
- Leif- Hide quoted text -

- Show quoted text -
 
You don't need to instantiate class to use it's static members. As example,
see how File in System.IO implements static methods

You reference your dll exactly in same manner as you reference System.IO or
another .Net assembly. And you use declared classes just like you use File.

Probably you need to re-visit documentation for static modifier and look at
related samples

Leif902 said:
No, I'm afraid that wouldn't work because I'd still have to create an
instance of the object of which the other objects were static members
of... and the program for which I am writing an extension won't do
that. It just calls global functions.

- Leif

How about static member objects?

--
Sheng Jiang



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
the results as doubles and strings which the prog. can understand).
The problem i'm having is this.
Because I can't create global instances of a managed object in Visual
C[++] I can not create an instance of the object that can be read and
modified by all the functions in the DLL. The DLL i'm trying to wrap
has an object that I need an instance of (to store data and change
settings in)... and all the functions need access too it, but of
course w/ managed code it can't be global.
Is there any workaround for this? The application can't create an
instance of the object, it's expansion mechanism only executes
functions from the DLL.
I need to be able to have all my functions read/write data from the
same instance.
Thanks, and sorry if this is poorly stated
- Leif- Hide quoted text -

- Show quoted text -
 
You don't need to instantiate class to use it's static members. As example,
see how File in System.IO implements static methods

You reference your dll exactly in same manner as you reference System.IO or
another .Net assembly. And you use declared classes just like you use File.

Probably you need to re-visit documentation for static modifier and look at
related samples




No, I'm afraid that wouldn't work because I'd still have to create an
instance of the object of which the other objects were static members
of... and the program for which I am writing an extension won't do
that. It just calls global functions.
- Leif
How about static member objects?
--
Sheng Jiang

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
the results as doubles and strings which the prog. can understand).
The problem i'm having is this.
Because I can't create global instances of a managed object in Visual
C[++] I can not create an instance of the object that can be read and
modified by all the functions in the DLL. The DLL i'm trying to wrap
has an object that I need an instance of (to store data and change
settings in)... and all the functions need access too it, but of
course w/ managed code it can't be global.
Is there any workaround for this? The application can't create an
instance of the object, it's expansion mechanism only executes
functions from the DLL.
I need to be able to have all my functions read/write data from the
same instance.
Thanks, and sorry if this is poorly stated
- Leif- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

I came back to this group to state exactly that, I realized it just
after I posted my last response earlier, I don't know what I was
thinking... that was obvious and should have been from the start...

Thanks so much for the help,
- Leif
 
Just incase anyone else is interested in the solution (I was being an
idiot, it was obvious, as someone else pointed out to me...),

The solution is simply to have a static pointer (or array of pointers)
to the instance(s) of the object that is set after the instance(s)
creation from an initialization function.

- Leif
 
Leif902 said:
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
the results as doubles and strings which the prog. can understand).


The problem i'm having is this.
Because I can't create global instances of a managed object in Visual
C[++] I can not create an instance of the object that can be read and

You can have a global gcroot<T^> variable.
 
Back
Top