Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Load DLL Failed?

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

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Load DLL Failed?
#2707
Posted by: mooncake 2003-10-07 19:56:50
Hi, i try this method, but prompt me error message.. :(

#include "wx/dynlib.h"
...


wxDllLoader *mydll = LoadLibrary("mylib.dll");

163 C:main.cpp cannot convert `HINSTANCE__*' to `wxDllLoader*' in initialization


163 C:main.cpp [Warning] unused variable `wxDllLoader*mydll'

what is the different between wxDllLoader and wxDynamicLibrary?

Thank you.
Meow~
Message2. Re: Load DLL Failed?
#2708
Posted by: 2003-10-07 20:54:43
I think you're asking a win32 function to return a wxWindows type, try
wxDllType *mydll = wxDllLoader::LoadLibrary("mylib");
wxDllLoader is provided for using static methods, whereas wxDynamicLibrary is a wrapper around it so you may derive your own classes.
Message3. Re: Load DLL Failed?
#2711
Posted by: mooncake 2003-10-08 07:47:32
Hi Adam, still prompt me error message.. :(

cannot convert `HINSTANCE__*' to `HINSTANCE__**' in

[Warning] unused variable `HINSTANCE__**mydll'


Thank you
Meow~
Message4. Re: Load DLL Failed?
#2712
Posted by: 2003-10-08 08:11:07
Sorry I left an * in there when I copied your code, it should have been:
wxDllType mydll = wxDllLoader::LoadLibrary("mylib");
Message5. Re: Load DLL Failed?
#2715
Posted by: mooncake 2003-10-08 18:37:08
Hi Adam,

still prompt me error message.. :(

[Warning] unused variable `HINSTANCE__*mydll'
Meow~
Message6. Re: Load DLL Failed?
#2717
Posted by: 2003-10-08 21:35:05
It's moaning becase you havn't used the handle you created, you have to do something with it, e.g. Get a system beep on Win32:
   wxDllType mydll = wxDllLoader::LoadLibrary("user32");

   typedef bool (*winbeeptype)(unsigned int);    
   winbeeptype win32_beep = (winbeeptype) wxDllLoader::GetSymbol(mydll, "MessageBeep");
   win32_beep(0xFFFFFFFF);
Message7. Re: Load DLL Failed?
#2718
Posted by: mooncake 2003-10-08 22:13:55
Hi Adam,

why we need to do like this?  Would you mind explain/describe for me about these following codes?

   typedef bool (*winbeeptype)(unsigned int);   

   winbeeptype win32_beep = (winbeeptype) wxDllLoader::GetSymbol(mydll, "MessageBeep");

Thank you.
Meow~
Message8. Re: Load DLL Failed?
#2720
Posted by: 2003-10-09 17:20:51
Sure, I can try, although all this pointer nonsense is still a bit alien to me.
typedef bool (*winbeeptype)(unsigned int);
is like the prototype of the function, so winbeeptype is type with 1 argument (an unsigned int) and a return type of bool, the same as MessageBeep from the DLL. win32_beep is created from this type:
winbeeptype win32_beep;
Finally the function pointer is asked for providing DLL handle and function name and squeezed into the winbeeptype prototype and it is assigned to win32_beep.
win32_beep = (winbeeptype) wxDllLoader::GetSymbol(mydll, "MessageBeep");
Message9. Re: Load DLL Failed?
#2722
Posted by: mooncake 2003-10-09 19:14:28
Hi,
    Need time to be understand.. >_<
    How do we know winbeeptype win32_beep ?
    Thank you.
Meow~
Message10. Re: Load DLL Failed?
#2723
Posted by: 2003-10-09 20:44:19
I'm not sure I know which bit, you don't get, I'll write another example:
// 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);
Message11. Re: Load DLL Failed?
#2752
Posted by: mooncake 2003-10-17 22:02:09
Hi Adam,

      I am just back from outstation.  So, how do we know the type of function from the dll for wx?

      Thanks.
Meow~
Message12. Re: Load DLL Failed?
#2754
Posted by: 2003-10-17 23:13:09
Well in the first example I looked it up in the win32 docs, for the second I'm assuming we would know, because we had written it. Are you trying to use functions from a 3rd party DLL which you have no import docs or source?
Message13. Re: Load DLL Failed?
#2755
Posted by: mooncake 2003-10-18 22:16:54
Hi,
     Hmm... Not really.   Becuase, sometime i will download others dll from the internet, so that we do not know the type or function names...
Meow~
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0