We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,987 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to create a .dll in C++

I use code::blocks as an IDE but now i want to create a .dll file. I have followed this tutorial however it is for VC++.

TUTORIAL:
http://msdn.microsoft.com/en-US/library/vstudio/ms235636

I am strugeling becuase I am used to creating .dlls in C#. They are so easy. You just create a new library project. Write your code eg:

    // The .dll version
    using System;
    namespace SomeName
    {
        class Class1
        {
            public int add(int x, int y)
            {
                return x + y;
            }
        }
    }

    // The real "runable" version
    using System;
    namespace AgainSomeName
    {
        class Class2
        {
            public void Main(string[] args)
            {
                SomeName.Class1.add(5, 3);
            }
        }
    }

Thats it. All you have to do now is right click on your project in your IDE and then say add reference and add the .dll file. Easy usable. Isnt there a way to do it like as easy as that. Without having to use all those #ifdef, #endif, #else and static __declspec(dllexport) words. Easy like you do it in C#?

Oh and also, if i use Visual studio C++ exspress can i then only create programs for the .NET when i use that IDE? or whill the programs work for computers without the .NET alsong as i just dont include .NET header files?

2
Contributors
1
Reply
2 Hours
Discussion Span
8 Months Ago
Last Updated
3
Views
Question
Answered
MasterHacker110
Junior Poster
179 posts since Dec 2011
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 0

As I'm sure you noticed when you read the documentation, creating libraries in C++ is very different to C# (in my opinion most things tend to be more difficult in C++). I imagine the complexity in C++ is essentially down to the close-knit relationship between C++ and C (I'm just guessing though). Anyway, its important to realise why __declspec(dllexport) is actually necessary: basically its used to expose a function with C++ name mangling. So, if this is not what you want then perhaps you should consider using extern "C" which tells the compiler not to apply the usual C++ decorations in the symbol table.

Unfortunately, I have never attempted to create a C++ dll in Code::Blocks, however, after a quick search using Google I found this which may be of some use to you (apologies in advance if its not).

Good Luck!

Valaraukar
Junior Poster
130 posts since Mar 2009
Reputation Points: 16
Solved Threads: 10
Skill Endorsements: 0
Question Answered as of 1 Month Ago by Valaraukar

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0526 seconds using 2.65MB