Function Calling From A DLL In a DLL

This is a discussion on Function Calling From A DLL In a DLL within the Windows Programming forums, part of the Platform Specific Boards category; Hmm, this may sound confusing lol. I am making a dll that needs to call functions from another dll. My ...

  1. #1
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    Function Calling From A DLL In a DLL

    Hmm, this may sound confusing lol. I am making a dll that needs to call functions from another dll.

    My program will have to dlls, fen.dll & dat.dll. Basically what im having problems doing is calling a putting a function from dat.dll inside fen.dll and then calling it.

    I think this is possible to do isnt it?

    Anyway i can put can get fen.dll to compile fine, and i can call my own functions just written in that dll from my program fine, but when i try to call a function from fen.dll thats in dat.dll it just dosnt work, has no effect in the program.

    Can someone show me how i should define functions inside fen.dll so i can use them. I am linking the dat.lib file as well.

    So i just need to know how to define functions in fen.dll so i can just call them in fen.dll from dat.dll.

    Thanks,
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Not too difficult! With the first dll, use LoadLibrary() to load the second dll.....then use GetProcAddress() to give you the function in the second dll....ala

    Code:
    //MyMain exe
    #include <windows.h>
    
    #define DllImport extern "C" __declspec (dllimport)
    
    DllImport int LoadAndRun(void);
    
    int WINAPI WinMain(HINSTANCE hThisInstance,
    				   HINSTANCE hPrevInstance, 
    				   LPSTR lpszArgument, 
    				   int nFunsterStil){
    
    	LoadAndRun();
    	
    	return 0;
    }
    Code:
    //MyFirstDll.dll 
    //- use the library from this created to build the exe above 
    #include <windows.h>
    
    #define DllExport extern "C" __declspec (dllexport)
    
    typedef void (*MYDLLFUNC)(void);
    
    DllExport int LoadAndRun(void){
    
    	HMODULE hMod;
    	MYDLLFUNC MyDllFunc = NULL;
    
    	hMod = LoadLibrary("MySecondDll.dll");
    	if(!hMod){
    		MessageBox(HWND_DESKTOP,"Error",NULL,MB_OK);
    		return 1;
    	}
    
    	MyDllFunc = (MYDLLFUNC)GetProcAddress(hMod,"FunctionInSecondDll");
    	if(!MyDllFunc){
    		MessageBox(HWND_DESKTOP,"Error",NULL,MB_OK);
    		return 1;
    	}
    
    	MyDllFunc();
    
    	FreeLibrary(hMod);
    	MyDllFunc = NULL;
    
    
    	return 0;
    }
    Code:
    //MySecondDll.dll
    // - Dont need the librarythat the compiler produces for this dll
    #include <windows.h>
    
    #define DllExport extern "C" __declspec (dllexport)
    
    DllExport FunctionInSecondDll(void){
    
    	MessageBox(HWND_DESKTOP,"Got there in the end!!",NULL,MB_OK);
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Calling function from remote dll
    By slcjoey in forum Windows Programming
    Replies: 3
    Last Post: 09-28-2005, 08:50 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21