473,396 Members | 2,017 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,396 software developers and data experts.

Including and calling functions from a dll in C++

how do i call a function of c++ from a c++ dll
Oct 3 '07 #1
3 1429
Banfa
9,065 Expert Mod 8TB
In the normal way, include the header file and call the function.
Oct 3 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Which operating system??

If you are not using Windows, stop reading.

If this is being done dynamically using Windows, you need a call to LoadLibrary followed by a call to GetProcAddress.

Plus the DLL, if written in C++, needs to export the function name as unmangled.
Oct 3 '07 #3
Banfa
9,065 Expert Mod 8TB
If this is being done dynamically using Windows, you need a call to LoadLibrary followed by a call to GetProcAddress.
Only if you are dynamically linking at run time (oh actually you said that but sonce I have already typed everything below I am going to post it anyway :D )

If you are statically linking at link time, by including the *.lib file on the linker, command line then this is not required. This is how you link to the Windows kernel, user and all their other DLLs.

NOTE: statically linking to a DLL is NOT the same as linking a static library. When you create(compile and link) a DLL the output includings a <DLLName>.DLL, the dynamicly loaded code and a <DLLName>.lib. The lib file is usually fairly small because all it contains is calling vectors to the functions actually in the DLL and normally linking it does not increase the size of the executable much. If you know you are going to be using a specific DLL linking the lib does save on all the LoadLibrary/GetProcAddress but then the program will not start with the DLL being present.

Dynamically linking to a DLL can be very useful, you can use it to add extensions or to implement a form of polymorphism at program level (i.e. have a user interface that allows the user to perform set operations but then how those operations are implemented and carried out depend on which DLL you have dynamically linked to), but the program has to know what the interface to the DLL is.

There are various ways of doing this, fixing what functions the DLL has to implement is one or having a set of fixed functions in the DLL that are capable of enumerating the other functions.

Go too much further down this route and it starts to become sensible to look into COM (and DCOM) objects.
Oct 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Michael Pfeifer | last post by:
Hi all, I need to convert datetimes from any timezone to UTC and back considering daylight saving. It is not enough, to just add or subtract the timezone offset. Also, I can not use c functions...
9
by: Trenqo 0 | last post by:
I'm looking for a way to include javascript files from within a ".js" file. This would allow me to only need to link to one ".js" file, and yet still organize my functions into non gargantuan files...
5
by: Dave | last post by:
does calling a regular function cost any cpu time? In other words, is it faster to write the code of two functions into main(), or is it the exact same thing as calling two functions. I know its...
1
by: Mark Jerde | last post by:
Yesterday I posted the message below to microsoft.public.dotnet.languages.vb and microsoft.public.vc.language. The two replies are also posted. I need to write some ISO C++ functions, more...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
2
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
18
by: sam_cit | last post by:
Hi Everyone, int main() { printf("not included stdio.h"); } Yes, i haven't included stdio.h and my compiler would generate a warning and would assume that it would return a int, my question...
4
by: r_ahimsa_m | last post by:
Hello, I am learning WWW technologies in Linux. I created index.html file which I can browse with Firefox/Konqueror using URL localhost/~robert/rozgloszenia/index.html. The page looks fine but...
10
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.