473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Simple Managed DLL Creation

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
Nov 17 '05 #1
7 1337
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.

"Mark Prenter" <so***@toomuchspam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #2
Use static members of a class instead.

Ronald Laeremans
Visual C++ team

"Hasani (remove nospam from address)" <hb********@n0sp4m.popstick.com> wrote
in message news:ut**************@TK2MSFTNGP12.phx.gbl...
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.

"Mark Prenter" <so***@toomuchspam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Nov 17 '05 #3
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
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Use static members of a class instead.

Ronald Laeremans
Visual C++ team

"Hasani (remove nospam from address)" <hb********@n0sp4m.popstick.com> wrote in message news:ut**************@TK2MSFTNGP12.phx.gbl...
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.

"Mark Prenter" <so***@toomuchspam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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



Nov 17 '05 #4
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

"Mark Prenter" <so***@toomuchspam.com> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
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
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Use static members of a class instead.

Ronald Laeremans
Visual C++ team

"Hasani (remove nospam from address)" <hb********@n0sp4m.popstick.com>

wrote
in message news:ut**************@TK2MSFTNGP12.phx.gbl...
> 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.
>
> "Mark Prenter" <so***@toomuchspam.com> wrote in message
> news:%2****************@tk2msftngp13.phx.gbl...
>> 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
>>
>>
>
>



Nov 17 '05 #5
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
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
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

"Mark Prenter" <so***@toomuchspam.com> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
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
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message news:%2******************@TK2MSFTNGP10.phx.gbl...
Use static members of a class instead.

Ronald Laeremans
Visual C++ team

"Hasani (remove nospam from address)" <hb********@n0sp4m.popstick.com>

wrote
in message news:ut**************@TK2MSFTNGP12.phx.gbl...
> 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.
>
> "Mark Prenter" <so***@toomuchspam.com> wrote in message
> news:%2****************@tk2msftngp13.phx.gbl...
>> 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
>>
>>
>
>



Nov 17 '05 #6
Mark Prenter wrote:
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.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 17 '05 #7
Thanks very much guys!!!

I feel much better now. :-)

/\/\ark
"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
Mark Prenter wrote:
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.

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

Nov 17 '05 #8

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

Similar topics

3
by: farialima | last post by:
Hello, My wife is taking care of a non-profit, and she asked me to help her set up an extranet for the the members. I've promissed I'd be done before the end of the year... now I have to deliver...
6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
13
by: Jason Swett | last post by:
I want to do graphics with C++. Surprisingly, so far nobody has been able to tell me anything helpful. How do I do it? Any input would be greatly appreciated. Jason
3
by: Ofer Achler | last post by:
I'm having horrible, headache inducing problems trying to make a wrapper, or just a c++ class to interact with a managed class. I mimiked a managed wrapper to an unmanaged class as showin here:...
0
by: Nadav | last post by:
Hi All, - I am working on a tool that manipulate managed assemblies, some of the functionality provided by the tool require manipulating the metadata sections of the managed assembly in a way it...
9
by: Peter Oliphant | last post by:
I would assume in the following that 'instance' being set to 'nullptr' should cause the instance of myClass that was created to no longer have any pointers pointing to it, and therefore be...
10
by: Patrick F | last post by:
Hi Trying to learn c++ and am woundering over afew things 1) What is the diffrence between . and -and :: ? 2) Why do you sometimes have to use ^ after declaring a object, what exacly does it do?...
1
by: Alper AKCAYOZ | last post by:
Hello, I have developped asynchronous socket communication with blocking Socket commands (accept, connect, send, receive) by using threads on Windows .NET Forms. It is working properly. Now I...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.