WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
 
Forum
 

How to call a DLL function from another DLL in C, How to call a DLL function from another DLL in C launguage

rr.kalaiyrasan
Quote Post


New Member
*

Group: Members
Posts: 1
Member No.: 66841
Joined: 7-October 15


Sponsored Links
Can some one please explain How to call a DLL function from another DLL in C launguage?
PMEmail Poster
Top
huntingspace
Quote Post


Active Member
***

Group: Members
Posts: 54
Member No.: 49504
Joined: 11-February 12


First way:
CODE

#include <stdio.h>

extern "C" __declspec(dllimport)double AddNumbers(double a, double b);

int main(int argc, char **argv)
{
    double result = AddNumbers(1, 2);
    printf("The result was: %f\n", result);
    return 0;
}


Second way:
CODE

#include <windows.h>
#include <stdio.h>

typedef double (*importFunction)(double, double);

int main(int argc, char **argv)
{
    importFunction addNumbers;
    double result;

    HINSTANCE hinstLib = LoadLibrary("Example.dll");
    if (hinstLib == NULL) {
        printf("ERROR: unable to load DLL\n");
        return 1;
    }

    addNumbers = (importFunction)GetProcAddress(hinstLib, "AddNumbers");
    if (addNumbers == NULL) {
        printf("ERROR: unable to find DLL function\n");
        return 1;
    }

    result = addNumbers(1, 2);

    FreeLibrary(hinstLib);

    printf("The result was: %f\n", result);

    return 0;
}
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian