CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: LNK2001 error

  1. #1

    LNK2001 error

    My 32-bit DLL needs to call a 16-bit DLL ReadSize16.dll and
    I get the linking error:
    error LNK2001: unresolved external symbol "int __stdcall _ReadSize(unsigned char, unsigned char *, unsigned long)" (?ReadSize@@YGHEPAEK@Z)
    fatal error LNK1120: 1 unresolved externals

    What am I missing?

    My 32-bit DLL code is below:

    //--------------------------------------------------------------------
    #include <windows.h>

    // Prototype for function in 16-bit DLL
    BOOL FAR PASCAL ReadSize(BYTE bDrive, LPBYTE lpBuffer, DWORD cbBuffSize);

    __declspec(dllexport) BOOL WINAPI CallReadSize()
    {
    HMODULE hModule;
    char lpBuff[512];
    BOOL fResult;

    if ((hModule=LoadLibrary("ReadSize16.dll")) == NULL)
    return 5; // DLL load error

    if (GetProcAddress(hModule, "ReadSize") == NULL)
    return 6; // DLL function call error

    if (fResult=ReadSize(0x80, (LPBYTE)lpBuff, 512)) {
    .......
    }

    return fResult;
    }
    Last edited by Kurosan; November 21st, 2003 at 03:50 AM.

  2. #2
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871
    Either do not use
    Code:
    BOOL FAR PASCAL ReadSize(BYTE bDrive, LPBYTE lpBuffer, DWORD cbBuffSize);
    or do not make calls:
    Code:
    LoadLibrary("ReadSize16.dll")) == NULL)
    ...
    GetProcAddress(hModule, "ReadSize")
    Well, if you want to link your 32 bit with 16 bit, use:
    Code:
    __declspec(dllimport)BOOL FAR PASCAL ReadSize(BYTE bDrive, LPBYTE lpBuffer, DWORD cbBuffSize);
    In this case you need .lib or your 16-bit DLL.
    In second case you need to place 16-bit DLL in searchable path.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  3. #3
    I try your method and use the 16-bit DLL (not the .lib file) and get this error:

    error LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall ReadSize(unsigned char, unsigned char *, unsigned long)" (__imp_?ReadSize@@YGHEPAEK@Z)
    fatal error LNK1120: 1 unresolved externals

    Any clue?

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871
    Hey...
    you guessed it wrong. In this case you need a .LIB file.
    You need not have lib, while using LoadLibrary calls.
    .LIB is required when compiler links with DLL.
    NOT required when LoadLibrary is used.
    Last edited by Ajay Vijay; November 23rd, 2003 at 06:45 AM.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Did you thunk? You simply cannot call a 16-bit DLL from a 32-bit program without thunking. Note that "thunk" is spelt properly; I don't mean "think". Thunking is not easy if you write the code and use the tools yourself.

    You can use a compiler capable of generating 16-bit code to write an OLE Automation server wrapper for the 16-bit DLL that can be used from a 32-bit client. That might sound difficult but it is not as hard as it sounds. You will need to learn some stuff but the knowledge will be useful for many other things too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured