Using 64-bit DLL from Delphi, GetProcAddress gives error [Edit]

Hi,

I have a DLL compiled with Visual Studio in C++, which is a wrapper to the lib files from the Logitech G15 LCD SDK API.

The 32-bit version works fine with no issues.

I then compiled the DLL as 64-bit. Checked with PE explorer and it showed it as a 64-bit DLL. Opened it with Dependency Walker, and it shows the exports are all there just like in the 32-bit one.

However.. when I try to load a function, it's as if the function didn't exist in the DLL exports: (changed platform to 64bit in my Delphi project first)


  DLLHandle := LoadLibrary('lgLcdWrapperX64.dll');
  if DLLHandle = 0 then Exit(False);

  @lgLcdInit       := GetProcAddress(dllHandle, 'lgLcdInitWrap');
  if (not Assigned(lgLcdInit)) then ShowMessage(SysErrorMessage(GetLastError));


GetLastError says "The specified module could not be found"

What could be wrong?

Edited by: brian - on Jun 23, 2012 6:54 AM
Edit: (64bit DLL made with delphi works fine)

Edited by: brian - on Jun 23, 2012 7:27 AM

Also.. it's very weird the last error message says the MODULE rather than PROCEDURE could not be found, since the DLL did load fine.

Delphi code:

{code}

Type Tshowstuff = function :dword; cdecl;

Var DllHandle: Cardinal;
    showstuff: Tshowstuff;


  DLLHandle := LoadLibrary('lgLcdWrapper.dll');
  ShowMessage(SysErrorMessage(GetLastError));
  caption := inttostr(DLLHandle);
  @showstuff       := GetProcAddress(dllHandle, 'lgLcdInitWrap');
  if (not Assigned(showstuff)) then ShowMessage(SysErrorMessage(GetLastError));

  showstuff;

  FreeLibrary(DLLHandle);
{code}

C++ DLL:

{code}
// lgLCDWrapper.DLL
//
// A Wrapper-DLL for Delphi and other compilers who cannot include the original
// lcLcd.Lib provided by Logitech. These functions are needed to communicate with
// the graphical LCD of an Logitech G15-Keyboard.
//
// Code by Olaf Stieleke, May 1st, 2007
// Compiler Visual C++ 2005 Express Edition
// Hereby dedicated to Open Source under GPL-License.
//

//Make sure to set additional Include-Path to lglcd.h (found in Logitech-SDK-Folders)
//Make sure to set additional Library-Path to lglcd.lib (found in Logitech-SDK-Folders)

#include "stdafx.h"
#include <lglcd.h>
#include "lgLcdWrapper.h"


BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call,LPVOID lpReserved)
{
    return TRUE;
}

DWORD _cdecl lgLcdInitWrap(void)
{
    return lgLcdInit();
}

DWORD _cdecl lgLcdDeInitWrap(void)
{
    return lgLcdDeInit();
}
DWORD _cdecl lgLcdConnectAWrap(lgLcdConnectContextA *ctx)
{
    return lgLcdConnectA(ctx);
}
DWORD _cdecl lgLcdDisconnectWrap(int connection)
{
    return lgLcdDisconnect(connection);
}
DWORD _cdecl lgLcdEnumerateWrap(int connection, int index, lgLcdDeviceDesc *description)
{
    return lgLcdEnumerate(connection,index,description);
}
DWORD _cdecl lgLcdOpenWrap(lgLcdOpenContext *ctx)
{
    return lgLcdOpen(ctx);
}
DWORD _cdecl lgLcdCloseWrap(int device)
{
    return lgLcdClose(device);
}
DWORD _cdecl lgLcdReadSoftButtonsWrap(int device, DWORD *buttons)
{
    return lgLcdReadSoftButtons(device,buttons);
}
DWORD _cdecl lgLcdUpdateBitmapWrap(int device, lgLcdBitmapHeader *bitmap, DWORD priority)
{
    return lgLcdUpdateBitmap(device,bitmap,priority);
}
DWORD _cdecl lgLcdSetAsLCDForegroundAppWrap(int device, int foregroundYesNoFlag)
{
    return lgLcdSetAsLCDForegroundApp(device,foregroundYesNoFlag);
}
{code}

