Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Adam, more question about loading DLL

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Adam, more question about loading DLL
#2851
Posted by: mooncake 2003-11-05 18:53:10
Example from Adam
==============
// Load library, will attempt to load libname.dll or libname.so in platforms normal way

       wxDllType mydll = wxDllLoader::LoadLibrary("libname");


// Define a type which is capable of holding function pointers to function taking 2 ints and returning one.

       typedef int (*int_func_int_int)(int, int);


// We know funk is like this,

//

//      int funk(int x, int y)

//      {

//           int z = (x+y);

//           return (z);

//       }

//

// so a pointer is created ready to hold it

       int_func_int_int p_funk;


// Then the pointer is filled with the reference to funk

       p_funk = (int_func_int_int) wxDllLoader::GetSymbol(mydll, "funk");


// Use p_funk as if it were funk

       int result = p_funk(5,8);


from your exam, how do you know this ? typedef int (*int_func_int_int)(int, int);
and, why dont you declare it as typedef int (*funk)(int, int) ?

thank you.
Meow~
Message2. Re: Adam, more question about loading DLL
#2855
Posted by: upCASE 2003-11-05 21:10:36
Hi mooncake!

I guess Adam refers to an example where he knows the function prototype because he wrote it or has the source for it, so it's a DLL he compiled himself.
 typedef int (*int_func_int_int)(int, int) is now used to make clear that the function returns an int and takes two ints as parameters. Sure, you could name it typedef int (*funk)(int, int), it doesn't really matter as long as you know what's going on.

If I worte a function I know to be in a DLL I compiled usong this prototype
float somefunc(double*, int, char);
I'd typedef it
typedef float (*myfunc)(double*, int, char);

Normally you find a reference with prototypes of all functions useable in a DLL, so you know how to typedef it. Look at the Win32 API for example. If you don't know the prototype, you'll be a t a loss.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: Adam, more question about loading DLL
#2859
Posted by: mooncake 2003-11-06 10:46:03
But, how the system know if you declare typedef float (*myfunc)(double*, int, char); and refer to  somefunc(double*, int, char) ?

If, one DLL involved 100 functions, and declare so on, the system will know?

Thank you.

Meanwhile, do you have any solutions that could read the contents from the DLL?

Thank you.
Meow~
Message4. Re: Adam, more question about loading DLL
#2860
Posted by: guidance 2003-11-06 20:17:08
>
> Meanwhile, do you have any solutions that could read the
> contents from the DLL?
>

Try this: http://g.yi.org/f.php?f=7482#2260
Message5. Re: Adam, more question about loading DLL
#2861
Posted by: upCASE 2003-11-06 21:15:07
Hi!
"But, how the system know if you declare typedef float (*myfunc)(double*, int, char); and refer to  somefunc(double*, int, char) ?"
The connection between the type you defined and the function you use is
 p_funk = (int_func_int_int) wxDllLoader::GetSymbol(mydll, "funk");
mydll is the DLL that was loaded and inside this DLL there's a symbol called funk that more or less signals the entry point of this function.
Viewing the contents of a DLL could be done with a disassembler. To only know the exported functions of a DLL it's enough to have PE tool for displaying them. This won't give you the prototypes though... Only the function names..

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message6. Re: Adam, more question about loading DLL
#2862
Posted by: mooncake 2003-11-06 22:19:44
Thank you, Guidance

Hi Upcase,  I am still blur... @@" Not so understand...

Meanwhile... If i want to know the type of functions of DLL, must use PE?
for example, i got anyname() from the DLL, but, if i want to know this function arguements etc... need to use PE?

Thank you
Meow~
Message7. Re: Adam, more question about loading DLL
#2863
Posted by: upCASE 2003-11-06 23:53:04
Hi!
PE is a format, not a program.
There are many programs out there that are able to tell you the imports and exports of a DLL or application. None of them, though, can tell you the correct prototypes of that function.
You either need
1. The docs for that DLL with prototypes
2. disassemble it and try to gather info on parameters and return values that way (not that easy, especially when you never did ASM before)

So far I haven't heard of a prog that could give you the prototypes.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-3-28  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0