473,564 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1343
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***@toomuchs pam.com> wrote in message
news:%2******** ********@tk2msf tngp13.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********@n0s p4m.popstick.co m> wrote
in message news:ut******** ******@TK2MSFTN GP12.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***@toomuchs pam.com> wrote in message
news:%2******** ********@tk2msf tngp13.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******** **********@TK2M SFTNGP10.phx.gb l...
Use static members of a class instead.

Ronald Laeremans
Visual C++ team

"Hasani (remove nospam from address)" <hb********@n0s p4m.popstick.co m> wrote in message news:ut******** ******@TK2MSFTN GP12.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***@toomuchs pam.com> wrote in message
news:%2******** ********@tk2msf tngp13.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***@toomuchs pam.com> wrote in message
news:es******** ******@TK2MSFTN GP11.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******** **********@TK2M SFTNGP10.phx.gb l...
Use static members of a class instead.

Ronald Laeremans
Visual C++ team

"Hasani (remove nospam from address)" <hb********@n0s p4m.popstick.co m>

wrote
in message news:ut******** ******@TK2MSFTN GP12.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***@toomuchs pam.com> wrote in message
> news:%2******** ********@tk2msf tngp13.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******** ******@tk2msftn gp13.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***@toomuchs pam.com> wrote in message
news:es******** ******@TK2MSFTN GP11.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******** **********@TK2M SFTNGP10.phx.gb l...
Use static members of a class instead.

Ronald Laeremans
Visual C++ team

"Hasani (remove nospam from address)" <hb********@n0s p4m.popstick.co m>

wrote
in message news:ut******** ******@TK2MSFTN GP12.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***@toomuchs pam.com> wrote in message
> news:%2******** ********@tk2msf tngp13.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******@onlin e.microsoft.com > wrote in message
news:OP******** ******@TK2MSFTN GP12.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
6328
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 :-) What PHP software / library / components could help me, instead of writing it from scratch ? They have PHP 4 (I think) and MySQL on the...
6
3259
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, no memory is lying around. GC reports only 84k of allocations. Starting 5-10 of this apps is going to start taking a considerable amount of memory....
13
2244
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
2670
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcmg_overview.asp but the compiler gives me a linker error, it will...
0
1252
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 could still be loaded by the consuming application ( concerning the manipulated assembly is a DLL ), The tool uses the unmanaged profiling API to...
9
1325
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 'destroyed': ref myClass { public: myClass() {} ~myClass() {} // never called !myClass() {} // never called
10
1730
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? 3) What is the diffrence between & and *? (I know that * is a pointer) 4) Managed and Unmanaged code, whats the diffrence? I am trying to write a...
1
6676
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 want to code the similar program with Asynchronous Socket commands of .NET using Managed C++ on Windows .NET Forms. My problem is with delegates. I...
30
3483
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
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
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
7888
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. ...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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
6255
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...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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
3643
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...

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.