Thread: Function Call From DLL

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

    Function Call From DLL

    Hey,

    I have a dll, no lib file or anything. I have dissasembled it and got a list of the exported function names.

    What i need to know how to do is call a function, from the dll in my program.

    I dont know the function params at the moment, so i when i load the dll and type:

    function_name(

    I need visual c to tell me the params as it does normally. Is it LoadLibarary() or somthing i need to use? Im not sure anyway.


    I hope this is understandable,

    Thanks alot,
    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,793
    If you dont have the function params, then this is not an easy task.........You need the params to build a typedef for a function pointer..........

    If you know how the function works and its exportable....its relatively easy...

    I did this example just now, and it shows how simple it can be - IF YOU HAVE THE FUNCTION INFO!!!

    Code:
    #include <windows.h>
    
    typedef int (WINAPI *MESSAGEBOXRAW)(HWND hWnd,LPCTSTR lpText,
    							 LPCTSTR lpCaption,UINT uType);
    
    MESSAGEBOXRAW MessageBoxRaw;
    
    
    int WINAPI WinMain(HINSTANCE hThisInstance, 
    				   HINSTANCE hPrevInstance, 
    				   LPSTR lpszArgument, 
    				   int nFunsterStil){
    	HMODULE hMod;
    
    	hMod = LoadLibrary("User32.dll");
    
    	if(hMod == NULL)
    		return 1;
    
    	MessageBoxRaw = (MESSAGEBOXRAW)GetProcAddress(hMod,
    		"MessageBoxA");
    
    	if(MessageBoxRaw == NULL)
    		return 1;
    
    	MessageBoxRaw(HWND_DESKTOP,"Success","Whoopee!!",MB_OK);
    
    	FreeLibrary(hMod);
    
    
    	return 0;
    
    }

  3. #3
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Thanks alot fordy,

    I used win32dasm to get the exported functions, i know that this dll works. Do you know if there is any other programs or anything i can use to get the function info?

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

  4. #4
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    Fordy!
    Where the did you learn that?
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by (TNT)
    Thanks alot fordy,

    I used win32dasm to get the exported functions, i know that this dll works. Do you know if there is any other programs or anything i can use to get the function info?

    Thanks
    TNT
    Its easy to see whats exported....and to then get a pointer....but your problem is that you dont know how the func works, what params it accepts and what it returns......

    Well although you can see the params in the assembler by what's popped at the start of the procedure, I dont think it will be easy to find what that param is....thay will all be DWORDS most likely....but that could be a handle, a pointer, a simple value or more or less anything.....

    Originally posted by Nor
    Fordy!
    Where the did you learn that?
    A life wasted on MSDN and lots of messing on VC++ when I should be doing something else

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    And if you get the param list wrong it will mangle the function names after it. (in release mode anyway) In some cases, especially if the param list is long/big, will need a def file.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Loading files with a function call
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 04-10-2007, 07:19 PM
  3. Error C2664 - Trying to call an external Dll
    By jamez05 in forum C++ Programming
    Replies: 3
    Last Post: 08-08-2006, 06:07 AM
  4. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  5. Function Calling From A DLL In a DLL
    By (TNT) in forum Windows Programming
    Replies: 1
    Last Post: 06-03-2002, 08:27 AM