|
-
November 21st, 2003, 03:45 AM
#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.
-
November 21st, 2003, 03:55 AM
#2
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.
-
November 21st, 2003, 05:01 AM
#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?
-
November 23rd, 2003, 06:41 AM
#4
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.
-
November 24th, 2003, 01:55 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|