Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2004

Tip: Looking for answers? Try searching our database.

Simple Managed DLL Creation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Prenter - 12 Jul 2004 22:00 GMT
Hi all, I'm fairly new to .NET and I haven't done much in C++ before,
nothing complex anyway, but I have a pretty good understanding of
programming in general.

What I'm trying to do is create a .DLL that contains a lot of the functions
and classes that I normally use.  I've followed the examples from
http://www.c-sharpcorner.com/2/pr12.asp which contains a pretty good example
of creating a simple .DLL.  Even though the example is in C#, it was pretty
easy to translate into C++ .NET.

And here's the question :  I was able to create a simple DLL which contains
classes, but I have not figured out how to include simple functions.  Is it
possible to have functions in a DLL that aren't associated with any
particular class or object?  "Simple" functions, as I call them?

Thanks,
/\/\ark
Hasani \(remove nospam from address\) - 12 Jul 2004 23:12 GMT
They're called global functions in c++
they're different than static.

http://c.ittoolbox.com/documents/document.asp?i=1596

If you were to reference this dll in .net, I doubt a global or static
methods will show up though, I did create a project a few months back in
managed c++ that used atl and when i referenced it in .net, it listed
structures that were not contained in a namespace, but those were structures
and not methods.

> Hi all, I'm fairly new to .NET and I haven't done much in C++ before,
> nothing complex anyway, but I have a pretty good understanding of
[quoted text clipped - 13 lines]
> Thanks,
> /\/\ark
Ronald Laeremans [MSFT] - 13 Jul 2004 01:40 GMT
Use static members of a class instead.

Ronald Laeremans
Visual C++ team

"Hasani (remove nospam from address)" <hblackwell@n0sp4m.popstick.com> wrote
> They're called global functions in c++
> they're different than static.
[quoted text clipped - 30 lines]
>> Thanks,
>> /\/\ark
Mark Prenter - 13 Jul 2004 18:26 GMT
Thanks for the reply.  I'm only somewhat familiar with the "static" keyword.
I understand that if I declare a VARIABLE static, there will only be one
instance for a library.  So it could be used for keeping an employee count,
for example.  But that's static variables, and I'm worried about static
functions or methods...

Are there any "gotcha's" when dealing with static methods?  Are variables
used inside the static method automatically static as well?  Does that cause
problems if two programs happen to use the same method out of the DLL at the
same time?

Thanks,
/\/\ark

> Use static members of a class instead.
>
[quoted text clipped - 36 lines]
> >> Thanks,
> >> /\/\ark
Ronald Laeremans [MSFT] - 13 Jul 2004 20:38 GMT
You can think of as a static method member of a type as being the same as a
global member but scoped in the name of the type. That means that for e.g.
threading they behave identically as global functions would.

There are some really corner issues that make a difference but for the
mainstream use you can ignore all of that and almost think of these as
namespace scoped global methods.

Ronald

> Thanks for the reply.  I'm only somewhat familiar with the "static"
> keyword.
[quoted text clipped - 57 lines]
>> >> Thanks,
>> >> /\/\ark
Mark Prenter - 13 Jul 2004 22:42 GMT
Hello Ronald, thanks for the reply.

Unfortunately, I don't have any experience with global functions in C++ so I
don't really comprehend what you are saying.

My concern is that I don't know if variables inside a static method are also
static by default?  Because I am writing a DLL which contains functions that
could be called at any time...  What happens if two programs, running at the
same time, call the same function from the DLL?  Will the data be corrupted?
Or can the same static function be called twice at the same time without
interference?

The reason I am questioning this is that we have several dual CPU machines,
and some of the programs I'm writing take several minutes to complete.
These programs will call Static Methods in the DLL I am currently writing.
These Static Methods are meant as individual functions and should not
"share" any variables.  So I don't know if I can actually use Static Methods
in this case?

Does this make sense?

Thanks,
/\/\ark

> You can think of as a static method member of a type as being the same as a
> global member but scoped in the name of the type. That means that for e.g.
[quoted text clipped - 67 lines]
> >> >> Thanks,
> >> >> /\/\ark
Brandon Bray [MSFT] - 13 Jul 2004 23:55 GMT
> My concern is that I don't know if variables inside a static method are
> also static by default?  Because I am writing a DLL which contains
> functions that could be called at any time...  What happens if two
> programs, running at the same time, call the same function from the DLL?
> Will the data be corrupted? Or can the same static function be called
> twice at the same time without interference?

Normally, variables introduced inside static functions are local to the
function invocation (they are on the specific thread's execution stack).
Thus they do not need to be protected by synchronization devices in
multi-threaded programs.

If a local variable is introduced with the 'static' keyword, then it is
shared between all invocations of that function. It is subject to race
conditions in a multi-threaded program.

It is very unlikely that you would want to introduce a static variable
inside a static function unless you really understand what you are doing and
have experience with multithreaded programming.

> The reason I am questioning this is that we have several dual CPU
> machines, and some of the programs I'm writing take several minutes to
> complete. These programs will call Static Methods in the DLL I am
> currently writing. These Static Methods are meant as individual functions
> and should not "share" any variables.  So I don't know if I can actually
> use Static Methods in this case?

It sounds like you're fine.

Signature

Brandon Bray, Visual C++ Compiler         http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.

Mark Prenter - 14 Jul 2004 00:25 GMT
Thanks very much guys!!!

I feel much better now.  :-)

/\/\ark

> > My concern is that I don't know if variables inside a static method are
> > also static by default?  Because I am writing a DLL which contains
[quoted text clipped - 24 lines]
>
> It sounds like you're fine.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.