loadlibrary from dll

This is a discussion on loadlibrary from dll within the Windows Programming forums, part of the Platform Specific Boards category; hey guys, ist it possible to use LoadLibrary from inside a dll file to get access to another dll? part ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    loadlibrary from dll

    hey guys,

    ist it possible to use LoadLibrary from inside a dll file to get access to another dll?

    part of sorcecode:

    Code:
    #include <string.h>
    #include <stdio.h>
    #include <windows.h>
    
    .
    .
    .
    
    extern "C" void __declspec(dllexport) __cdecl EXPORTNAME
    (float *a,int *b, char *c, char *d, char *e)
    
    {
    typedef void (_cdecl *MYPROC)(double*, double*); 
    
    HINSTANCE hinstlib_ctrl;
    
    MYPROC call_controller;
    
    hinstlib_ctrl = LoadLibrary("DLLNAME.dll"); // compiler ERROR in this LINE 
    
    //call_controller=(MYPROC)GetProcAddress(hinstlib_ct rl,"Controller"); 
    
    .
    .
    .
    maybe anyone has an answer!

    thank you

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Instead of asking "is this possible," why not provide us with the compiler error?

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    13
    Code:
    error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [17]' to 'LPCWSTR'
    1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    is the error message posted by VC++08.

    I was asking, whether it is possible, because i am not sure, if you can use the loadlibrary in a dll.

    All topics I read about where concerning executables.

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The error tells you that you are building a unicode version but passing the parameters for the ascii version to LoadLibrary
    try
    Code:
    hinstlib_ctrl = LoadLibrary(_T("DLLNAME.dll"));
    Kurt

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    13
    thanks for the answer, kurt

    i got better indeed, the long error message is gone, but now
    the message is

    Code:
     error C3861: '_T': identifier not found

    Do I have to include further loadlibrary functions?

  6. #6
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    I don't work on windows much but I think you have to #include <tchar.h> or something like this.
    Kurt

  7. #7
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Kurt is correct; you need to #include <tchar.h>

    In the future, when you get an error when you're compiling, and you need help figuring it out, then you come here and post the EXACT error message you're receiving.

    Now, this is a good discussion on WinAPI and Unicode, so you should probably go there and read.

  8. #8
    Registered User
    Join Date
    Jun 2008
    Posts
    62
    If you don't want the extra include, the other (MS visual studios specific) way of turning a c-string into a LPCWSTR is by putting an L in front of it. So LoadLibrary(L"theDll.dll"); should work.

  9. #9
    Registered User
    Join Date
    Mar 2010
    Posts
    13
    Thx a lot for all your help:

    Of course the additional L was the correct answer.
    Didn't work at first though.

    The problem was a corrupted windows.h import from vs2008.
    Reinstalling it fixed the problem.

    Thx again for your help

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    The problem was a corrupted windows.h import from vs2008.
    Um...how exactly do you import a header file?

  11. #11
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by Cogman View Post
    If you don't want the extra include, the other (MS visual studios specific) way of turning a c-string into a LPCWSTR is by putting an L in front of it. So LoadLibrary(L"theDll.dll"); should work.
    this will work only when compiling as UNICODE

    _T or TEXT macros work in both cases - for UNICODE they add L, for non-UNICODE they do nothing
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  12. #12
    Registered User
    Join Date
    Mar 2010
    Posts
    13
    Quote Originally Posted by Bubba View Post
    Um...how exactly do you import a header file?
    Actually "import" is maybe the wrong expression.

    Compiling the cpp file didnt't work using the old vs2008 installation (though it was the same windows.h used)

    After reinstalling vs2008 the USE (maybe that's a better term) of the windows.h worked without any problems.
    Last edited by DampfHans; 04-04-2010 at 04:44 AM.

  13. #13
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Why this thread is not in Win32 forum?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Make sure you are not calling the second DLL from within the first DLLs DLLMain() function, it may result in undefined behaviour.

    That is; LoadLibrary() is not safe to be used within a DLLMain() function.
    "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. Replies: 8
    Last Post: 12-01-2008, 09:09 AM
  2. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  3. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  5. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 04:29 AM

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