..h include file
{code}
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdInitWrap(void);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdDeInitWrap(void);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdConnectAWrap(lgLcdConnectContextA *ctx);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdDisconnectWrap(int connection);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdEnumerateWrap(int connection, int index, lgLcdDeviceDesc *description);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdOpenWrap(lgLcdOpenContext *ctx);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdCloseWrap(int device);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdReadSoftButtonsWrap(int device, DWORD *buttons);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdUpdateBitmapWrap(int device, lgLcdBitmapHeader *bitmap, DWORD priority);
extern "C" __declspec(dllexport) DWORD  _cdecl lgLcdSetAsLCDForegroundAppWrap(int device, int foregroundYesNoFlag);
{code}

stdafx.cpp]

{code}
    #include "stdafx.h"
    // stdafx.h : Includedatei für Standardsystem-Includedateien
// oder häufig verwendete projektspezifische Includedateien,
// die nur in unregelmäßigen Abständen geändert werden.
//

#pragma once

// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind.
// In MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen.
#ifndef WINVER              // Lassen Sie die Verwendung spezifischer Features von Windows XP oder später zu.
#define WINVER 0x0501       // Ändern Sie dies in den geeigneten Wert für andere Versionen von Windows.
#endif

#ifndef _WIN32_WINNT        // Lassen Sie die Verwendung spezifischer Features von Windows XP oder später zu.                   
#define _WIN32_WINNT 0x0501 // Ändern Sie dies in den geeigneten Wert für andere Versionen von Windows.
#endif                      

#ifndef _WIN32_WINDOWS      // Lassen Sie die Verwendung spezifischer Features von Windows 98 oder später zu.
#define _WIN32_WINDOWS 0x0410 // Ändern Sie dies in den geeigneten Wert für Windows Me oder höher.
#endif

#ifndef _WIN32_IE           // Lassen Sie die Verwendung spezifischer Features von IE 6.0 oder später zu.
#define _WIN32_IE 0x0600    // Ändern Sie dies in den geeigneten Wert für andere Versionen von IE.
#endif

#define WIN32_LEAN_AND_MEAN     // Selten verwendete Teile der Windows-Header nicht einbinden.
// Windows-Headerdateien:
#include <windows.h>
{code}

DLL Exports:

http://i.stack.imgur.com/iZBdP.png

Edited by: brian - on Jun 23, 2012 7:35 AM
0
brian
6/23/2012 2:37:07 PM
embarcadero.delphi.nativeapi 1236 articles. 1 followers. Follow

2 Replies
3259 Views

Similar Articles

[PageSpeed] 22

Found the issue. When I added the x64 platform in VS2010 it set 2 settings that cause the whole issue:

Project options > Linker > Advanced > - Randomized Base Address - Data Execution Prevention (DEP)

Disabling those 2 settings fixed it.

http://i.imgur.com/NkWGo.png
0
brian
6/23/2012 3:39:23 PM
Hi,

I guess you still have a problem.

{code}
Var DllHandle: Cardinal;
    showstuff: Tshowstuff;
{code}
 
DllHandle should be of type THandle as Cardinal is still 32bit under win64.

Eriks
0
Eriks
7/5/2012 5:54:11 AM
Reply:

Web resources about - Using 64-bit DLL from Delphi, GetProcAddress gives error [Edit] - embarcadero.delphi.nativeapi

Dynamic-link library - Wikipedia, the free encyclopedia
(for legacy system drivers ). The file formats for DLLs are the same as for Windows EXE files — that is, Portable Executable (PE) for 32-bit ...

Forum - Corelan Team
Corelan Team :: Knowledge is not an object, it's a flow :: Home Login/Register/Logout Articles Free Tools AD & CS AD Disable Users Certificate ...

"Dear user, pay the debt!" - Another Malware Campaign Hits the Czech Republic
Jakub Kroustek talks about the latest social engineering malware to hit the Czech Republic

Alan in wonDLLand
Alan in wonDLLand - Alan's Ramblings

Security Advisories - eEye Digital Security
eEye offers customers access to its constantly growing library of security webinars, podcasts, case studies, datasheets, and white papers to ...

flipcode - Developer's Toolbox
See what's going on with flipcode! This section of the archives stores flipcode's complete Developer Toolbox collection,featuring a variety of ...

Malwr - Malware Analysis by Cuckoo Sandbox
Submit malware for free analysis with Cuckoo Sandbox

marklio
better than the original

DllGetVersion function (Windows)
Type: HRESULT If this function succeeds, it returns S_OK . Otherwise, it returns an HRESULT error code. This function is exported by name from ...

GetProcAddress function (Windows)
... the function or variable. The LoadLibrary , LoadLibraryEx , LoadPackagedLibrary , or GetModuleHandle function returns this handle. The GetProcAddress ...

Resources last updated: 1/20/2016 5:20:19 PM