Best way to use static method functions from MC++ lib in VB.NET

G

Guest

I've created a MC++ library with a class that contains some static method functions

I create a reference to the library from a VB.NET application and I ca
call the functions with no problems

I'm wondering if there is an alternative to creating a reference to the dll or assembly
Is there a way to register a namespace in MC++ or VB.NET so that my class works like standar
base classes such as the Systems class using the imports statement in the VB.NET app

I'm looking for a way to make the static class as easy to use as possibl
Do namespaces have an advantage over using the add reference feature

Also, I wonder if there is any impact on support for multi-threading if I make m
class method functions static?
 
J

Joe Delekto

Greets,

While I've not run across it, there may be a way to make one of your
class library DLLs automatically referenced by the Visual Studio .NET IDE.
Certain project types add references to other .NET DLLs (such as the
System.Web.dll), so perhaps you could create a custom project type that adds
your control library. (Note that if you create, say, a console application,
you have to add that reference yourself.)

This is definitely not recommended (i.e. don't do it for production
code!), but one MC++ project I worked on used the System namespace to
declare a "ConsoleEx" class with static members that were meant to augment
the .NET Framework Console functions. It would definitely be frowned upon
for a production release, especially if there were ever a class with that
name to be added to the framework, but it worked for me nonetheless. (I
only used it for internal testing as a way to 'cheat' without needing a
'using' statement specifically for that class.)

As far as multi-threading is concerned, you only have an issue if you
have static data members which are accessed by your static member functions.
In that case, you would have to lock access to them between threads. If,
however, you take all your parameters to your static member functions and
create any interim objects and data internally (without any static members
or variables [i.e. everything on the stack or heap and not shared between
threads]) then you should have no problems running in a multi-threaded
environment without any special synchronization considerations.

Regards,

Joe
 
W

William DePalo [MVP VC++]

Rob said:
I'm wondering if there is an alternative to creating a reference to the dll or assembly?
Is there a way to register a namespace in MC++ or VB.NET so that my class works like standard
base classes such as the Systems class using the imports statement in the
VB.NET app?

If you have some assembly which provides useful services potentially to many
consumers you may want to install it in the Global Assembly Cache (GAC):

http://msdn.microsoft.com/library/d...nworkingwithassembliesglobalassemblycache.asp

If you find you want to do that you may want to install it pre-compiled to
avoid incurring any JIT compile penalty when it is used:

http://msdn.microsoft.com/library/d...ols/html/cpgrfnativeimagegeneratorngenexe.asp
I'm looking for a way to make the static class as easy to use as possible
Do namespaces have an advantage over using the add reference feature?

Namespaces are used to lessen the possibilty that two
vendors/applications/assemblies/classes will have the same names making
usage difficult. In other words it addresses the problem sometimes called
(global) namespace pollution.
Also, I wonder if there is any impact on support for multi-threading if I make my
class method functions static?

The single biggest issue with respect to threading (IMO) is the prevention
of multiple simultaneous updates of shared data by code running in distinct
threads. No matter whether your member function is static or not, you must
synchronize access to any shared data that is modifiable by multiple
threads.

Regards,
Will
 

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